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

wrap --help output #1440

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

wrap --help output #1440

wants to merge 3 commits into from

Conversation

th1000s
Copy link
Contributor

@th1000s th1000s commented Jun 5, 2023

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

@dandavison
Copy link
Owner

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.)

@th1000s
Copy link
Contributor Author

th1000s commented Jun 5, 2023

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

@dandavison
Copy link
Owner

(There's a formatter error here.)

@th1000s
Copy link
Contributor Author

th1000s commented Jun 6, 2023

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?

@dandavison
Copy link
Owner

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

Use new, smaller PagerCfg instead of the full Config, as for
pager output only 3 variables are relevant.

oneshot_write() can be used to write paginated output, usually
before exiting.
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).
src/cli.rs Outdated
{
write!(&mut writer, "{}", help.ansi()).unwrap();
// dtor?
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't the writer drop impl/destructor but the one of output_type!

@th1000s
Copy link
Contributor Author

th1000s commented Jun 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants