Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #832 - mgeisler:fix-wrapping-bugs, r=kbknapp
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
- Loading branch information