Skip to content

Commit

Permalink
Switch to bwrap (extrawurst#1792)
Browse files Browse the repository at this point in the history
* switch from textwrap to bwrap
  • Loading branch information
TheBlackSheep3 authored and IndianBoy42 committed Jun 4, 2024
1 parent 99349a3 commit 7db7b94
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
54 changes: 11 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
Expand All @@ -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"
Expand Down
28 changes: 26 additions & 2 deletions src/components/commit_details/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cow<'_, str>> =
textwrap::wrap(body, width).into_iter().collect();
bwrap::wrap!(body, width)
.lines()
.map(String::from)
.map(Cow::from)
.collect();

(wrapped_title, wrapped_message)
} else {
Expand Down Expand Up @@ -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");
Expand All @@ -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",
Expand All @@ -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"
]
);
}
}

Expand Down

0 comments on commit 7db7b94

Please sign in to comment.