diff --git a/CHANGELOG.md b/CHANGELOG.md index cb64678d0..a58d78f27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 22a38e74d..00bc5c4dd 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -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)?; diff --git a/cli/src/config-schema.json b/cli/src/config-schema.json index bbeaaca8b..7d69b38d0 100644 --- a/cli/src/config-schema.json +++ b/cli/src/config-schema.json @@ -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", diff --git a/cli/src/config/misc.toml b/cli/src/config/misc.toml index fd395c2df..dbd203eee 100644 --- a/cli/src/config/misc.toml +++ b/cli/src/config/misc.toml @@ -5,5 +5,6 @@ # Placeholder: added by user [ui] +paginate = "auto" pager = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } } log-word-wrap = false diff --git a/cli/src/ui.rs b/cli/src/ui.rs index f405d071a..f17274ecf 100644 --- a/cli/src/ui.rs +++ b/cli/src/ui.rs @@ -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 { + config + .get::("ui.paginate") + .map_err(|err| CommandError::ConfigError(format!("Invalid `ui.paginate`: {err:?}"))) +} + fn pager_setting(config: &config::Config) -> Result { config .get::("ui.pager") @@ -109,7 +116,7 @@ impl Ui { color, formatter_factory, pager_cmd: pager_setting(config)?, - paginate: PaginationChoice::Auto, + paginate: pagination_setting(config)?, progress_indicator, output: UiOutput::new_terminal(), }) @@ -117,6 +124,7 @@ impl Ui { 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(); @@ -132,8 +140,9 @@ 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 { - return; + match self.paginate { + PaginationChoice::Never => return, + PaginationChoice::Auto => {} } match self.output { diff --git a/docs/config.md b/docs/config.md index 58a2673e0..7b157913e 100644 --- a/docs/config.md +++ b/docs/config.md @@ -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.