summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-06-25 11:02:03 -0400
committerDan Davison <dandavison7@gmail.com>2020-06-25 15:18:19 -0400
commit1d19643af2d5efa0b5c5c5735233083e7e6bd6ca (patch)
tree8da994ef95b3afa4e5a12128e49a03b8dd3b95f8
parent1478ce4d160711d416ddcd0cbb5b5de43e5254a2 (diff)
Make number-zero-style non-Option
-rw-r--r--src/cli.rs4
-rw-r--r--src/config.rs24
-rw-r--r--src/features/numbers.rs13
3 files changed, 19 insertions, 22 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 5136f6cb..6ec520a9 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -338,8 +338,8 @@ pub struct Opt {
/// 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")]
- pub number_zero_style: Option<String>,
+ #[structopt(long = "number-zero-style", default_value = "auto")]
+ pub number_zero_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
diff --git a/src/config.rs b/src/config.rs
index e7b6b868..32c01837 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -54,7 +54,7 @@ pub struct Config {
pub number_plus_style: Style,
pub number_right_format: String,
pub number_right_format_style: Style,
- pub number_zero_style: Option<Style>,
+ pub number_zero_style: Style,
pub paging_mode: PagingMode,
pub plus_emph_style: Style,
pub plus_empty_line_marker_style: Style,
@@ -157,11 +157,11 @@ impl From<cli::Opt> for Config {
make_commit_file_hunk_header_styles(&opt, true_color);
let (
- number_left_format_style,
number_minus_style,
- number_right_format_style,
- number_plus_style,
number_zero_style,
+ number_plus_style,
+ number_left_format_style,
+ number_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)
@@ -378,7 +378,7 @@ fn make_hunk_styles<'a>(
fn make_line_number_styles<'a>(
opt: &'a cli::Opt,
true_color: bool,
-) -> (Style, Style, Style, Style, Option<Style>) {
+) -> (Style, Style, Style, Style, Style) {
let number_left_format_style = Style::from_str(
&opt.number_left_format_style,
None,
@@ -391,6 +391,9 @@ fn make_line_number_styles<'a>(
let number_minus_style =
Style::from_str(&opt.number_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 number_plus_style =
Style::from_str(&opt.number_plus_style, None, None, None, true_color, false);
@@ -403,17 +406,12 @@ fn make_line_number_styles<'a>(
false,
);
- let number_zero_style = match &opt.number_zero_style {
- Some(x) => Some(Style::from_str(x, None, None, None, true_color, false)),
- None => None,
- };
-
(
- number_left_format_style,
number_minus_style,
- number_right_format_style,
- number_plus_style,
number_zero_style,
+ number_plus_style,
+ number_left_format_style,
+ number_right_format_style,
)
}
diff --git a/src/features/numbers.rs b/src/features/numbers.rs
index 92b6b7f6..d304a04b 100644
--- a/src/features/numbers.rs
+++ b/src/features/numbers.rs
@@ -22,9 +22,9 @@ pub fn make_feature() -> Vec<(String, OptionValueFunction)> {
),
(
"number-zero-style",
- Option<String>,
+ String,
None,
- _opt => Some("#dddddd".to_string())
+ _opt => "#dddddd"
),
(
"number-plus-style",
@@ -44,11 +44,10 @@ 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, config.number_zero_style) {
- (Some(_), Some(_), Some(zero_style)) => (zero_style, zero_style),
- _ => (config.number_minus_style, config.number_plus_style),
- };
+ 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 mut formatted_numbers = Vec::new();