diff --git a/CHANGELOG.md b/CHANGELOG.md index f94682f6fb..baf743c5d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * support 'n'/'p' key to move to the next/prev hunk in diff component [[@hamflx](https://github.com/hamflx)] ([#1523](https://github.com/extrawurst/gitui/issues/1523)) * simplify theme overrides [[@cruessler](https://github.com/cruessler)] ([#1367](https://github.com/extrawurst/gitui/issues/1367)) * support for sign-off of commits [[@domtac](https://github.com/domtac)]([#1757](https://github.com/extrawurst/gitui/issues/1757)) +* switched from textwrap to bwrap for text wrapping [[@TheBlackSheep3](https://github.com/TheBlackSheep3/)] ([#1762](https://github.com/extrawurst/gitui/issues/1762)) ### Fixes * fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726)) diff --git a/Cargo.lock b/Cargo.lock index dc5061f4fd..7bd56dd6eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,17 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.3" @@ -173,6 +162,15 @@ version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +[[package]] +name = "bwrap" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d13da3319ae5c5771712fba7b79b028793149bc462a08990bc8fd7c7554dbb95" +dependencies = [ + "unicode-width", +] + [[package]] name = "bytemuck" version = "1.13.0" @@ -733,6 +731,7 @@ dependencies = [ "backtrace", "bitflags", "bugreport", + "bwrap", "bytesize", "chrono", "clap", @@ -760,7 +759,6 @@ dependencies = [ "struct-patch", "syntect", "tempfile", - "textwrap", "unicode-segmentation", "unicode-truncate", "unicode-width", @@ -772,9 +770,6 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.6", -] [[package]] name = "hermit-abi" @@ -838,7 +833,7 @@ version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fb7c1b80a1dfa604bb4a649a5c5aeef3d913f7c520cb42b40e534e8a61bcdfc" dependencies = [ - "ahash 0.8.3", + "ahash", "indexmap", "is-terminal", "itoa", @@ -1660,12 +1655,6 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" -[[package]] -name = "smawk" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043" - [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -1797,17 +1786,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" -dependencies = [ - "smawk", - "unicode-linebreak", - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.39" @@ -1892,16 +1870,6 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" -[[package]] -name = "unicode-linebreak" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5faade31a542b8b35855fff6e8def199853b2da8da256da52f52f1316ee3137" -dependencies = [ - "hashbrown", - "regex", -] - [[package]] name = "unicode-normalization" version = "0.1.22" diff --git a/Cargo.toml b/Cargo.toml index 4a7299a7fa..7fbfac341b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ asyncgit = { path = "./asyncgit", version = "0.23", default-features = false } backtrace = "0.3" bitflags = "1.3" bugreport = "0.5" +bwrap = { version = "1.3.0", features = ["use_std"] } bytesize = { version = "1.2", default-features = false } chrono = { version = "0.4", default-features = false, features = [ "clock" ] } clap = { version = "4.1", features = [ "env", "cargo" ] } @@ -49,7 +50,6 @@ serde = "1.0" simplelog = { version = "0.12", default-features = false } struct-patch = "0.2" syntect = { version = "5.0", default-features = false, features = ["parsing", "default-syntaxes", "default-themes", "html"] } -textwrap = "0.16" unicode-segmentation = "1.10" unicode-truncate = "0.2" unicode-width = "0.1" diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs index 8ff2775e81..6c1a86c7a5 100644 --- a/src/components/commit_details/details.rs +++ b/src/components/commit_details/details.rs @@ -86,11 +86,20 @@ impl DetailsComponent { message: &CommitMessage, width: usize, ) -> WrappedCommitMessage<'_> { - let wrapped_title = textwrap::wrap(&message.subject, width); + let width = width.max(1); + let wrapped_title = bwrap::wrap!(&message.subject, width) + .lines() + .map(String::from) + .map(Cow::from) + .collect(); if let Some(ref body) = message.body { let wrapped_message: Vec> = - textwrap::wrap(body, width).into_iter().collect(); + bwrap::wrap!(body, width) + .lines() + .map(String::from) + .map(Cow::from) + .collect(); (wrapped_title, wrapped_message) } else { @@ -429,6 +438,10 @@ mod tests { get_wrapped_lines(&message, 14), vec!["Commit message"] ); + assert_eq!( + get_wrapped_lines(&message, 0), + vec!["Commit", "message"] + ); let message_with_newline = CommitMessage::from("Commit message\n"); @@ -441,6 +454,10 @@ mod tests { get_wrapped_lines(&message_with_newline, 14), vec!["Commit message"] ); + assert_eq!( + get_wrapped_lines(&message, 0), + vec!["Commit", "message"] + ); let message_with_body = CommitMessage::from( "Commit message\nFirst line\nSecond line", @@ -457,6 +474,13 @@ mod tests { get_wrapped_lines(&message_with_body, 14), vec!["Commit message", "First line", "Second line"] ); + assert_eq!( + get_wrapped_lines(&message_with_body, 7), + vec![ + "Commit", "message", "First", "line", "Second", + "line" + ] + ); } }