diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-25 12:59:07 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-25 16:21:32 -0400 |
commit | 68071fc743ebb8126c006d66d843a6b4310bf486 (patch) | |
tree | c4d533d9851de180f70a1211acff02c820a958b9 | |
parent | 1d19643af2d5efa0b5c5c5735233083e7e6bd6ca (diff) |
Rename: --number => --line-numbers
-rw-r--r-- | src/cli.rs | 70 | ||||
-rw-r--r-- | src/config.rs | 90 | ||||
-rw-r--r-- | src/delta.rs | 2 | ||||
-rw-r--r-- | src/features/line_numbers.rs (renamed from src/features/numbers.rs) | 103 | ||||
-rw-r--r-- | src/features/mod.rs | 6 | ||||
-rw-r--r-- | src/paint.rs | 9 | ||||
-rw-r--r-- | src/set_options.rs | 26 |
7 files changed, 167 insertions, 139 deletions
@@ -318,52 +318,46 @@ pub struct Opt { /// given. pub hunk_header_decoration_style: String, - /// Display line numbers next to the diff. The first column contains line - /// numbers in the previous version of the file, and the second column contains - /// line number in the new version of the file. A blank cell in the first or - /// second column indicates that the line does not exist in that file (it was - /// added or removed, respectively). - #[structopt(short = "n", long = "numbers")] - pub show_line_numbers: bool, - - /// Style (foreground, background, attributes) for the minus file line numbers (line numbers in - /// the old version) See STYLES and LINE NUMBERS sections. - #[structopt(long = "number-minus-style", default_value = "auto")] - pub number_minus_style: String, - - /// Style (foreground, background, attributes) for the plus file line numbers (line numbers in - /// the old version) See STYLES and LINE NUMBERS sections. - #[structopt(long = "number-plus-style", default_value = "auto")] - pub number_plus_style: String, - - /// Style (foreground, background, attributes) to apply on unchanged lines (if --number is set), - /// overriding --number-minus-style and --number-plus-style. See STYLES section. - #[structopt(long = "number-zero-style", default_value = "auto")] - pub number_zero_style: String, + /// Display line numbers next to the diff. See LINE NUMBERS section. + #[structopt(short = "n", long = "line-numbers")] + pub line_numbers: bool, + + /// Style (foreground, background, attributes) for line numbers in the old (minus) version of + /// the file. See STYLES and LINE NUMBERS sections. + #[structopt(long = "line-numbers-minus-style", default_value = "auto")] + pub line_numbers_minus_style: String, + + /// Style (foreground, background, attributes) for line numbers in unchanged (zero) lines. See + /// STYLES and LINE NUMBERS sections. + #[structopt(long = "line-numbers-zero-style", default_value = "auto")] + pub line_numbers_zero_style: String, + + /// Style (foreground, background, attributes) for line numbers in the new (plus) version of + /// the file. See STYLES and LINE NUMBERS sections. + #[structopt(long = "line-numbers-plus-style", default_value = "auto")] + pub line_numbers_plus_style: String, /// Format string for the left column of line numbers. A typical value would be "{nm:^4}⋮" /// which means to display the line numbers of the minus file (old version), followed by a /// dividing character. See the LINE NUMBERS section. - #[structopt(long = "number-left-format", default_value = "{nm:^4}⋮")] - pub number_left_format: String, + #[structopt(long = "line-numbers-left-format", default_value = "{nm:^4}⋮")] + pub line_numbers_left_format: String, /// Format string for the right column of line numbers. A typical value would be "{np:^4}│ " /// which means to display the line numbers of the plus file (new version), followed by a /// dividing character, and a space. See the LINE NUMBERS section. - #[structopt(long = "number-right-format", default_value = "{np:^4}│ ")] - pub number_right_format: String, - - /// Style (foreground, background, attributes) for the left line number format string - /// (--number), if --number is set. See STYLES section. Defaults to - /// --hunk-header-decoration-style. - #[structopt(long = "number-left-format-style", default_value = "auto")] - pub number_left_format_style: String, - - /// Style (foreground, background, attributes) for the right line number format string - /// (--number), if --number is set. See STYLES section. Defaults to - /// --hunk-header-decoration-style. - #[structopt(long = "number-right-format-style", default_value = "auto")] - pub number_right_format_style: String, + #[structopt(long = "line-numbers-right-format", default_value = "{np:^4}│ ")] + pub line_numbers_right_format: String, + + /// 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, + + /// 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 = "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 32c01837..ce3e9c91 100644 --- a/src/config.rs +++ b/src/config.rs @@ -48,13 +48,13 @@ pub struct Config { pub navigate: bool, pub null_style: Style, pub null_syntect_style: SyntectStyle, - pub number_left_format: String, - pub number_left_format_style: Style, - pub number_minus_style: Style, - pub number_plus_style: Style, - pub number_right_format: String, - pub number_right_format_style: Style, - pub number_zero_style: Style, + pub line_numbers_left_format: String, + pub line_numbers_left_format_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_zero_style: Style, pub paging_mode: PagingMode, pub plus_emph_style: Style, pub plus_empty_line_marker_style: Style, @@ -62,7 +62,7 @@ pub struct Config { pub plus_non_emph_style: Style, pub plus_style: Style, pub show_background_colors: bool, - pub show_line_numbers: bool, + pub line_numbers: bool, pub syntax_dummy_theme: SyntaxTheme, pub syntax_set: SyntaxSet, pub syntax_theme: Option<SyntaxTheme>, @@ -157,11 +157,11 @@ impl From<cli::Opt> for Config { make_commit_file_hunk_header_styles(&opt, true_color); let ( - number_minus_style, - number_zero_style, - number_plus_style, - number_left_format_style, - number_right_format_style, + line_numbers_minus_style, + line_numbers_zero_style, + line_numbers_plus_style, + line_numbers_left_format_style, + line_numbers_right_format_style, ) = make_line_number_styles(&opt, true_color); let syntax_theme = if syntax_theme::is_no_syntax_highlighting_theme_name(&syntax_theme_name) @@ -212,13 +212,13 @@ impl From<cli::Opt> for Config { navigate: opt.navigate, null_style: Style::new(), null_syntect_style: SyntectStyle::default(), - number_left_format: opt.number_left_format, - number_left_format_style, - number_minus_style, - number_plus_style, - number_right_format: opt.number_right_format, - number_right_format_style, - number_zero_style, + line_numbers_left_format: opt.line_numbers_left_format, + line_numbers_left_format_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_zero_style, paging_mode, plus_emph_style, plus_empty_line_marker_style, @@ -226,7 +226,7 @@ impl From<cli::Opt> for Config { plus_non_emph_style, plus_style, show_background_colors: opt.show_background_colors, - show_line_numbers: opt.show_line_numbers, + line_numbers: opt.line_numbers, syntax_dummy_theme, syntax_set: assets.syntax_set, syntax_theme, @@ -379,8 +379,8 @@ fn make_line_number_styles<'a>( opt: &'a cli::Opt, true_color: bool, ) -> (Style, Style, Style, Style, Style) { - let number_left_format_style = Style::from_str( - &opt.number_left_format_style, + let line_numbers_left_format_style = Style::from_str( + &opt.line_numbers_left_format_style, None, None, None, @@ -388,17 +388,35 @@ fn make_line_number_styles<'a>( false, ); - let number_minus_style = - Style::from_str(&opt.number_minus_style, None, None, None, true_color, false); + let line_numbers_minus_style = Style::from_str( + &opt.line_numbers_minus_style, + None, + None, + None, + true_color, + false, + ); - let number_zero_style = - Style::from_str(&opt.number_zero_style, None, None, None, true_color, false); + let line_numbers_zero_style = Style::from_str( + &opt.line_numbers_zero_style, + None, + None, + None, + true_color, + false, + ); - let number_plus_style = - Style::from_str(&opt.number_plus_style, None, None, None, true_color, false); + let line_numbers_plus_style = Style::from_str( + &opt.line_numbers_plus_style, + None, + None, + None, + true_color, + false, + ); - let number_right_format_style = Style::from_str( - &opt.number_right_format_style, + let line_numbers_right_format_style = Style::from_str( + &opt.line_numbers_right_format_style, None, None, None, @@ -407,11 +425,11 @@ fn make_line_number_styles<'a>( ); ( - number_minus_style, - number_zero_style, - number_plus_style, - number_left_format_style, - number_right_format_style, + line_numbers_minus_style, + line_numbers_zero_style, + line_numbers_plus_style, + line_numbers_left_format_style, + line_numbers_right_format_style, ) } diff --git a/src/delta.rs b/src/delta.rs index 366520ec..37a799a4 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -423,7 +423,7 @@ fn handle_hunk_header_line( } }; - if !config.show_line_numbers { + if !config.line_numbers { let line_number = &format!("{}", painter.plus_line_number); match config.hunk_header_style.decoration_ansi_term_style() { Some(style) => writeln!(painter.writer, "{}", style.paint(line_number))?, diff --git a/src/features/numbers.rs b/src/features/line_numbers.rs index d304a04b..7602343a 100644 --- a/src/features/numbers.rs +++ b/src/features/line_numbers.rs @@ -9,25 +9,25 @@ use crate::style::Style; pub fn make_feature() -> Vec<(String, OptionValueFunction)> { builtin_feature!([ ( - "numbers", + "line-numbers", bool, None, _opt => true ), ( - "number-minus-style", + "line-numbers-minus-style", String, Some("color.diff.old"), _opt => "red" ), ( - "number-zero-style", + "line-numbers-zero-style", String, None, _opt => "#dddddd" ), ( - "number-plus-style", + "line-numbers-plus-style", String, Some("color.diff.new"), _opt => "green" @@ -44,28 +44,34 @@ 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 (number_minus_style, number_plus_style) = match (minus_number, plus_number) { - (Some(_), Some(_)) => (config.number_zero_style, config.number_zero_style), - _ => (config.number_minus_style, config.number_plus_style), + let (minus_style, plus_style) = match (minus_number, plus_number) { + (Some(_), Some(_)) => ( + config.line_numbers_zero_style, + config.line_numbers_zero_style, + ), + _ => ( + config.line_numbers_minus_style, + config.line_numbers_plus_style, + ), }; let mut formatted_numbers = Vec::new(); formatted_numbers.extend(format_and_paint_line_number_field( - &config.number_left_format, - &config.number_left_format_style, + &config.line_numbers_left_format, + &config.line_numbers_left_format_style, minus_number, plus_number, - &number_minus_style, - &number_plus_style, + &minus_style, + &plus_style, )); formatted_numbers.extend(format_and_paint_line_number_field( - &config.number_right_format, - &config.number_right_format_style, + &config.line_numbers_right_format, + &config.line_numbers_right_format_style, minus_number, plus_number, - &number_minus_style, - &number_plus_style, + &minus_style, + &plus_style, )); formatted_numbers @@ -95,8 +101,8 @@ fn format_and_paint_line_number_field<'a>( number_format_style: &Style, minus: Option<usize>, plus: Option<usize>, - number_minus_style: &Style, - number_plus_style: &Style, + line_numbers_minus_style: &Style, + line_numbers_plus_style: &Style, ) -> Vec<ansi_term::ANSIGenericString<'a, str>> { let mut formatted_number_strings = Vec::new(); @@ -107,10 +113,11 @@ fn format_and_paint_line_number_field<'a>( .push(number_format_style.paint(&format_string[offset.._match.start()])); match &caps[1] { - "nm" => formatted_number_strings - .push(number_minus_style.paint(format_line_number(minus, &caps[3], &caps[4]))), + "nm" => formatted_number_strings.push( + line_numbers_minus_style.paint(format_line_number(minus, &caps[3], &caps[4])), + ), "np" => formatted_number_strings - .push(number_plus_style.paint(format_line_number(plus, &caps[3], &caps[4]))), + .push(line_numbers_plus_style.paint(format_line_number(plus, &caps[3], &caps[4]))), _ => unreachable!(), } offset = _match.end(); @@ -198,18 +205,18 @@ pub mod tests { #[test] fn test_two_minus_lines() { let config = make_config(&[ - "--number", - "--number-left-format", + "--line-numbers", + "--line-numbers-left-format", "{nm:^4}⋮", - "--number-right-format", + "--line-numbers-right-format", "{np:^4}│", - "--number-left-format-style", + "--line-numbers-left-format-style", "0 1", - "--number-minus-style", + "--line-numbers-minus-style", "0 2", - "--number-right-format-style", + "--line-numbers-right-format-style", "0 3", - "--number-plus-style", + "--line-numbers-plus-style", "0 4", ]); let output = run_delta(TWO_MINUS_LINES_DIFF, &config); @@ -223,18 +230,18 @@ pub mod tests { #[test] fn test_two_plus_lines() { let config = make_config(&[ - "--number", - "--number-left-format", + "--line-numbers", + "--line-numbers-left-format", "{nm:^4}⋮", - "--number-right-format", + "--line-numbers-right-format", "{np:^4}│", - "--number-left-format-style", + "--line-numbers-left-format-style", "0 1", - "--number-minus-style", + "--line-numbers-minus-style", "0 2", - "--number-right-format-style", + "--line-numbers-right-format-style", "0 3", - "--number-plus-style", + "--line-numbers-plus-style", "0 4", ]); let output = run_delta(TWO_PLUS_LINES_DIFF, &config); @@ -247,18 +254,18 @@ pub mod tests { #[test] fn test_one_minus_one_plus_line() { let config = make_config(&[ - "--number", - "--number-left-format", + "--line-numbers", + "--line-numbers-left-format", "{nm:^4}⋮", - "--number-right-format", + "--line-numbers-right-format", "{np:^4}│", - "--number-left-format-style", + "--line-numbers-left-format-style", "0 1", - "--number-minus-style", + "--line-numbers-minus-style", "0 2", - "--number-right-format-style", + "--line-numbers-right-format-style", "0 3", - "--number-plus-style", + "--line-numbers-plus-style", "0 4", ]); let output = run_delta(ONE_MINUS_ONE_PLUS_LINE_DIFF, &config); @@ -272,18 +279,18 @@ pub mod tests { #[test] fn test_repeated_placeholder() { let config = make_config(&[ - "--number", - "--number-left-format", + "--line-numbers", + "--line-numbers-left-format", "{nm:^4} {nm:^4}⋮", - "--number-right-format", + "--line-numbers-right-format", "{np:^4}│", - "--number-left-format-style", + "--line-numbers-left-format-style", "0 1", - "--number-minus-style", + "--line-numbers-minus-style", "0 2", - "--number-right-format-style", + "--line-numbers-right-format-style", "0 3", - "--number-plus-style", + "--line-numbers-plus-style", "0 4", ]); let output = run_delta(ONE_MINUS_ONE_PLUS_LINE_DIFF, &config); diff --git a/src/features/mod.rs b/src/features/mod.rs index 652856a6..f5ada716 100644 --- a/src/features/mod.rs +++ b/src/features/mod.rs @@ -39,8 +39,8 @@ pub fn make_builtin_features() -> HashMap<String, BuiltinFeature> { diff_so_fancy::make_feature().into_iter().collect(), ), ( - "numbers".to_string(), - numbers::make_feature().into_iter().collect(), + "line-numbers".to_string(), + line_numbers::make_feature().into_iter().collect(), ), ( "navigate".to_string(), @@ -76,8 +76,8 @@ macro_rules! builtin_feature { pub mod color_only; pub mod diff_highlight; pub mod diff_so_fancy; +pub mod line_numbers; pub mod navigate; -pub mod numbers; #[cfg(test)] pub mod tests { diff --git a/src/paint.rs b/src/paint.rs index 14e16aa6..fa2eea87 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -10,7 +10,7 @@ use syntect::parsing::{SyntaxReference, SyntaxSet}; use crate::config; use crate::delta::State; use crate::edits; -use crate::features::numbers; +use crate::features::line_numbers; use crate::paint::superimpose_style_sections::superimpose_style_sections; use crate::style::Style; @@ -167,8 +167,11 @@ impl<'a> Painter<'a> { let mut handled_prefix = false; let mut ansi_strings = Vec::new(); - if config.show_line_numbers && line_numbers.is_some() { - ansi_strings.extend(numbers::format_and_paint_line_numbers(line_numbers, config)) + if config.line_numbers && line_numbers.is_some() { + ansi_strings.extend(line_numbers::format_and_paint_line_numbers( + line_numbers, + config, + )) } for (section_style, mut text) in superimpose_style_sections( syntax_sections, diff --git a/src/set_options.rs b/src/set_options.rs index e737b0d9..419f468d 100644 --- a/src/set_options.rs +++ b/src/set_options.rs @@ -76,14 +76,20 @@ pub fn set_options( ("minus-non-emph-style", minus_non_emph_style), ("minus-non-emph-style", minus_non_emph_style), ("navigate", navigate), - ("number", show_line_numbers), - ("number-left-format", number_left_format), - ("number-left-format-style", number_left_format_style), - ("number-minus-style", number_minus_style), - ("number-plus-style", number_plus_style), - ("number-right-format", number_right_format), - ("number-right-format-style", number_right_format_style), - ("number-zero-style", number_zero_style), + ("line-numbers", line_numbers), + ("line-numbers-left-format", line_numbers_left_format), + ( + "line-numbers-left-format-style", + line_numbers_left_format_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-zero-style", line_numbers_zero_style), ("paging-mode", paging_mode), // Hack: plus-style must come before plus-*emph-style because the latter default // dynamically to the value of the former. @@ -184,8 +190,8 @@ fn gather_features<'a>( if opt.diff_so_fancy { features.push_front("diff-so-fancy".to_string()); } - if opt.show_line_numbers { - features.push_front("numbers".to_string()); + if opt.line_numbers { + features.push_front("line-numbers".to_string()); } if opt.navigate { features.push_front("navigate".to_string()); |