perf(help): Remove next-help possible values

Next-line help for possible values does not feel like its pulling its
weight.  If anything we should do next-line help for the entire
argument.

This dropped about 0.5 KiB but more importantly is prep for other
changes.
This commit is contained in:
Ed Page 2023-05-03 20:09:36 -05:00
parent ec52b74d68
commit 3963d73e18
3 changed files with 7 additions and 42 deletions

View file

@ -162,18 +162,6 @@ impl PossibleValue {
self.help.as_ref()
}
/// Get the help specified for this argument, if any and the argument
/// value is not hidden
#[inline]
#[cfg(feature = "help")]
pub(crate) fn get_visible_help(&self) -> Option<&StyledStr> {
if !self.hide {
self.get_help()
} else {
None
}
}
/// Report if [`PossibleValue::hide`] is set
#[inline]
pub fn is_hide_set(&self) -> bool {

View file

@ -654,7 +654,6 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
self.writer.push_styled(&help);
if let Some(arg) = arg {
const DASH_SPACE: usize = "- ".len();
const COLON_SPACE: usize = ": ".len();
let possible_vals = arg.get_possible_values();
if !possible_vals.is_empty()
&& !arg.is_hide_possible_values_set()
@ -669,23 +668,9 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
.filter_map(|f| f.get_visible_quoted_name().map(|name| display_width(&name)))
.max()
.expect("Only called with possible value");
let help_longest = possible_vals
.iter()
.filter_map(|f| f.get_visible_help().map(|h| h.display_width()))
.max()
.expect("Only called with possible value with help");
// should new line
let taken = longest + spaces + DASH_SPACE;
let possible_value_new_line =
self.term_w >= taken && self.term_w < taken + COLON_SPACE + help_longest;
let spaces = spaces + TAB_WIDTH - DASH_SPACE;
let trailing_indent = if possible_value_new_line {
spaces + DASH_SPACE
} else {
spaces + longest + DASH_SPACE + COLON_SPACE
};
let trailing_indent = spaces + DASH_SPACE;
let trailing_indent = self.get_spaces(trailing_indent);
if !help_is_empty {
@ -704,14 +689,9 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
if let Some(help) = pv.get_help() {
debug!("HelpTemplate::help: Possible Value help");
if possible_value_new_line {
let padding = trailing_indent.len();
let _ = write!(self.writer, ":\n{:padding$}", "");
} else {
// To align help messages
let padding = longest - display_width(pv.get_name());
let _ = write!(self.writer, ": {:padding$}", "");
}
// To align help messages
let padding = longest - display_width(pv.get_name());
let _ = write!(self.writer, ": {:padding$}", "");
let avail_chars = if self.term_w > trailing_indent.len() {
self.term_w - trailing_indent.len()

View file

@ -449,15 +449,12 @@ Usage: test [OPTIONS]
Options:
--possible-values <possible_values>
Possible values:
- short_name:
Long enough help message, barely warrant wrapping
- second:
Short help gets handled the same
- short_name: Long enough help message, barely warrant wrapping
- second: Short help gets handled the same
--possible-values-with-new-line <possible_values_with_new_line>
Possible values:
- long enough name to trigger new line:
Really long enough help message to clearly warrant
- long enough name to trigger new line: Really long enough help message to clearly warrant
wrapping believe me
- second