diff options
-rw-r--r-- | src/cli.rs | 8 | ||||
-rw-r--r-- | src/config.rs | 49 | ||||
-rw-r--r-- | src/features/mod.rs | 4 | ||||
-rw-r--r-- | src/features/numbers.rs | 30 | ||||
-rw-r--r-- | src/set_options.rs | 3 |
5 files changed, 50 insertions, 44 deletions
@@ -323,18 +323,16 @@ pub struct Opt { /// 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 = "number")] + #[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. Defaults to - /// --hunk-header-decoration-style. + /// 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. Defaults to - /// --hunk-header-decoration-style. + /// the old version) See STYLES and LINE NUMBERS sections. #[structopt(long = "number-plus-style", default_value = "auto")] pub number_plus_style: String, diff --git a/src/config.rs b/src/config.rs index 28020202..e7b6b868 100644 --- a/src/config.rs +++ b/src/config.rs @@ -162,11 +162,7 @@ impl From<cli::Opt> for Config { number_right_format_style, number_plus_style, number_zero_style, - ) = make_line_number_styles( - &opt, - hunk_header_style.decoration_ansi_term_style(), - true_color, - ); + ) = make_line_number_styles(&opt, true_color); let syntax_theme = if syntax_theme::is_no_syntax_highlighting_theme_name(&syntax_theme_name) { @@ -381,59 +377,34 @@ fn make_hunk_styles<'a>( fn make_line_number_styles<'a>( opt: &'a cli::Opt, - default_style: Option<ansi_term::Style>, true_color: bool, ) -> (Style, Style, Style, Style, Option<Style>) { - let (default_foreground, default_background) = match default_style { - Some(default_style) => (default_style.foreground, default_style.background), - None => (None, None), - }; - let number_left_format_style = Style::from_str( &opt.number_left_format_style, - default_foreground, - default_background, None, - true_color, - false, - ); - - let number_minus_style = Style::from_str( - &opt.number_minus_style, - default_foreground, - default_background, None, - true_color, - false, - ); - - let number_plus_style = Style::from_str( - &opt.number_plus_style, - default_foreground, - default_background, None, true_color, false, ); + let number_minus_style = + Style::from_str(&opt.number_minus_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 number_right_format_style = Style::from_str( &opt.number_right_format_style, - default_foreground, - default_background, + None, + None, None, true_color, false, ); let number_zero_style = match &opt.number_zero_style { - Some(x) => Some(Style::from_str( - x, - default_foreground, - default_background, - None, - true_color, - false, - )), + Some(x) => Some(Style::from_str(x, None, None, None, true_color, false)), None => None, }; diff --git a/src/features/mod.rs b/src/features/mod.rs index 67596633..652856a6 100644 --- a/src/features/mod.rs +++ b/src/features/mod.rs @@ -39,6 +39,10 @@ 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(), + ), + ( "navigate".to_string(), navigate::make_feature().into_iter().collect(), ), diff --git a/src/features/numbers.rs b/src/features/numbers.rs index 2f7cb2e5..92b6b7f6 100644 --- a/src/features/numbers.rs +++ b/src/features/numbers.rs @@ -3,8 +3,38 @@ use lazy_static::lazy_static; use regex::Regex; use crate::config; +use crate::features::OptionValueFunction; use crate::style::Style; +pub fn make_feature() -> Vec<(String, OptionValueFunction)> { + builtin_feature!([ + ( + "numbers", + bool, + None, + _opt => true + ), + ( + "number-minus-style", + String, + Some("color.diff.old"), + _opt => "red" + ), + ( + "number-zero-style", + Option<String>, + None, + _opt => Some("#dddddd".to_string()) + ), + ( + "number-plus-style", + String, + Some("color.diff.new"), + _opt => "green" + ) + ]) +} + /// Return a vec of `ansi_term::ANSIGenericString`s representing the left and right fields of the /// two-column line number display. pub fn format_and_paint_line_numbers<'a>( diff --git a/src/set_options.rs b/src/set_options.rs index a1cadc6b..e737b0d9 100644 --- a/src/set_options.rs +++ b/src/set_options.rs @@ -184,6 +184,9 @@ 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.navigate { features.push_front("navigate".to_string()); } |