Skip to content

Commit

Permalink
Wrap --help output and use pager
Browse files Browse the repository at this point in the history
Set clap option `max_term_width`, so the help output is by default as
wide as the terminal or this max value. Then manually wrap the
`after_long_help()` text (only on demand) to the same width using
`textwrap`. Also use matching ansi codes in this section.

The help output is now paginated if output is to a terminal.

All code paths flow back to main() so an invoked pager is properly
waited for (by the OutputType drop impl).
  • Loading branch information
th1000s committed Jul 22, 2024
1 parent 14fe71a commit 6208283
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 163 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ unicode-width = "0.1.10"
xdg = "2.4.1"
clap_complete = "4.4.4"
terminal-colorsaurus = "0.4.1"
textwrap = { version = "0.16.0", default-features = false, features = [] }

[dependencies.git2]
version = "0.18.2"
Expand Down
4 changes: 4 additions & 0 deletions manual/src/full---help-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,11 @@ Similarly, the default value of --line-numbers-right-format is '{np:^4}│'. Thi
Use '<' for left-align, '^' for center-align, and '>' for right-align.
SUPPORT
-------
If something isn't working correctly, or you have a feature request, please open an issue at https://github.com/dandavison/delta/issues.
For a short help summary, please use delta -h.
```
2 changes: 2 additions & 0 deletions src/ansi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use iterator::{AnsiElementIterator, Element};

pub const ANSI_CSI_CLEAR_TO_EOL: &str = "\x1b[0K";
pub const ANSI_CSI_CLEAR_TO_BOL: &str = "\x1b[1K";
pub const ANSI_SGR_BOLD: &str = "\x1b[1m";
pub const ANSI_SGR_RESET: &str = "\x1b[0m";
pub const ANSI_SGR_REVERSE: &str = "\x1b[7m";
pub const ANSI_SGR_UNDERLINE: &str = "\x1b[4m";

pub fn strip_ansi_codes(s: &str) -> String {
strip_ansi_codes_from_strings_iterator(ansi_strings_iterator(s))
Expand Down
Loading

0 comments on commit 6208283

Please sign in to comment.