Skip to content

Commit

Permalink
imp(Help Wrapping): makes some minor changes to when next line help i…
Browse files Browse the repository at this point in the history
…s automatically used
  • Loading branch information
kbknapp committed Sep 6, 2016
1 parent 7e21b44 commit 5658b11
Showing 1 changed file with 12 additions and 8 deletions.
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));
}

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

0 comments on commit 5658b11

Please sign in to comment.