Skip to content

Commit 9fc4372

Browse files
AMDmi3Wilfred
authored andcommitted
Make --color affect missing line number formatting
Fixes #213
1 parent ce076a1 commit 9fc4372

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Diff for: src/side_by_side.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn format_missing_line_num(
3737
prev_num: LineNumber,
3838
source_dims: &SourceDimensions,
3939
is_lhs: bool,
40+
use_color: bool,
4041
) -> String {
4142
let column_width = if is_lhs {
4243
source_dims.lhs_line_nums_width
@@ -54,13 +55,18 @@ fn format_missing_line_num(
5455
return "".into();
5556
}
5657

58+
let mut style = Style::new();
59+
if use_color {
60+
style = style.dimmed();
61+
}
62+
5763
let num_digits = format!("{}", prev_num.one_indexed()).len();
5864
format!(
5965
"{:>width$} ",
6066
(if after_end { " " } else { "." }).repeat(num_digits),
6167
width = column_width - 1
6268
)
63-
.dimmed()
69+
.style(style)
6470
.to_string()
6571
}
6672

@@ -133,6 +139,7 @@ fn display_line_nums(
133139
prev_lhs_line_num.unwrap_or_else(|| 1.into()),
134140
source_dims,
135141
true,
142+
use_color,
136143
),
137144
};
138145
let display_rhs_line_num: String = match rhs_line_num {
@@ -152,6 +159,7 @@ fn display_line_nums(
152159
prev_rhs_line_num.unwrap_or_else(|| 1.into()),
153160
source_dims,
154161
false,
162+
use_color,
155163
),
156164
};
157165

@@ -469,6 +477,7 @@ pub fn print(
469477
.unwrap_or_else(|| prev_lhs_line_num.unwrap_or_else(|| 10.into())),
470478
&source_dims,
471479
true,
480+
use_color,
472481
);
473482
if let Some(line_num) = lhs_line_num {
474483
if lhs_lines_with_novel.contains(&line_num) {
@@ -489,6 +498,7 @@ pub fn print(
489498
.unwrap_or_else(|| prev_rhs_line_num.unwrap_or_else(|| 10.into())),
490499
&source_dims,
491500
false,
501+
use_color,
492502
);
493503
if let Some(line_num) = rhs_line_num {
494504
if rhs_lines_with_novel.contains(&line_num) {
@@ -551,9 +561,13 @@ mod tests {
551561
);
552562

553563
assert_eq!(
554-
format_missing_line_num(0.into(), &source_dims, true),
564+
format_missing_line_num(0.into(), &source_dims, true, true),
555565
". ".dimmed().to_string()
556566
);
567+
assert_eq!(
568+
format_missing_line_num(0.into(), &source_dims, true, false),
569+
". ".to_string()
570+
);
557571
}
558572

559573
#[test]
@@ -569,9 +583,13 @@ mod tests {
569583
);
570584

571585
assert_eq!(
572-
format_missing_line_num(1.into(), &source_dims, true),
586+
format_missing_line_num(1.into(), &source_dims, true, true),
573587
" ".dimmed().to_string()
574588
);
589+
assert_eq!(
590+
format_missing_line_num(1.into(), &source_dims, true, false),
591+
" ".to_string()
592+
);
575593
}
576594

577595
#[test]

0 commit comments

Comments
 (0)