Conversation
Member
|
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). |
Contributor
Author
|
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
Contributor
Author
|
The build failures have been fixed. |
Member
|
Excellent, thanks! @homu r+ |
Contributor
|
📌 Commit 564c5f0 has been approved by |
homu
added a commit
that referenced
this pull request
Jan 30, 2017
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
homu
added a commit
that referenced
this pull request
Jan 30, 2017
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
Contributor
Contributor
|
☀️ Test successful - status |
kbknapp
added a commit
that referenced
this pull request
Feb 3, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've been working towards integrating my textwrap crate and along the way, I found some small problems in the existing
wrap_helpfunction in clap. I basically added new code that calls bothtextwrap::fillandwrap_helpand panicked on any difference:This PR fixes two small problems discovered this way, one of which became #828.