Skip to content

Conversation

@BurntSushi
Copy link
Member

Previously, without the 'wrap_help' feature enabled, Clap would not do
any auto-wrapping of help text. For help text with long lines, this
tends to lead to non-ideal formatting. It can be especially difficult to
read when the width of the terminal is smaller.

This commit enables 'wrap_help', which will automatically cause Clap to
query the terminal size and wrap according to that. Or, if the terminal
size cannot be determined, it will default to a maximum line width of
100.

Ref #9599 (comment)

@BurntSushi
Copy link
Member Author

Before:

ruff-help-no-wrap

After:

ruff-help-yes-wrap

@charliermarsh charliermarsh added the cli Related to the command-line interface label Jan 24, 2024
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

You beat me by 5 minutes! My version of this PR is still compiling locally 😄

Previously, without the 'wrap_help' feature enabled, Clap would not do
any auto-wrapping of help text. For help text with long lines, this
tends to lead to non-ideal formatting. It can be especially difficult to
read when the width of the terminal is smaller.

This commit enables 'wrap_help', which will automatically cause Clap to
query the terminal size and wrap according to that. Or, if the terminal
size cannot be determined, it will default to a maximum line width of
100.

Ref #9599 (comment)
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Nice that the --help in the docs is now neatly formatted as well :D

@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@BurntSushi BurntSushi merged commit fc3e266 into main Jan 24, 2024
@BurntSushi BurntSushi deleted the ag/wrap-help branch January 24, 2024 15:51
/// Returns the output of a given subcommand (e.g., `ruff help check`).
fn subcommand_help_text(subcommand: &str) -> Result<String> {
let mut cmd = args::Args::command();
let mut cmd = args::Args::command().term_width(79);
Copy link
Member

Choose a reason for hiding this comment

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

Lol, why 79 😆

Copy link
Member

Choose a reason for hiding this comment

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

Andrew's abiding by PEP-8, clearly: https://peps.python.org/pep-0008/#maximum-line-length

Copy link
Member

@MichaReiser MichaReiser Jan 24, 2024

Choose a reason for hiding this comment

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

But it's not python and it's not code... I just found it funny that it's 79 and not like 80

Copy link
Member

Choose a reason for hiding this comment

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

Anyway, I don't think it matters because markdown is not whitespace sensitive, so I don't think the rendering changes on the website

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah Markdown won't care. I've been using 79 columns since forever, so I just wrote that here.

(The actual reason why I use a somewhat short line width more generally is so I can have code windows side-by-side, at a reasonable font size, without auto-line-wrapping kicking in.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Related to the command-line interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants