-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix wrapping bugs #832
Fix wrapping bugs #832
Conversation
Thanks for tackling this! I'm fine with the coveralls failing, so don't worry about that. But I need the Travis checks to pass, and it looks like it's failing on stable and 1.11.0 (minimum supported version of Rust). |
Yeah, I'll look into the build failures later -- hopefully tonight! |
08be630
to
78dec94
Compare
Before, wrapping the help text at, say, 80 characters really meant that every line could be at most 79 characters wide. Lines can now be up to and including avail_chars columns wide. If needed, a desired margin or padding can be subtracted from the avail_chars argument at a later point.
The &help[j..j] string slice was empty so nothing was shown.
Before, inserting a newline did not move the prev_space index forward. This meant that the next word was measured incorrectly since the length was measured back to the word before the newly inserted linebreak. Fixes clap-rs#828.
78dec94
to
564c5f0
Compare
3 similar comments
The build failures have been fixed. |
Excellent, thanks! @homu r+ |
📌 Commit 564c5f0 has been approved by |
Fix wrapping bugs I've been working towards integrating my [textwrap][1] crate and along the way, I found some small problems in the existing `wrap_help` function in clap. I basically added new code that calls both `textwrap::fill` and `wrap_help` and panicked on any difference: ``` fn wrap_help(help: &mut String, longest_w: usize, avail_chars: usize) { let input = help.clone(); let mut old = help.clone(); old_wrap_help(&mut old, longest_w, avail_chars); let mut wrapped = String::with_capacity(help.len()); for (i, line) in help.lines().enumerate() { if i > 0 { wrapped.push('\n'); } wrapped.push_str(&textwrap::fill(line, avail_chars)); } // TODO: move up, This keeps old behavior of not wrapping at all // if one of the words would overflow the line if longest_w < avail_chars { *help = wrapped; } if *old != *help { println!("********************************"); println!("longest_w: {}, avail_chars: {}", longest_w, avail_chars); println!("help: {:3} bytes: {:?}", input.len(), input); println!("old: {:3} bytes: {:?}", old.len(), old); println!("new: {:3} bytes: {:?}", help.len(), help); println!("********************************"); panic!("bad wrap"); } } fn old_wrap_help(help: &mut String, longest_w: usize, avail_chars: usize) { // ... as before ``` This PR fixes two small problems discovered this way, one of which became #828. [1]: https://crates.io/crates/textwrap
Fix wrapping bugs I've been working towards integrating my [textwrap][1] crate and along the way, I found some small problems in the existing `wrap_help` function in clap. I basically added new code that calls both `textwrap::fill` and `wrap_help` and panicked on any difference: ``` fn wrap_help(help: &mut String, longest_w: usize, avail_chars: usize) { let input = help.clone(); let mut old = help.clone(); old_wrap_help(&mut old, longest_w, avail_chars); let mut wrapped = String::with_capacity(help.len()); for (i, line) in help.lines().enumerate() { if i > 0 { wrapped.push('\n'); } wrapped.push_str(&textwrap::fill(line, avail_chars)); } // TODO: move up, This keeps old behavior of not wrapping at all // if one of the words would overflow the line if longest_w < avail_chars { *help = wrapped; } if *old != *help { println!("********************************"); println!("longest_w: {}, avail_chars: {}", longest_w, avail_chars); println!("help: {:3} bytes: {:?}", input.len(), input); println!("old: {:3} bytes: {:?}", old.len(), old); println!("new: {:3} bytes: {:?}", help.len(), help); println!("********************************"); panic!("bad wrap"); } } fn old_wrap_help(help: &mut String, longest_w: usize, avail_chars: usize) { // ... as before ``` This PR fixes two small problems discovered this way, one of which became #828. [1]: https://crates.io/crates/textwrap
☀️ Test successful - status |
Because why the hell not? 1.6.0 (2022-07-05) New features: FEATURE clap-rs#832: Clarify that Captures::len includes all groups, not just matching groups. FEATURE clap-rs#857: Add an ExactSizeIterator impl for SubCaptureMatches. FEATURE clap-rs#861: Improve RegexSet documentation examples. FEATURE clap-rs#877: Upgrade to Unicode 14. Bug fixes: BUG clap-rs#792: Fix error message rendering bug. 1.5.6 (2022-05-20) BUG clap-rs#680: Fixes a bug where [[:alnum:][:^ascii:]] dropped [:alnum:] from the class. BUG clap-rs#859: Fixes a bug where Hir::is_match_empty returned false for \b. BUG clap-rs#862: Fixes a bug where 'ab??' matches 'ab' instead of 'a' in 'ab'.
I've been working towards integrating my textwrap crate and along the way, I found some small problems in the existing
wrap_help
function in clap. I basically added new code that calls bothtextwrap::fill
andwrap_help
and panicked on any difference:This PR fixes two small problems discovered this way, one of which became #828.