mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
fix: allow final word to be wrapped in wrap_help
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 #828.
This commit is contained in:
parent
563a539a8e
commit
564c5f0f17
2 changed files with 15 additions and 1 deletions
|
@ -960,8 +960,21 @@ fn wrap_help(help: &mut String, longest_w: usize, avail_chars: usize) {
|
|||
debugln!("Help::wrap_help:iter: Char at {}: {:?}", j, &help[j..j+1]);
|
||||
help.remove(j);
|
||||
help.insert(j, '\n');
|
||||
prev_space = idx;
|
||||
}
|
||||
} else {
|
||||
sdebugln!("No");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::wrap_help;
|
||||
|
||||
#[test]
|
||||
fn wrap_help_last_word() {
|
||||
let mut help = String::from("foo bar baz");
|
||||
wrap_help(&mut help, 3, 5);
|
||||
assert_eq!(help, "foo\nbar\nbaz");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,7 +159,8 @@ FLAGS:
|
|||
information
|
||||
-V, --version
|
||||
Prints
|
||||
version information";
|
||||
version
|
||||
information";
|
||||
|
||||
static OLD_NEWLINE_CHARS: &'static str = "ctest 0.1
|
||||
|
||||
|
|
Loading…
Reference in a new issue