diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-01 22:38:08 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-01 22:38:08 +1100 |
commit | c5ab4503f733211d4fc37489c3043e170c14330d (patch) | |
tree | c1fa1c5989bedaa9b617b7faead83fdb3fefdb42 | |
parent | 657bdf030790155803c6498c93a1a2f2efdf35cd (diff) |
add paging mode option
-rw-r--r-- | src/cli.rs | 12 | ||||
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 2 |
3 files changed, 17 insertions, 1 deletions
@@ -8,6 +8,7 @@ use structopt::StructOpt; use crate::bat::assets::HighlightingAssets; use crate::config; use crate::style; +use crate::bat::output::{PagingMode}; #[derive(StructOpt, Clone, Debug)] #[structopt( @@ -153,6 +154,10 @@ pub struct Opt { /// one into the other. #[structopt(long = "max-line-distance", default_value = "0.3")] pub max_line_distance: f64, + + /// the paging mode. One of 'always', 'never' and 'quit-if-one-screen' + #[structopt(long = "paging_mode", default_value = "quit-if-one-screen")] + pub paging_mode: String, } #[derive(Clone, Debug, PartialEq)] @@ -237,11 +242,18 @@ pub fn process_command_line_arguments<'a>( None => Some(available_terminal_width), }; + let paging_mode = match opt.paging_mode.as_ref() { + "always" => PagingMode::Always, + "never" => PagingMode::Never, + _ => PagingMode::QuitIfOneScreen, + }; + config::get_config( opt, &assets.syntax_set, &assets.theme_set, available_terminal_width, background_color_width, + paging_mode, ) } diff --git a/src/config.rs b/src/config.rs index 2135efe8..3c3f033b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,6 +8,7 @@ use crate::cli; use crate::env; use crate::paint; use crate::style; +use crate::bat::output::{PagingMode}; pub struct Config<'a> { pub theme: Option<&'a Theme>, @@ -26,6 +27,7 @@ pub struct Config<'a> { pub opt: &'a cli::Opt, pub no_style: Style, pub max_buffered_lines: usize, + pub paging_mode: PagingMode, } pub fn get_config<'a>( @@ -34,6 +36,7 @@ pub fn get_config<'a>( theme_set: &'a ThemeSet, terminal_width: usize, width: Option<usize>, + paging_mode: PagingMode, ) -> Config<'a> { let theme_name_from_bat_pager = env::get_env_var("BAT_THEME"); let (is_light_mode, theme_name) = get_is_light_mode_and_theme_name( @@ -118,6 +121,7 @@ pub fn get_config<'a>( opt, no_style: style::get_no_style(), max_buffered_lines: 32, + paging_mode, } } diff --git a/src/main.rs b/src/main.rs index 0650cdf1..f2c29b5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ fn main() -> std::io::Result<()> { process::exit(0); } - let mut output_type = OutputType::from_mode(PagingMode::QuitIfOneScreen, None).unwrap(); + let mut output_type = OutputType::from_mode(config.paging_mode, None).unwrap(); let mut writer = output_type.handle().unwrap(); if let Err(error) = delta( |