Skip to content

Commit e3620d4

Browse files
committed
Document all the things
1 parent 709d5a7 commit e3620d4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/diff.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,32 @@ impl<'a> DiffState<'a> {
2424
eprintln!(" {line}");
2525
}
2626
}
27+
2728
fn print_skipped_msg(&self, skipped: usize) {
2829
match skipped {
30+
// When the amount of skipped lines is exactly `CONTEXT * 2`, we already
31+
// print all the context and don't actually skip anything.
2932
0 => {}
33+
// Instead of writing a line saying we skipped one line, print that one line
3034
1 => eprintln!(" {}", self.skipped_lines[CONTEXT]),
3135
_ => eprintln!("... {skipped} lines skipped ..."),
3236
}
3337
}
38+
39+
/// Print an initial `CONTEXT` amount of lines.
3440
fn print_start_skip(&self) {
3541
for line in self.skipped_lines.iter().take(CONTEXT) {
3642
eprintln!(" {line}");
3743
}
3844
}
45+
3946
fn print_skip(&mut self) {
4047
let half = self.skipped_lines.len() / 2;
4148
if !self.print_start_context {
4249
self.print_start_context = true;
4350
self.print_end_skip(self.skipped_lines.len().saturating_sub(CONTEXT));
4451
} else if half < CONTEXT {
52+
// Print all the skipped lines if the amount of context desired is less than the amount of lines
4553
for line in self.skipped_lines.drain(..) {
4654
eprintln!(" {line}");
4755
}
@@ -83,8 +91,9 @@ impl<'a> DiffState<'a> {
8391
self.skip(l);
8492
}
8593
Right(r) => {
94+
// When there's an added line after a removed line, we'll want to special case some print cases.
95+
// FIXME(oli-obk): also do special printing modes when there are multiple lines that only have minor changes.
8696
if let Some(l) = self.prev_left.take() {
87-
// If the lines only add chars or only remove chars, display an inline diff
8897
let diff = chars(l, r);
8998
let mut seen_l = false;
9099
let mut seen_r = false;
@@ -96,7 +105,8 @@ impl<'a> DiffState<'a> {
96105
}
97106
}
98107
if seen_l && seen_r {
99-
// the line both adds and removes chars, print both lines, but highlight their differences
108+
// The line both adds and removes chars, print both lines, but highlight their differences instead of
109+
// drawing the entire line in red/green.
100110
eprint!("{}", "-".red());
101111
for char in &diff {
102112
match char {
@@ -116,6 +126,7 @@ impl<'a> DiffState<'a> {
116126
}
117127
eprintln!();
118128
} else {
129+
// The line only adds or only removes chars, print a single line highlighting their differences.
119130
eprint!("{}", "~".yellow());
120131
for char in diff {
121132
match char {

0 commit comments

Comments
 (0)