From f191eac8f3f92ab2545c7e0997aa92087c18318b Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Thu, 25 Jun 2020 15:25:27 -0400 Subject: Rename: format-style => style --- src/cli.rs | 8 +++--- src/config.rs | 24 ++++++++--------- src/features/line_numbers.rs | 64 +++++++++++++++++++++++--------------------- src/set_options.rs | 10 ++----- 4 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index b277091f..20ebc86d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -351,13 +351,13 @@ pub struct Opt { /// Style (foreground, background, attributes) for the left column of line numbers. See STYLES /// and LINE NUMBERS sections. - #[structopt(long = "line-numbers-left-format-style", default_value = "auto")] - pub line_numbers_left_format_style: String, + #[structopt(long = "line-numbers-left-style", default_value = "auto")] + pub line_numbers_left_style: String, /// Style (foreground, background, attributes) for the right column of line numbers. See STYLES /// and LINE NUMBERS sections. - #[structopt(long = "line-numbers-right-format-style", default_value = "auto")] - pub line_numbers_right_format_style: String, + #[structopt(long = "line-numbers-right-style", default_value = "auto")] + pub line_numbers_right_style: String, #[structopt(long = "color-only")] /// Do not alter the input in any way other than applying colors. Equivalent to diff --git a/src/config.rs b/src/config.rs index ce3e9c91..97b03645 100644 --- a/src/config.rs +++ b/src/config.rs @@ -49,11 +49,11 @@ pub struct Config { pub null_style: Style, pub null_syntect_style: SyntectStyle, pub line_numbers_left_format: String, - pub line_numbers_left_format_style: Style, + pub line_numbers_left_style: Style, pub line_numbers_minus_style: Style, pub line_numbers_plus_style: Style, pub line_numbers_right_format: String, - pub line_numbers_right_format_style: Style, + pub line_numbers_right_style: Style, pub line_numbers_zero_style: Style, pub paging_mode: PagingMode, pub plus_emph_style: Style, @@ -160,8 +160,8 @@ impl From for Config { line_numbers_minus_style, line_numbers_zero_style, line_numbers_plus_style, - line_numbers_left_format_style, - line_numbers_right_format_style, + line_numbers_left_style, + line_numbers_right_style, ) = make_line_number_styles(&opt, true_color); let syntax_theme = if syntax_theme::is_no_syntax_highlighting_theme_name(&syntax_theme_name) @@ -213,11 +213,11 @@ impl From for Config { null_style: Style::new(), null_syntect_style: SyntectStyle::default(), line_numbers_left_format: opt.line_numbers_left_format, - line_numbers_left_format_style, + line_numbers_left_style, line_numbers_minus_style, line_numbers_plus_style, line_numbers_right_format: opt.line_numbers_right_format, - line_numbers_right_format_style, + line_numbers_right_style, line_numbers_zero_style, paging_mode, plus_emph_style, @@ -379,8 +379,8 @@ fn make_line_number_styles<'a>( opt: &'a cli::Opt, true_color: bool, ) -> (Style, Style, Style, Style, Style) { - let line_numbers_left_format_style = Style::from_str( - &opt.line_numbers_left_format_style, + let line_numbers_left_style = Style::from_str( + &opt.line_numbers_left_style, None, None, None, @@ -415,8 +415,8 @@ fn make_line_number_styles<'a>( false, ); - let line_numbers_right_format_style = Style::from_str( - &opt.line_numbers_right_format_style, + let line_numbers_right_style = Style::from_str( + &opt.line_numbers_right_style, None, None, None, @@ -428,8 +428,8 @@ fn make_line_number_styles<'a>( line_numbers_minus_style, line_numbers_zero_style, line_numbers_plus_style, - line_numbers_left_format_style, - line_numbers_right_format_style, + line_numbers_left_style, + line_numbers_right_style, ) } diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs index 7602343a..76100072 100644 --- a/src/features/line_numbers.rs +++ b/src/features/line_numbers.rs @@ -44,7 +44,7 @@ pub fn format_and_paint_line_numbers<'a>( let (minus_number, plus_number) = line_numbers.unwrap(); // If both minus and plus numbers are present then the line is a zero line. - let (minus_style, plus_style) = match (minus_number, plus_number) { + let (minus_number_style, plus_number_style) = match (minus_number, plus_number) { (Some(_), Some(_)) => ( config.line_numbers_zero_style, config.line_numbers_zero_style, @@ -59,19 +59,19 @@ pub fn format_and_paint_line_numbers<'a>( formatted_numbers.extend(format_and_paint_line_number_field( &config.line_numbers_left_format, - &config.line_numbers_left_format_style, + &config.line_numbers_left_style, minus_number, plus_number, - &minus_style, - &plus_style, + &minus_number_style, + &plus_number_style, )); formatted_numbers.extend(format_and_paint_line_number_field( &config.line_numbers_right_format, - &config.line_numbers_right_format_style, + &config.line_numbers_right_style, minus_number, plus_number, - &minus_style, - &plus_style, + &minus_number_style, + &plus_number_style, )); formatted_numbers @@ -98,32 +98,36 @@ lazy_static! { fn format_and_paint_line_number_field<'a>( format_string: &'a str, - number_format_style: &Style, - minus: Option, - plus: Option, - line_numbers_minus_style: &Style, - line_numbers_plus_style: &Style, + style: &Style, + minus_number: Option, + plus_number: Option, + minus_number_style: &Style, + plus_number_style: &Style, ) -> Vec> { - let mut formatted_number_strings = Vec::new(); + let mut ansi_strings = Vec::new(); let mut offset = 0; for caps in LINE_NUMBER_FORMAT_REGEX.captures_iter(&format_string) { let _match = caps.get(0).unwrap(); - formatted_number_strings - .push(number_format_style.paint(&format_string[offset.._match.start()])); + ansi_strings.push(style.paint(&format_string[offset.._match.start()])); match &caps[1] { - "nm" => formatted_number_strings.push( - line_numbers_minus_style.paint(format_line_number(minus, &caps[3], &caps[4])), - ), - "np" => formatted_number_strings - .push(line_numbers_plus_style.paint(format_line_number(plus, &caps[3], &caps[4]))), + "nm" => ansi_strings.push(minus_number_style.paint(format_line_number( + minus_number, + &caps[3], + &caps[4], + ))), + "np" => ansi_strings.push(plus_number_style.paint(format_line_number( + plus_number, + &caps[3], + &caps[4], + ))), _ => unreachable!(), } offset = _match.end(); } - formatted_number_strings.push(number_format_style.paint(&format_string[offset..])); - formatted_number_strings + ansi_strings.push(style.paint(&format_string[offset..])); + ansi_strings } /// Return line number formatted according to `alignment` and `width`. @@ -210,11 +214,11 @@ pub mod tests { "{nm:^4}⋮", "--line-numbers-right-format", "{np:^4}│", - "--line-numbers-left-format-style", + "--line-numbers-left-style", "0 1", "--line-numbers-minus-style", "0 2", - "--line-numbers-right-format-style", + "--line-numbers-right-style", "0 3", "--line-numbers-plus-style", "0 4", @@ -235,11 +239,11 @@ pub mod tests { "{nm:^4}⋮", "--line-numbers-right-format", "{np:^4}│", - "--line-numbers-left-format-style", + "--line-numbers-left-style", "0 1", "--line-numbers-minus-style", "0 2", - "--line-numbers-right-format-style", + "--line-numbers-right-style", "0 3", "--line-numbers-plus-style", "0 4", @@ -259,11 +263,11 @@ pub mod tests { "{nm:^4}⋮", "--line-numbers-right-format", "{np:^4}│", - "--line-numbers-left-format-style", + "--line-numbers-left-style", "0 1", "--line-numbers-minus-style", "0 2", - "--line-numbers-right-format-style", + "--line-numbers-right-style", "0 3", "--line-numbers-plus-style", "0 4", @@ -284,11 +288,11 @@ pub mod tests { "{nm:^4} {nm:^4}⋮", "--line-numbers-right-format", "{np:^4}│", - "--line-numbers-left-format-style", + "--line-numbers-left-style", "0 1", "--line-numbers-minus-style", "0 2", - "--line-numbers-right-format-style", + "--line-numbers-right-style", "0 3", "--line-numbers-plus-style", "0 4", diff --git a/src/set_options.rs b/src/set_options.rs index 419f468d..7e7b68ec 100644 --- a/src/set_options.rs +++ b/src/set_options.rs @@ -78,17 +78,11 @@ pub fn set_options( ("navigate", navigate), ("line-numbers", line_numbers), ("line-numbers-left-format", line_numbers_left_format), - ( - "line-numbers-left-format-style", - line_numbers_left_format_style - ), + ("line-numbers-left-style", line_numbers_left_style), ("line-numbers-minus-style", line_numbers_minus_style), ("line-numbers-plus-style", line_numbers_plus_style), ("line-numbers-right-format", line_numbers_right_format), - ( - "line-numbers-right-format-style", - line_numbers_right_format_style - ), + ("line-numbers-right-style", line_numbers_right_style), ("line-numbers-zero-style", line_numbers_zero_style), ("paging-mode", paging_mode), // Hack: plus-style must come before plus-*emph-style because the latter default -- cgit v1.2.3