delta icon indicating copy to clipboard operation
delta copied to clipboard

wrap --help output

Open th1000s opened this issue 2 years ago • 6 comments

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.


Another try to improve deltas --help output, and I finally can use textwrap! But now --version and --help is handled manually. Another possibility would be to manually construct the pieces of claps StyledStr (...which is returned from render_help() and according to dbg!() different from the simple String wrapper? render_help() = StyledStr { pieces: [ (None, "A viewer for git and diff output",), (..)] } ).

CC @tjquillan @nickelc @FGasper

th1000s avatar Jun 05 '23 21:06 th1000s

Thanks! I tried this out and it seems like a good improvement to me.

(Tangential: Ultimately I feel that the lengthy man-page style output should be sent into a pager.)

dandavison avatar Jun 05 '23 21:06 dandavison

Now that --help is handled manually, piping the output into less -R is easy. And clap doesn't seen to support a pager currently.

th1000s avatar Jun 05 '23 21:06 th1000s

(There's a formatter error here.)

dandavison avatar Jun 05 '23 22:06 dandavison

The fmt is fixed, but sending the output into a pager via OutputType::from_mode (now using a lighter PagerCfg) doesn't work, the default pager less just quits after the first page. PagingMode::Always doesn't help, and a default DeltaEnv::init() works fine for the normal delta. However DELTA_PAGER="cat" does display the entire output. strace shows less is started as "/usr/bin/less", ["less", "--RAW-CONTROL-CHARS"] as expected, what am I missing?

th1000s avatar Jun 06 '23 21:06 th1000s

Hm. Is it the LESS environment variable supplying additional arguments?

dandavison avatar Jun 06 '23 22:06 dandavison

Now with pager support, even listens to PAGER etc. env vars for configuration (but not --paging never).

The full---help-output.md markdown is a bit out of sync, but could be generated from then ansi --help output itself. However the one tool for that, term2md, currently removes leading whitespace.

Oh and I found --show-themes is/was already broken.

th1000s avatar Jun 07 '23 22:06 th1000s

This one has conflicts for us to resolve. Sorry for letting it drag on.

dandavison avatar Jul 17 '24 09:07 dandavison

The full help output has to be regenerated (some ansi2md util would help), and I have to check that the big moved textblock in cli.rs is still correct.

th1000s avatar Jul 22 '24 22:07 th1000s

Also fixed the rust 1.80 build, note the Cargo.* changes. FTR, the build for the time crate was:

  --> /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/time-0.3.31/src/format_description/parse/mod.rs:83:9
   |
83 |     let items = format_items
   |         ^^^^^
...
86 |     Ok(items.into())
   |              ---- type must be known at this point
   |
help: consider giving `items` an explicit type, where the placeholders `_` are specified
   |
83 |     let items: Box<_> = format_items
   |              ++++++++

(Currently, v0.17.0, cargo install delta still works with 1.80, only --locked fails.)

th1000s avatar Jul 30 '24 22:07 th1000s

I've approved this one already; please merge at will!

dandavison avatar Aug 01 '24 00:08 dandavison

I think this PR accidentally caused delta -h lines to be wrapped; I've opened https://github.com/dandavison/delta/issues/1795.

dandavison avatar Aug 09 '24 18:08 dandavison

@dandavison would it be possible to cut a new release with this Rust 1.80 fix? It would make it possible to upgrade delta in nixpkgs (https://github.com/NixOS/nixpkgs/issues/332957)

ofalvai avatar Aug 13 '24 12:08 ofalvai

@ofalvai will do! I'll ping here when it's done.

dandavison avatar Aug 14 '24 03:08 dandavison