diff options
author | Dan Davison <dandavison7@gmail.com> | 2022-03-13 22:49:28 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2022-03-14 10:53:30 -0400 |
commit | f4a80c54f2974818beb4cd935ae85e9ba13d6819 (patch) | |
tree | c49703c8913e6b4698b8791f150c8affb7e2c2bd | |
parent | a0c848e05562b84ecb034bec4d5cf7fdaa051078 (diff) |
Introduce line-numbers-left/right-style = none to mean no column-oriented styles
-rw-r--r-- | src/config.rs | 2 | ||||
-rw-r--r-- | src/features/line_numbers.rs | 22 | ||||
-rw-r--r-- | src/parse_style.rs | 7 |
3 files changed, 20 insertions, 11 deletions
diff --git a/src/config.rs b/src/config.rs index 24fe681d..f25faad2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -332,7 +332,7 @@ impl From<cli::Opt> for Config { minus_style: styles["minus-style"], navigate: opt.navigate, navigate_regex, - null_style: Style::new(), + null_style: Style::null_style(), null_syntect_style: SyntectStyle::default(), pager: opt.pager, paging_mode: opt.computed.paging_mode, diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs index 0f138499..329d2efb 100644 --- a/src/features/line_numbers.rs +++ b/src/features/line_numbers.rs @@ -249,17 +249,19 @@ fn format_and_paint_line_number_field<'a>( let format_data = &line_numbers_data.format_data[side]; let plus_file = &line_numbers_data.plus_file; - let style = &config.line_numbers_style_leftright[side]; - let style2 = if line_numbers[Minus].is_some() { - styles[Minus] - } else { - styles[Plus] - }; + let mut style = &config.line_numbers_style_leftright[side]; + if style == &config.null_style { + style = if line_numbers[Minus].is_some() { + &styles[Minus] + } else { + &styles[Plus] + }; + } let mut ansi_strings = Vec::new(); let mut suffix = ""; for placeholder in format_data { - ansi_strings.push(style2.paint(placeholder.prefix.as_str())); + ansi_strings.push(style.paint(placeholder.prefix.as_str())); let width = if let Some(placeholder_width) = placeholder.width { max(placeholder_width, min_field_width) @@ -278,7 +280,7 @@ fn format_and_paint_line_number_field<'a>( None, config, ); - ansi_strings.push(style2.paint(formatted)) + ansi_strings.push(style.paint(formatted)) } Some(Placeholder::NumberPlus) => { let formatted = format_line_number( @@ -289,14 +291,14 @@ fn format_and_paint_line_number_field<'a>( Some(plus_file), config, ); - ansi_strings.push(style2.paint(formatted)) + ansi_strings.push(style.paint(formatted)) } None => {} _ => unreachable!("Invalid placeholder"), } suffix = placeholder.suffix.as_str(); } - ansi_strings.push(style2.paint(suffix)); + ansi_strings.push(style.paint(suffix)); ansi_strings } diff --git a/src/parse_style.rs b/src/parse_style.rs index eaeba24c..70f40ff1 100644 --- a/src/parse_style.rs +++ b/src/parse_style.rs @@ -18,6 +18,9 @@ impl Style { true_color: bool, git_config: Option<&GitConfig>, ) -> Self { + if style_string.to_lowercase() == "none" { + return Self::null_style(); + } let (ansi_term_style, is_omitted, is_raw, is_syntax_highlighted) = parse_ansi_term_style(style_string, default, true_color, git_config); let decoration_style = DecorationStyle::from_str( @@ -35,6 +38,10 @@ impl Style { } } + pub fn null_style() -> Self { + Self::new() + } + pub fn from_git_str(git_style_string: &str) -> Self { Self::from_str(git_style_string, None, None, true, None) } |