Skip to content

Commit

Permalink
configs: add the ability to disable paging via ui.paginate
Browse files Browse the repository at this point in the history
  • Loading branch information
mbStavola committed Aug 11, 2023
1 parent 1abd367 commit 263595b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `jj log`/`obslog`/`op log` now supports `--limit N` option to show the first
`N` entries.

* Added the `ui.paginate` option to enable/disable pager usage in commands

### Fixed bugs

* SSH authentication could hang when ssh-agent couldn't be reached
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2488,7 +2488,7 @@ fn handle_early_args(
args.config_toml.push(format!(r#"ui.color="{choice}""#));
}
if args.no_pager.unwrap_or_default() {
ui.set_pagination(crate::ui::PaginationChoice::No);
ui.set_pagination(crate::ui::PaginationChoice::Never);
}
if !args.config_toml.is_empty() {
layered_configs.parse_config_args(&args.config_toml)?;
Expand Down
9 changes: 9 additions & 0 deletions cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
],
"default": "auto"
},
"paginate": {
"type": "string",
"description": "Whether or not to use a pager",
"enum": [
"never",
"auto"
],
"default": "auto"
},
"pager": {
"type": "string",
"description": "Pager to use for displaying command output",
Expand Down
1 change: 1 addition & 0 deletions cli/src/config/misc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
# Placeholder: added by user

[ui]
paginate = "auto"
pager = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } }
log-word-wrap = false
16 changes: 12 additions & 4 deletions cli/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,20 @@ fn use_color(choice: ColorChoice) -> bool {
}
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, serde::Deserialize)]
#[serde(rename_all(deserialize = "kebab-case"))]
pub enum PaginationChoice {
No,
Never,
#[default]
Auto,
}

fn pagination_setting(config: &config::Config) -> Result<PaginationChoice, CommandError> {
config
.get::<PaginationChoice>("ui.paginate")
.map_err(|err| CommandError::ConfigError(format!("Invalid `ui.paginate`: {err:?}")))
}

fn pager_setting(config: &config::Config) -> Result<CommandNameAndArgs, CommandError> {
config
.get::<CommandNameAndArgs>("ui.pager")
Expand All @@ -109,14 +116,15 @@ impl Ui {
color,
formatter_factory,
pager_cmd: pager_setting(config)?,
paginate: PaginationChoice::Auto,
paginate: pagination_setting(config)?,
progress_indicator,
output: UiOutput::new_terminal(),
})
}

pub fn reset(&mut self, config: &config::Config) -> Result<(), CommandError> {
self.color = use_color(color_setting(config));
self.paginate = pagination_setting(config)?;
self.pager_cmd = pager_setting(config)?;
self.progress_indicator = progress_indicator_setting(config);
let sanitize = io::stdout().is_terminal();
Expand All @@ -132,7 +140,7 @@ impl Ui {
/// Switches the output to use the pager, if allowed.
#[instrument(skip_all)]
pub fn request_pager(&mut self) {
if self.paginate == PaginationChoice::No {
if self.paginate == PaginationChoice::Never {
return;
}

Expand Down
9 changes: 9 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ a `$`):

`less -FRX` is the default pager in the absence of any other setting.

Additionally, paging behavior can be toggled via `ui.paginate` like so:

```toml
# Enable pagination for commands that support it (default)
ui.paginate = "auto"
# Disable all pagination, equivalent to using --no-pager
ui.paginate = "never"
```

### Processing contents to be paged

If you'd like to pass the output through a formatter e.g.
Expand Down

0 comments on commit 263595b

Please sign in to comment.