Skip to content

Commit 403c5aa

Browse files
Switch to bwrap (#1792)
* switch from textwrap to bwrap
1 parent a828bd2 commit 403c5aa

File tree

4 files changed

+39
-46
lines changed

4 files changed

+39
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
* 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))
2020
* simplify theme overrides [[@cruessler](https://github.com/cruessler)] ([#1367](https://github.com/extrawurst/gitui/issues/1367))
2121
* support for sign-off of commits [[@domtac](https://github.com/domtac)]([#1757](https://github.com/extrawurst/gitui/issues/1757))
22+
* switched from textwrap to bwrap for text wrapping [[@TheBlackSheep3](https://github.com/TheBlackSheep3/)] ([#1762](https://github.com/extrawurst/gitui/issues/1762))
2223

2324
### Fixes
2425
* fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726))

Cargo.lock

Lines changed: 11 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ asyncgit = { path = "./asyncgit", version = "0.23", default-features = false }
2525
backtrace = "0.3"
2626
bitflags = "1.3"
2727
bugreport = "0.5"
28+
bwrap = { version = "1.3.0", features = ["use_std"] }
2829
bytesize = { version = "1.2", default-features = false }
2930
chrono = { version = "0.4", default-features = false, features = [ "clock" ] }
3031
clap = { version = "4.1", features = [ "env", "cargo" ] }
@@ -49,7 +50,6 @@ serde = "1.0"
4950
simplelog = { version = "0.12", default-features = false }
5051
struct-patch = "0.2"
5152
syntect = { version = "5.0", default-features = false, features = ["parsing", "default-syntaxes", "default-themes", "html"] }
52-
textwrap = "0.16"
5353
unicode-segmentation = "1.10"
5454
unicode-truncate = "0.2"
5555
unicode-width = "0.1"

src/components/commit_details/details.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,20 @@ impl DetailsComponent {
8686
message: &CommitMessage,
8787
width: usize,
8888
) -> WrappedCommitMessage<'_> {
89-
let wrapped_title = textwrap::wrap(&message.subject, width);
89+
let width = width.max(1);
90+
let wrapped_title = bwrap::wrap!(&message.subject, width)
91+
.lines()
92+
.map(String::from)
93+
.map(Cow::from)
94+
.collect();
9095

9196
if let Some(ref body) = message.body {
9297
let wrapped_message: Vec<Cow<'_, str>> =
93-
textwrap::wrap(body, width).into_iter().collect();
98+
bwrap::wrap!(body, width)
99+
.lines()
100+
.map(String::from)
101+
.map(Cow::from)
102+
.collect();
94103

95104
(wrapped_title, wrapped_message)
96105
} else {
@@ -429,6 +438,10 @@ mod tests {
429438
get_wrapped_lines(&message, 14),
430439
vec!["Commit message"]
431440
);
441+
assert_eq!(
442+
get_wrapped_lines(&message, 0),
443+
vec!["Commit", "message"]
444+
);
432445

433446
let message_with_newline =
434447
CommitMessage::from("Commit message\n");
@@ -441,6 +454,10 @@ mod tests {
441454
get_wrapped_lines(&message_with_newline, 14),
442455
vec!["Commit message"]
443456
);
457+
assert_eq!(
458+
get_wrapped_lines(&message, 0),
459+
vec!["Commit", "message"]
460+
);
444461

445462
let message_with_body = CommitMessage::from(
446463
"Commit message\nFirst line\nSecond line",
@@ -457,6 +474,13 @@ mod tests {
457474
get_wrapped_lines(&message_with_body, 14),
458475
vec!["Commit message", "First line", "Second line"]
459476
);
477+
assert_eq!(
478+
get_wrapped_lines(&message_with_body, 7),
479+
vec![
480+
"Commit", "message", "First", "line", "Second",
481+
"line"
482+
]
483+
);
460484
}
461485
}
462486

0 commit comments

Comments
 (0)