From 5658b117aec3e03adff9c8c52a4c4bc1fcb4e1ff Mon Sep 17 00:00:00 2001 From: Kevin K Date: Mon, 5 Sep 2016 19:51:14 -0400 Subject: [PATCH 1/3] imp(Help Wrapping): makes some minor changes to when next line help is automatically used --- src/app/help.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/app/help.rs b/src/app/help.rs index 0cf942e1..3887ccb5 100644 --- a/src/app/help.rs +++ b/src/app/help.rs @@ -313,8 +313,9 @@ impl<'a> Help<'a> { let nlh = self.next_line_help || arg.is_set(ArgSettings::NextLineHelp); let width = self.term_w; let taken = (longest + 12) + str_width(&*spec_vals); - let force_next_line = !nlh && width >= taken && str_width(h) > (width - taken) && - (taken as f32 / width as f32) > 0.25; + let force_next_line = !nlh && width >= taken && + (taken as f32 / width as f32) > 0.40 && + str_width(h) > (width - taken); if arg.has_switch() { if !(nlh || force_next_line) { @@ -374,6 +375,7 @@ impl<'a> Help<'a> { help.push_str(h); &*help }; + if help.contains("{n}") { if let Some(part) = help.split("{n}").next() { try!(write!(self.writer, "{}", part)); @@ -402,8 +404,9 @@ impl<'a> Help<'a> { // We calculate with longest+12 since if it's already NLH we don't care let taken = (longest + 12) + str_width(&*spec_vals); - let force_next_line = !nlh && width >= taken && str_width(h) > (width - taken) && - (taken as f32 / width as f32) > 0.25; + let force_next_line = !nlh && width >= taken && + (taken as f32 / width as f32) > 0.40 && + str_width(h) > (width - taken); debugln!("Force Next Line...{:?}", force_next_line); debugln!("Force Next Line math (help_len > (width - flags/opts/spcs))...{} > ({} - {})", str_width(h), @@ -411,7 +414,7 @@ impl<'a> Help<'a> { taken); let spcs = if nlh || force_next_line { - 8 // "tab" + "tab" + 12 // "tab" * 3 } else { longest + 12 }; @@ -419,9 +422,9 @@ impl<'a> Help<'a> { let too_long = spcs + str_width(h) + str_width(&*spec_vals) >= width; debugln!("Spaces: {}", spcs); - // Is help on next line, if so newline + 2x tab + // Is help on next line, if so then indent if nlh || force_next_line { - try!(write!(self.writer, "\n{}{}", TAB, TAB)); + try!(write!(self.writer, "\n{}{}{}", TAB, TAB, TAB)); } debug!("Too long..."); @@ -456,6 +459,7 @@ impl<'a> Help<'a> { help.push_str(&*spec_vals); &*help }; + if help.contains("{n}") { if let Some(part) = help.split("{n}").next() { try!(write!(self.writer, "{}", part)); @@ -463,7 +467,7 @@ impl<'a> Help<'a> { for part in help.split("{n}").skip(1) { try!(write!(self.writer, "\n")); if nlh || force_next_line { - try!(write!(self.writer, "{}{}", TAB, TAB)); + try!(write!(self.writer, "{}{}{}", TAB, TAB, TAB)); } else if arg.has_switch() { write_nspaces!(self.writer, longest + 12); } else { From e4f194c82b4ce2db698cf145e56b55f40b019cb5 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Mon, 5 Sep 2016 20:16:09 -0400 Subject: [PATCH 2/3] chore: increase version --- CHANGELOG.md | 9 +++++++++ Cargo.toml | 2 +- README.md | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdfd9bc0..9fa013cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ + + +### v2.11.2 (2016-09-06) + +#### Improvements + +* **Help Wrapping:** makes some minor changes to when next line help is automatically used ([5658b117](https://github.com/kbknapp/clap-rs/commit/5658b117aec3e03adff9c8c52a4c4bc1fcb4e1ff)) + + ### v2.11.1 (2016-09-05) diff --git a/Cargo.toml b/Cargo.toml index 0b639d8d..e30bfd54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clap" -version = "2.11.1" +version = "2.11.2" authors = ["Kevin K. "] exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"] repository = "https://github.com/kbknapp/clap-rs.git" diff --git a/README.md b/README.md index 28c05325..75f11f46 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) ## What's New +Here's the highlights for v2.11.2 + +* Makes some minor changes to when next line help is automatically used for improved wrapping + Here's the highlights for v2.11.1 * Fixes an issue where settings weren't propogated down through grand-child subcommands From 60de29a7ef89846842efe1a3e24359bff09de526 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Mon, 5 Sep 2016 20:46:18 -0400 Subject: [PATCH 3/3] tests: updates test to new help improvements --- tests/help.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/help.rs b/tests/help.rs index 3c876cf7..05922fd0 100644 --- a/tests/help.rs +++ b/tests/help.rs @@ -91,13 +91,15 @@ FLAGS: -V, --version Prints version information OPTIONS: - -c, --cafe - A coffeehouse, coffee shop, or café is an establishment which - primarily serves hot coffee, related coffee beverages - (e.g., café latte, cappuccino, espresso), tea, and other - hot beverages. Some coffeehouses also serve cold beverages - such as iced coffee and iced tea. Many cafés also serve - some type of food, such as light snacks, muffins, or pastries."; + -c, --cafe A coffeehouse, coffee shop, or café is an + establishment which primarily serves hot + coffee, related coffee beverages (e.g., + café latte, cappuccino, espresso), tea, + and other hot beverages. Some + coffeehouses also serve cold beverages + such as iced coffee and iced tea. Many + cafés also serve some type of food, such + as light snacks, muffins, or pastries."; static ISSUE_626_PANIC: &'static str = "ctest 0.1 @@ -110,13 +112,14 @@ FLAGS: OPTIONS: -c, --cafe - La culture du café est très développée dans - de nombreux pays à climat chaud - d\'Amérique, d\'Afrique et d\'Asie, dans - des plantations qui sont cultivées pour - les marchés d\'exportation. Le café est - souvent une contribution majeure aux - exportations des régions productrices."; + La culture du café est très développée + dans de nombreux pays à climat chaud + d\'Amérique, d\'Afrique et d\'Asie, + dans des plantations qui sont + cultivées pour les marchés + d\'exportation. Le café est souvent + une contribution majeure aux + exportations des régions productrices."; #[test] fn help_short() {