mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 10:07:28 +00:00
cli: add --no-pager
This commit is contained in:
parent
7c2400f3e5
commit
0df5f7c5bf
3 changed files with 35 additions and 0 deletions
|
@ -1237,6 +1237,14 @@ pub struct GlobalArgs {
|
|||
help_heading = "Global Options"
|
||||
)]
|
||||
pub color: Option<ColorChoice>,
|
||||
/// 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)?;
|
||||
}
|
||||
|
|
23
src/ui.rs
23
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 { .. } => {
|
||||
|
|
|
@ -253,6 +253,7 @@ fn test_help() {
|
|||
--no-commit-working-copy Don't commit the working copy
|
||||
--at-operation <AT_OPERATION> Operation to load the repo at [default: @] [aliases: at-op]
|
||||
--color <WHEN> When to colorize output (always, never, auto)
|
||||
--no-pager Disable the pager
|
||||
--config-toml <TOML> Additional configuration options
|
||||
-v, --verbose Enable verbose logging
|
||||
"###);
|
||||
|
|
Loading…
Reference in a new issue