Skip to content
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

Help imps #648

Merged
merged 3 commits into from
Sep 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

<a name="v2.11.2"></a>
### 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))


<a name="v2.11.1"></a>
### v2.11.1 (2016-09-05)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "clap"
version = "2.11.1"
version = "2.11.2"
authors = ["Kevin K. <kbknapp@gmail.com>"]
exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"]
repository = "https://github.com/kbknapp/clap-rs.git"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions src/app/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -402,26 +404,27 @@ 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),
width,
taken);

let spcs = if nlh || force_next_line {
8 // "tab" + "tab"
12 // "tab" * 3
} else {
longest + 12
};

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not "\n{0}{0}{0}", TAB?

}

debug!("Too long...");
Expand Down Expand Up @@ -456,14 +459,15 @@ 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));
}
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 {
Expand Down
31 changes: 17 additions & 14 deletions tests/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,15 @@ FLAGS:
-V, --version Prints version information

OPTIONS:
-c, --cafe <FILE>
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 <FILE> 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

Expand All @@ -110,13 +112,14 @@ FLAGS:

OPTIONS:
-c, --cafe <FILE>
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() {
Expand Down