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

cli: make pager configurable per command #5311

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bryceberger
Copy link
Member

@bryceberger bryceberger commented Jan 9, 2025

Closes #5217

Allow ui.pager to be set as a table like so:

[ui]
pager.status = ":none"
pager.log = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } }
pager.diff = ["delta", "..."]
pager.default = "..."

ui.pager.log is used for jj log, ui.pager.diff for jj diff, etc. The full name of the highest level subcommand is used, i.e. jj operation diff uses ui.pager.operation. The value ":none" disables paging for the selected command. If a command is not specifically mentioned, the value of ui.pager.default is used.

The old behaviour is unchanged, i.e. ui.pager = ["less", "-FRX"] will set the pager for all subcommands.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

Allow `ui.pager` to be set as a table like so:

    [ui]
    pager.status = ":none"
    pager.log = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } }
    pager.diff = ["delta", "..."]
    pager.default = "..."

`ui.pager.log` is used for `jj log`, `ui.pager.diff` for `jj diff`,
etc. The full name of the highest level subcommand is used, i.e. `jj
operation diff` uses `ui.pager.operation`. The value ":none" disables
paging for the selected command. If a command is not specifically
mentioned, the value of `ui.pager.default` is used.

The old behaviour is unchanged, i.e. `ui.pager = ["less", "-FRX"]` will
set the pager for all subcommands.
@bryceberger
Copy link
Member Author

Unsure how to update config-schema.json for this. The current entry for pager just says "type": "string", which isn't true.

Also unsure if / where there are tests for pagers. I was unable to find any on a cursory glance.

@bryceberger bryceberger marked this pull request as ready for review January 9, 2025 05:06
@yuja
Copy link
Contributor

yuja commented Jan 9, 2025

[ui]
pager.status = ":none"
pager.log = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } }
pager.diff = ["delta", "..."]
pager.default = "..."

I think it's better to not overuse ":<type>" syntax. How about adding a separate table for per-table pager configuration?

[ui]
paginate = "auto"  # default
pager = "..."  # default

[<table-for-per-command-pager-options>]
status.paginate = "never"
diff.pager = ["delta", "..."]

# or generic per-command table like this?
[commands.status]
ui.paginate = "never"

# or extend the conditional table?
[[--scope]]
--when.commands = ["status"]
ui.paginate = "never"

The full name of the highest level subcommand is used, i.e. jj operation diff uses ui.pager.operation.

I think "file show" and "file list" are quite different, and the user might want to enable pager only for one of them.

@bryceberger
Copy link
Member Author

I'm intrigued by extending the [[--scope]] rules.

The rule for --when.repositories = ["a", "b"] is to match "a" | "b" --- would have to put some thought into how to match operation, operation diff, and diff separately. Maybe "operation.diff"?

Currently, jj_lib::config_resolver::resolve() throws away the layer if its --when doesn't match. Thinking of changing ScopeCondition::matches() to return Option<bool>, with None meaning "not enough information to resolve", i.e. resolving --when.repository during cli_util::run_internal but waiting until commands::run_command to resolve --when.commands.

@yuja
Copy link
Contributor

yuja commented Jan 9, 2025

The rule for --when.repositories = ["a", "b"] is to match "a" | "b" --- would have to put some thought into how to match operation, operation diff, and diff separately. Maybe "operation.diff"?

or "operation diff"? The [colors] table uses space-separated string.

Currently, jj_lib::config_resolver::resolve() throws away the layer if its --when doesn't match. Thinking of changing ScopeCondition::matches() to return Option<bool>, with None meaning "not enough information to resolve", i.e. resolving --when.repository during cli_util::run_internal but waiting until commands::run_command to resolve --when.commands.

run_command() calls resolve() multiple times, so I think it's okay to omit --when.commands conditionals until the command name becomes available. That's how --repository path is resolved.

@bryceberger bryceberger marked this pull request as draft January 10, 2025 18:13
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.

FR: Make the pager configurable per subcommand (e.g. enable for diff, disable for status, etc).
2 participants