diff --git a/src/cli_util.rs b/src/cli_util.rs index fcaf1f663..40e7a6e8b 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -1237,6 +1237,14 @@ pub struct GlobalArgs { help_heading = "Global Options" )] pub color: Option, + /// Disable the pager + #[arg( + long, + value_name = "WHEN", + global = true, + help_heading = "Global Options" + )] + pub no_pager: bool, /// Additional configuration options // TODO: Introduce a `--config` option with simpler syntax for simple // cases, designed so that `--config ui.color=auto` works @@ -1411,6 +1419,9 @@ pub fn parse_args( .config_toml .push(format!("ui.color=\"{}\"", choice.to_string())); } + if args.global_args.no_pager { + ui.set_pagination(crate::ui::PaginationChoice::No); + } if !args.global_args.config_toml.is_empty() { ui.extra_toml_settings(&args.global_args.config_toml)?; } diff --git a/src/ui.rs b/src/ui.rs index 1b6b3e02a..9b8314d2e 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -25,6 +25,7 @@ use crate::formatter::{Formatter, FormatterFactory}; pub struct Ui { color: bool, + paginate: PaginationChoice, progress_indicator: bool, cwd: PathBuf, formatter_factory: FormatterFactory, @@ -93,6 +94,18 @@ fn use_color(choice: ColorChoice) -> bool { } } +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum PaginationChoice { + No, + Auto, +} + +impl Default for PaginationChoice { + fn default() -> Self { + PaginationChoice::Auto + } +} + fn pager_setting(settings: &UserSettings) -> String { settings .config() @@ -110,6 +123,7 @@ impl Ui { color, cwd, formatter_factory, + paginate: PaginationChoice::Auto, progress_indicator, output: UiOutput::new_terminal(), settings, @@ -124,8 +138,17 @@ impl Ui { } } + /// Sets the pagination value. + pub fn set_pagination(&mut self, choice: PaginationChoice) { + self.paginate = choice; + } + /// Switches the output to use the pager, if allowed. pub fn request_pager(&mut self) { + if self.paginate == PaginationChoice::No { + return; + } + match self.output { UiOutput::Paged { .. } => {} UiOutput::Terminal { .. } => { diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index b1cf7e79f..a33bddd0e 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -253,6 +253,7 @@ fn test_help() { --no-commit-working-copy Don't commit the working copy --at-operation Operation to load the repo at [default: @] [aliases: at-op] --color When to colorize output (always, never, auto) + --no-pager Disable the pager --config-toml Additional configuration options -v, --verbose Enable verbose logging "###);