@@ -24,24 +24,32 @@ impl<'a> DiffState<'a> {
24
24
eprintln ! ( " {line}" ) ;
25
25
}
26
26
}
27
+
27
28
fn print_skipped_msg ( & self , skipped : usize ) {
28
29
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.
29
32
0 => { }
33
+ // Instead of writing a line saying we skipped one line, print that one line
30
34
1 => eprintln ! ( " {}" , self . skipped_lines[ CONTEXT ] ) ,
31
35
_ => eprintln ! ( "... {skipped} lines skipped ..." ) ,
32
36
}
33
37
}
38
+
39
+ /// Print an initial `CONTEXT` amount of lines.
34
40
fn print_start_skip ( & self ) {
35
41
for line in self . skipped_lines . iter ( ) . take ( CONTEXT ) {
36
42
eprintln ! ( " {line}" ) ;
37
43
}
38
44
}
45
+
39
46
fn print_skip ( & mut self ) {
40
47
let half = self . skipped_lines . len ( ) / 2 ;
41
48
if !self . print_start_context {
42
49
self . print_start_context = true ;
43
50
self . print_end_skip ( self . skipped_lines . len ( ) . saturating_sub ( CONTEXT ) ) ;
44
51
} else if half < CONTEXT {
52
+ // Print all the skipped lines if the amount of context desired is less than the amount of lines
45
53
for line in self . skipped_lines . drain ( ..) {
46
54
eprintln ! ( " {line}" ) ;
47
55
}
@@ -83,8 +91,9 @@ impl<'a> DiffState<'a> {
83
91
self . skip ( l) ;
84
92
}
85
93
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.
86
96
if let Some ( l) = self . prev_left . take ( ) {
87
- // If the lines only add chars or only remove chars, display an inline diff
88
97
let diff = chars ( l, r) ;
89
98
let mut seen_l = false ;
90
99
let mut seen_r = false ;
@@ -96,7 +105,8 @@ impl<'a> DiffState<'a> {
96
105
}
97
106
}
98
107
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.
100
110
eprint ! ( "{}" , "-" . red( ) ) ;
101
111
for char in & diff {
102
112
match char {
@@ -116,6 +126,7 @@ impl<'a> DiffState<'a> {
116
126
}
117
127
eprintln ! ( ) ;
118
128
} else {
129
+ // The line only adds or only removes chars, print a single line highlighting their differences.
119
130
eprint ! ( "{}" , "~" . yellow( ) ) ;
120
131
for char in diff {
121
132
match char {
0 commit comments