on main help sign in
fix(diffview): improve code width and make it half space on each side
eb50c92Andrey Nering
internal/exp/diffview/diffview.go+39−38
@@ -43,9 +43,10 @@ type DiffView struct {
43 unified udiff.UnifiedDiff
43 unified udiff.UnifiedDiff
44 edits []udiff.Edit
44 edits []udiff.Edit
45
45
46− splitHunks []splitHunk
46+ splitHunks []splitHunk
47− beforeCodeWidth int
47+
48− afterCodeWidth int
48+ codeWidth int
49+ fullCodeWidth int // with leading symbols
49}
50}
50
51
51// New creates a new DiffView with default settings.
52// New creates a new DiffView with default settings.
@@ -128,6 +129,8 @@ func (dv *DiffView) String() string {
128 if err := dv.computeDiff(); err != nil {
129 if err := dv.computeDiff(); err != nil {
129 return err.Error()
130 return err.Error()
130 }
131 }
132+ dv.convertDiffToSplit()
133+ dv.detectCodeWidth()
131
134
132 switch dv.layout {
135 switch dv.layout {
133 case layoutUnified:
136 case layoutUnified:
@@ -141,9 +144,6 @@ func (dv *DiffView) String() string {
141
144
142// renderUnified renders the unified diff view as a string.
145// renderUnified renders the unified diff view as a string.
143func (dv *DiffView) renderUnified() string {
146func (dv *DiffView) renderUnified() string {
144− dv.detectUnifiedWidth()
145−
146− codeWidth := dv.width - leadingSymbolsSize
147 beforeNumDigits, afterNumDigits := dv.lineNumberDigits()
147 beforeNumDigits, afterNumDigits := dv.lineNumberDigits()
148
148
149 var b strings.Builder
149 var b strings.Builder
@@ -153,7 +153,7 @@ func (dv *DiffView) renderUnified() string {
153 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", beforeNumDigits)))
153 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", beforeNumDigits)))
154 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", afterNumDigits)))
154 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", afterNumDigits)))
155 }
155 }
156− b.WriteString(dv.style.DividerLine.Code.Width(codeWidth + leadingSymbolsSize).Render(dv.hunkLineFor(h)))
156+ b.WriteString(dv.style.DividerLine.Code.Width(dv.fullCodeWidth).Render(dv.hunkLineFor(h)))
157 b.WriteRune('\n')
157 b.WriteRune('\n')
158
158
159 beforeLine := h.FromLine
159 beforeLine := h.FromLine
@@ -168,7 +168,7 @@ func (dv *DiffView) renderUnified() string {
168 b.WriteString(dv.style.EqualLine.LineNumber.Render(pad(beforeLine, beforeNumDigits)))
168 b.WriteString(dv.style.EqualLine.LineNumber.Render(pad(beforeLine, beforeNumDigits)))
169 b.WriteString(dv.style.EqualLine.LineNumber.Render(pad(afterLine, afterNumDigits)))
169 b.WriteString(dv.style.EqualLine.LineNumber.Render(pad(afterLine, afterNumDigits)))
170 }
170 }
171− b.WriteString(dv.style.EqualLine.Code.Width(codeWidth + leadingSymbolsSize).Render(" " + content))
171+ b.WriteString(dv.style.EqualLine.Code.Width(dv.fullCodeWidth).Render(" " + content))
172 beforeLine++
172 beforeLine++
173 afterLine++
173 afterLine++
174 case udiff.Insert:
174 case udiff.Insert:
@@ -177,7 +177,7 @@ func (dv *DiffView) renderUnified() string {
177 b.WriteString(dv.style.InsertLine.LineNumber.Render(pad(afterLine, afterNumDigits)))
177 b.WriteString(dv.style.InsertLine.LineNumber.Render(pad(afterLine, afterNumDigits)))
178 }
178 }
179 b.WriteString(dv.style.InsertLine.Symbol.Render("+ "))
179 b.WriteString(dv.style.InsertLine.Symbol.Render("+ "))
180− b.WriteString(dv.style.InsertLine.Code.Width(codeWidth).Render(content))
180+ b.WriteString(dv.style.InsertLine.Code.Width(dv.codeWidth).Render(content))
181 afterLine++
181 afterLine++
182 case udiff.Delete:
182 case udiff.Delete:
183 if dv.lineNumbers {
183 if dv.lineNumbers {
@@ -185,7 +185,7 @@ func (dv *DiffView) renderUnified() string {
185 b.WriteString(dv.style.DeleteLine.LineNumber.Render(pad(" ", afterNumDigits)))
185 b.WriteString(dv.style.DeleteLine.LineNumber.Render(pad(" ", afterNumDigits)))
186 }
186 }
187 b.WriteString(dv.style.DeleteLine.Symbol.Render("- "))
187 b.WriteString(dv.style.DeleteLine.Symbol.Render("- "))
188− b.WriteString(dv.style.DeleteLine.Code.Width(codeWidth).Render(content))
188+ b.WriteString(dv.style.DeleteLine.Code.Width(dv.codeWidth).Render(content))
189 beforeLine++
189 beforeLine++
190 }
190 }
191 b.WriteRune('\n')
191 b.WriteRune('\n')
@@ -197,9 +197,6 @@ func (dv *DiffView) renderUnified() string {
197
197
198// renderSplit renders the split (side-by-side) diff view as a string.
198// renderSplit renders the split (side-by-side) diff view as a string.
199func (dv *DiffView) renderSplit() string {
199func (dv *DiffView) renderSplit() string {
200− dv.convertDiffToSplit()
201− dv.detectSplitWidth()
202−
203 beforeNumDigits, afterNumDigits := dv.lineNumberDigits()
200 beforeNumDigits, afterNumDigits := dv.lineNumberDigits()
204
201
205 var b strings.Builder
202 var b strings.Builder
@@ -208,11 +205,11 @@ func (dv *DiffView) renderSplit() string {
208 if dv.lineNumbers {
205 if dv.lineNumbers {
209 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", beforeNumDigits)))
206 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", beforeNumDigits)))
210 }
207 }
211− b.WriteString(dv.style.DividerLine.Code.Width(dv.beforeCodeWidth + leadingSymbolsSize).Render(dv.hunkLineFor(dv.unified.Hunks[i])))
208+ b.WriteString(dv.style.DividerLine.Code.Width(dv.fullCodeWidth).Render(dv.hunkLineFor(dv.unified.Hunks[i])))
212 if dv.lineNumbers {
209 if dv.lineNumbers {
213 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", afterNumDigits)))
210 b.WriteString(dv.style.DividerLine.LineNumber.Render(pad("…", afterNumDigits)))
214 }
211 }
215− b.WriteString(dv.style.DividerLine.Code.Width(dv.afterCodeWidth + leadingSymbolsSize).Render(" "))
212+ b.WriteString(dv.style.DividerLine.Code.Width(dv.fullCodeWidth).Render(" "))
216 b.WriteRune('\n')
213 b.WriteRune('\n')
217
214
218 beforeLine := h.fromLine
215 beforeLine := h.fromLine
@@ -233,19 +230,19 @@ func (dv *DiffView) renderSplit() string {
233 if dv.lineNumbers {
230 if dv.lineNumbers {
234 b.WriteString(dv.style.MissingLine.LineNumber.Render(pad(" ", beforeNumDigits)))
231 b.WriteString(dv.style.MissingLine.LineNumber.Render(pad(" ", beforeNumDigits)))
235 }
232 }
236− b.WriteString(dv.style.MissingLine.Code.Width(dv.beforeCodeWidth + leadingSymbolsSize).Render(" "))
233+ b.WriteString(dv.style.MissingLine.Code.Width(dv.fullCodeWidth).Render(" "))
237 case l.before.Kind == udiff.Equal:
234 case l.before.Kind == udiff.Equal:
238 if dv.lineNumbers {
235 if dv.lineNumbers {
239 b.WriteString(dv.style.EqualLine.LineNumber.Render(pad(beforeLine, beforeNumDigits)))
236 b.WriteString(dv.style.EqualLine.LineNumber.Render(pad(beforeLine, beforeNumDigits)))
240 }
237 }
241− b.WriteString(dv.style.EqualLine.Code.Width(dv.beforeCodeWidth + leadingSymbolsSize).Render(" " + beforeContent))
238+ b.WriteString(dv.style.EqualLine.Code.Width(dv.fullCodeWidth).Render(" " + beforeContent))
242 beforeLine++
239 beforeLine++
243 case l.before.Kind == udiff.Delete:
240 case l.before.Kind == udiff.Delete:
244 if dv.lineNumbers {
241 if dv.lineNumbers {
245 b.WriteString(dv.style.DeleteLine.LineNumber.Render(pad(beforeLine, beforeNumDigits)))
242 b.WriteString(dv.style.DeleteLine.LineNumber.Render(pad(beforeLine, beforeNumDigits)))
246 }
243 }
247 b.WriteString(dv.style.DeleteLine.Symbol.Render("- "))
244 b.WriteString(dv.style.DeleteLine.Symbol.Render("- "))
248− b.WriteString(dv.style.DeleteLine.Code.Width(dv.beforeCodeWidth).Render(beforeContent))
245+ b.WriteString(dv.style.DeleteLine.Code.Width(dv.codeWidth).Render(beforeContent))
249 beforeLine++
246 beforeLine++
250 }
247 }
251
248
@@ -254,19 +251,19 @@ func (dv *DiffView) renderSplit() string {
254 if dv.lineNumbers {
251 if dv.lineNumbers {
255 b.WriteString(dv.style.MissingLine.LineNumber.Render(pad(" ", afterNumDigits)))
252 b.WriteString(dv.style.MissingLine.LineNumber.Render(pad(" ", afterNumDigits)))
256 }
253 }
257− b.WriteString(dv.style.MissingLine.Code.Width(dv.afterCodeWidth + leadingSymbolsSize).Render(" "))
254+ b.WriteString(dv.style.MissingLine.Code.Width(dv.fullCodeWidth).Render(" "))
258 case l.after.Kind == udiff.Equal:
255 case l.after.Kind == udiff.Equal:
259 if dv.lineNumbers {
256 if dv.lineNumbers {
260 b.WriteString(dv.style.EqualLine.LineNumber.Render(pad(afterLine, afterNumDigits)))
257 b.WriteString(dv.style.EqualLine.LineNumber.Render(pad(afterLine, afterNumDigits)))
261 }
258 }
262− b.WriteString(dv.style.EqualLine.Code.Width(dv.afterCodeWidth + leadingSymbolsSize).Render(" " + afterContent))
259+ b.WriteString(dv.style.EqualLine.Code.Width(dv.fullCodeWidth).Render(" " + afterContent))
263 afterLine++
260 afterLine++
264 case l.after.Kind == udiff.Insert:
261 case l.after.Kind == udiff.Insert:
265 if dv.lineNumbers {
262 if dv.lineNumbers {
266 b.WriteString(dv.style.InsertLine.LineNumber.Render(pad(afterLine, afterNumDigits)))
263 b.WriteString(dv.style.InsertLine.LineNumber.Render(pad(afterLine, afterNumDigits)))
267 }
264 }
268 b.WriteString(dv.style.InsertLine.Symbol.Render("+ "))
265 b.WriteString(dv.style.InsertLine.Symbol.Render("+ "))
269− b.WriteString(dv.style.InsertLine.Code.Width(dv.afterCodeWidth).Render(afterContent))
266+ b.WriteString(dv.style.InsertLine.Code.Width(dv.codeWidth).Render(afterContent))
270 afterLine++
267 afterLine++
271 }
268 }
272
269
@@ -335,51 +332,55 @@ func (dv *DiffView) hunkShownLines(h *udiff.Hunk) (before, after int) {
335 return
332 return
336}
333}
337
334
338−func (dv *DiffView) detectUnifiedWidth() {
335+func (dv *DiffView) detectCodeWidth() {
339− if dv.width > 0 {
336+ switch dv.layout {
340− return
337+ case layoutUnified:
338+ dv.detectUnifiedCodeWidth()
339+ case layoutSplit:
340+ dv.detectSplitCodeWidth()
341 }
341 }
342+ dv.fullCodeWidth = dv.codeWidth + leadingSymbolsSize
343+}
344+
345+func (dv *DiffView) detectUnifiedCodeWidth() {
346+ dv.codeWidth = 0
342
347
343 for _, h := range dv.unified.Hunks {
348 for _, h := range dv.unified.Hunks {
344 shownLines := ansi.StringWidth(dv.hunkLineFor(h))
349 shownLines := ansi.StringWidth(dv.hunkLineFor(h))
345
350
346 for _, l := range h.Lines {
351 for _, l := range h.Lines {
347− lineWidth := ansi.StringWidth(strings.TrimSuffix(l.Content, "\n"))
352+ lineWidth := ansi.StringWidth(strings.TrimSuffix(l.Content, "\n")) + 1
348− lineWidth += leadingSymbolsSize
349− dv.width = max(dv.width, lineWidth, shownLines)
353+ dv.codeWidth = max(dv.codeWidth, lineWidth, shownLines)
350 }
354 }
351 }
355 }
352}
356}
353
357
354func (dv *DiffView) convertDiffToSplit() {
358func (dv *DiffView) convertDiffToSplit() {
359+ if dv.layout != layoutSplit {
360+ return
361+ }
362+
355 dv.splitHunks = make([]splitHunk, len(dv.unified.Hunks))
363 dv.splitHunks = make([]splitHunk, len(dv.unified.Hunks))
356 for i, h := range dv.unified.Hunks {
364 for i, h := range dv.unified.Hunks {
357 dv.splitHunks[i] = hunkToSplit(h)
365 dv.splitHunks[i] = hunkToSplit(h)
358 }
366 }
359}
367}
360
368
361−func (dv *DiffView) detectSplitWidth() {
369+func (dv *DiffView) detectSplitCodeWidth() {
362− if dv.width > 0 {
370+ dv.codeWidth = 0
363− return
364− }
365
371
366 for i, h := range dv.splitHunks {
372 for i, h := range dv.splitHunks {
367 shownLines := ansi.StringWidth(dv.hunkLineFor(dv.unified.Hunks[i]))
373 shownLines := ansi.StringWidth(dv.hunkLineFor(dv.unified.Hunks[i]))
368
374
369 for _, l := range h.lines {
375 for _, l := range h.lines {
370− var lineWidth int
371 if l.before != nil {
376 if l.before != nil {
372 codeWidth := ansi.StringWidth(strings.TrimSuffix(l.before.Content, "\n")) + 1
377 codeWidth := ansi.StringWidth(strings.TrimSuffix(l.before.Content, "\n")) + 1
373− dv.beforeCodeWidth = max(dv.beforeCodeWidth, codeWidth, shownLines)
378+ dv.codeWidth = max(dv.codeWidth, codeWidth, shownLines)
374− lineWidth += codeWidth
375 }
379 }
376 if l.after != nil {
380 if l.after != nil {
377 codeWidth := ansi.StringWidth(strings.TrimSuffix(l.after.Content, "\n")) + 1
381 codeWidth := ansi.StringWidth(strings.TrimSuffix(l.after.Content, "\n")) + 1
378− dv.afterCodeWidth = max(dv.afterCodeWidth, codeWidth, shownLines)
382+ dv.codeWidth = max(dv.codeWidth, codeWidth, shownLines)
379− lineWidth += codeWidth
380 }
383 }
381− lineWidth += leadingSymbolsSize * 2
382− dv.width = max(dv.width, lineWidth, shownLines)
383 }
384 }
384 }
385 }
385}
386}
internal/exp/diffview/testdata/TestDiffView/Split/CustomContextLines/DarkMode.golden+16−16
@@ -1,16 +1,16 @@
1−  …  @@ -1,13 +1,15 @@    …   
1+  …  @@ -1,13 +1,15 @@    …   
2−  1  package main   1  package main 
2+  1  package main   1  package main 
3−  2     2   
3+  2     2   
4−  3  import (   3  import ( 
4+  3  import (   3  import ( 
5−  4  "fmt"   4  "fmt" 
5+  4  "fmt"   4  "fmt" 
6−       5 +  "strings" 
6+       5 +  "strings" 
7−  5  )   6  ) 
7+  5  )   6  ) 
8−  6     7   
8+  6     7   
9−  7  func main() {   8  func main() { 
9+  7  func main() {   8  func main() { 
10−  8  fmt.Println(getContent())   9  fmt.Println(getContent()) 
10+  8  fmt.Println(getContent())   9  fmt.Println(getContent()) 
11−  9  }  10  } 
11+  9  }  10  } 
12− 10    11   
12+ 10    11   
13− 11  func getContent() string {  12  func getContent() string { 
13+ 11  func getContent() string {  12  func getContent() string { 
14− 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14+ 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
15−      14 +  return content 
15+      14 +  return content 
16− 13  }  15  } 
16+ 13  }  15  } 
internal/exp/diffview/testdata/TestDiffView/Split/CustomContextLines/LightMode.golden+16−16
@@ -1,16 +1,16 @@
1−  …  @@ -1,13 +1,15 @@    …   
1+  …  @@ -1,13 +1,15 @@    …   
2−  1  package main   1  package main 
2+  1  package main   1  package main 
3−  2     2   
3+  2     2   
4−  3  import (   3  import ( 
4+  3  import (   3  import ( 
5−  4  "fmt"   4  "fmt" 
5+  4  "fmt"   4  "fmt" 
6−       5 +  "strings" 
6+       5 +  "strings" 
7−  5  )   6  ) 
7+  5  )   6  ) 
8−  6     7   
8+  6     7   
9−  7  func main() {   8  func main() { 
9+  7  func main() {   8  func main() { 
10−  8  fmt.Println(getContent())   9  fmt.Println(getContent()) 
10+  8  fmt.Println(getContent())   9  fmt.Println(getContent()) 
11−  9  }  10  } 
11+  9  }  10  } 
12− 10    11   
12+ 10    11   
13− 11  func getContent() string {  12  func getContent() string { 
13+ 11  func getContent() string {  12  func getContent() string { 
14− 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14+ 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
15−      14 +  return content 
15+      14 +  return content 
16− 13  }  15  } 
16+ 13  }  15  } 
internal/exp/diffview/testdata/TestDiffView/Split/Default/DarkMode.golden+7−7
@@ -1,7 +1,7 @@
1−  …  @@ -5,5 +5,6 @@    …   
1+  …  @@ -5,5 +5,6 @@    …   
2−  5  )   5  ) 
2+  5  )   5  ) 
3−  6     6   
3+  6     6   
4−  7  func main() {   7  func main() { 
4+  7  func main() {   7  func main() { 
5−  8 -  fmt.Println("Hello, world!")   8 +  content := "Hello, world!" 
5+  8 -  fmt.Println("Hello, world!")   8 +  content := "Hello, world!" 
6−       9 +  fmt.Println(content) 
6+       9 +  fmt.Println(content) 
7−  9  }  10  } 
7+  9  }  10  } 
internal/exp/diffview/testdata/TestDiffView/Split/Default/LightMode.golden+7−7
@@ -1,7 +1,7 @@
1−  …  @@ -5,5 +5,6 @@    …   
1+  …  @@ -5,5 +5,6 @@    …   
2−  5  )   5  ) 
2+  5  )   5  ) 
3−  6     6   
3+  6     6   
4−  7  func main() {   7  func main() { 
4+  7  func main() {   7  func main() { 
5−  8 -  fmt.Println("Hello, world!")   8 +  content := "Hello, world!" 
5+  8 -  fmt.Println("Hello, world!")   8 +  content := "Hello, world!" 
6−       9 +  fmt.Println(content) 
6+       9 +  fmt.Println(content) 
7−  9  }  10  } 
7+  9  }  10  } 
internal/exp/diffview/testdata/TestDiffView/Split/MultipleHunks/DarkMode.golden+15−15
@@ -1,15 +1,15 @@
1−  …  @@ -2,6 +2,7 @@    …   
1+  …  @@ -2,6 +2,7 @@    …   
2−  2     2   
2+  2     2   
3−  3  import (   3  import ( 
3+  3  import (   3  import ( 
4−  4  "fmt"   4  "fmt" 
4+  4  "fmt"   4  "fmt" 
5−       5 +  "strings" 
5+       5 +  "strings" 
6−  5  )   6  ) 
6+  5  )   6  ) 
7−  6     7   
7+  6     7   
8−  7  func main() {   8  func main() { 
8+  7  func main() {   8  func main() { 
9−  …  @@ -9,5 +10,6 @@    …   
9+  …  @@ -9,5 +10,6 @@    …   
10−  9  }  10  } 
10+  9  }  10  } 
11− 10    11   
11+ 10    11   
12− 11  func getContent() string {  12  func getContent() string { 
12+ 11  func getContent() string {  12  func getContent() string { 
13− 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13+ 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14−      14 +  return content 
14+      14 +  return content 
15− 13  }  15  } 
15+ 13  }  15  } 
internal/exp/diffview/testdata/TestDiffView/Split/MultipleHunks/LightMode.golden+15−15
@@ -1,15 +1,15 @@
1−  …  @@ -2,6 +2,7 @@    …   
1+  …  @@ -2,6 +2,7 @@    …   
2−  2     2   
2+  2     2   
3−  3  import (   3  import ( 
3+  3  import (   3  import ( 
4−  4  "fmt"   4  "fmt" 
4+  4  "fmt"   4  "fmt" 
5−       5 +  "strings" 
5+       5 +  "strings" 
6−  5  )   6  ) 
6+  5  )   6  ) 
7−  6     7   
7+  6     7   
8−  7  func main() {   8  func main() { 
8+  7  func main() {   8  func main() { 
9−  …  @@ -9,5 +10,6 @@    …   
9+  …  @@ -9,5 +10,6 @@    …   
10−  9  }  10  } 
10+  9  }  10  } 
11− 10    11   
11+ 10    11   
12− 11  func getContent() string {  12  func getContent() string { 
12+ 11  func getContent() string {  12  func getContent() string { 
13− 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
13+ 12 -  return "Hello, world!"  13 +  content := strings.ToUpper("Hello, World!") 
14−      14 +  return content 
14+      14 +  return content 
15− 13  }  15  } 
15+ 13  }  15  } 
internal/exp/diffview/testdata/TestDiffView/Split/NoLineNumbers/DarkMode.golden+7−7
@@ -1,7 +1,7 @@
1− @@ -5,5 +5,6 @@    
1+ @@ -5,5 +5,6 @@    
2− )  ) 
2+ )  ) 
3−    
3+    
4− func main() {  func main() { 
4+ func main() {  func main() { 
5−-  fmt.Println("Hello, world!") +  content := "Hello, world!" 
5+-  fmt.Println("Hello, world!") +  content := "Hello, world!" 
6−  +  fmt.Println(content) 
6+  +  fmt.Println(content) 
7− }  } 
7+ }  } 
internal/exp/diffview/testdata/TestDiffView/Split/NoLineNumbers/LightMode.golden+7−7
@@ -1,7 +1,7 @@
1− @@ -5,5 +5,6 @@    
1+ @@ -5,5 +5,6 @@    
2− )  ) 
2+ )  ) 
3−    
3+    
4− func main() {  func main() { 
4+ func main() {  func main() { 
5−-  fmt.Println("Hello, world!") +  content := "Hello, world!" 
5+-  fmt.Println("Hello, world!") +  content := "Hello, world!" 
6−  +  fmt.Println(content) 
6+  +  fmt.Println(content) 
7− }  } 
7+ }  } 
internal/exp/diffview/testdata/TestDiffView/Unified/CustomContextLines/DarkMode.golden+17−17
@@ -1,17 +1,17 @@
1−  …   …  @@ -1,13 +1,15 @@  
1+  …   …  @@ -1,13 +1,15 @@  
2−  1   1  package main 
2+  1   1  package main 
3−  2   2   
3+  2   2   
4−  3   3  import ( 
4+  3   3  import ( 
5−  4   4  "fmt" 
5+  4   4  "fmt" 
6−     5 +  "strings" 
6+     5 +  "strings" 
7−  5   6  ) 
7+  5   6  ) 
8−  6   7   
8+  6   7   
9−  7   8  func main() { 
9+  7   8  func main() { 
10−  8   9  fmt.Println(getContent()) 
10+  8   9  fmt.Println(getContent()) 
11−  9  10  } 
11+  9  10  } 
12− 10  11   
12+ 10  11   
13− 11  12  func getContent() string { 
13+ 11  12  func getContent() string { 
14− 12    -  return "Hello, world!" 
14+ 12    -  return "Hello, world!" 
15−    13 +  content := strings.ToUpper("Hello, World!")
15+    13 +  content := strings.ToUpper("Hello, World!") 
16−    14 +  return content 
16+    14 +  return content 
17− 13  15  } 
17+ 13  15  } 
internal/exp/diffview/testdata/TestDiffView/Unified/CustomContextLines/LightMode.golden+17−17
@@ -1,17 +1,17 @@
1−  …   …  @@ -1,13 +1,15 @@  
1+  …   …  @@ -1,13 +1,15 @@  
2−  1   1  package main 
2+  1   1  package main 
3−  2   2   
3+  2   2   
4−  3   3  import ( 
4+  3   3  import ( 
5−  4   4  "fmt" 
5+  4   4  "fmt" 
6−     5 +  "strings" 
6+     5 +  "strings" 
7−  5   6  ) 
7+  5   6  ) 
8−  6   7   
8+  6   7   
9−  7   8  func main() { 
9+  7   8  func main() { 
10−  8   9  fmt.Println(getContent()) 
10+  8   9  fmt.Println(getContent()) 
11−  9  10  } 
11+  9  10  } 
12− 10  11   
12+ 10  11   
13− 11  12  func getContent() string { 
13+ 11  12  func getContent() string { 
14− 12    -  return "Hello, world!" 
14+ 12    -  return "Hello, world!" 
15−    13 +  content := strings.ToUpper("Hello, World!")
15+    13 +  content := strings.ToUpper("Hello, World!") 
16−    14 +  return content 
16+    14 +  return content 
17− 13  15  } 
17+ 13  15  } 
internal/exp/diffview/testdata/TestDiffView/Unified/Default/DarkMode.golden+8−8
@@ -1,8 +1,8 @@
1−  …   …  @@ -5,5 +5,6 @@  
1+  …   …  @@ -5,5 +5,6 @@  
2−  5   5  ) 
2+  5   5  ) 
3−  6   6   
3+  6   6   
4−  7   7  func main() { 
4+  7   7  func main() { 
5−  8    -  fmt.Println("Hello, world!")
5+  8    -  fmt.Println("Hello, world!") 
6−     8 +  content := "Hello, world!" 
6+     8 +  content := "Hello, world!" 
7−     9 +  fmt.Println(content) 
7+     9 +  fmt.Println(content) 
8−  9  10  } 
8+  9  10  } 
internal/exp/diffview/testdata/TestDiffView/Unified/Default/LightMode.golden+8−8
@@ -1,8 +1,8 @@
1−  …   …  @@ -5,5 +5,6 @@  
1+  …   …  @@ -5,5 +5,6 @@  
2−  5   5  ) 
2+  5   5  ) 
3−  6   6   
3+  6   6   
4−  7   7  func main() { 
4+  7   7  func main() { 
5−  8    -  fmt.Println("Hello, world!")
5+  8    -  fmt.Println("Hello, world!") 
6−     8 +  content := "Hello, world!" 
6+     8 +  content := "Hello, world!" 
7−     9 +  fmt.Println(content) 
7+     9 +  fmt.Println(content) 
8−  9  10  } 
8+  9  10  } 
internal/exp/diffview/testdata/TestDiffView/Unified/MultipleHunks/DarkMode.golden+16−16
@@ -1,16 +1,16 @@
1−  …   …  @@ -2,6 +2,7 @@  
1+  …   …  @@ -2,6 +2,7 @@  
2−  2   2   
2+  2   2   
3−  3   3  import ( 
3+  3   3  import ( 
4−  4   4  "fmt" 
4+  4   4  "fmt" 
5−     5 +  "strings" 
5+     5 +  "strings" 
6−  5   6  ) 
6+  5   6  ) 
7−  6   7   
7+  6   7   
8−  7   8  func main() { 
8+  7   8  func main() { 
9−  …   …  @@ -9,5 +10,6 @@  
9+  …   …  @@ -9,5 +10,6 @@  
10−  9  10  } 
10+  9  10  } 
11− 10  11   
11+ 10  11   
12− 11  12  func getContent() string { 
12+ 11  12  func getContent() string { 
13− 12    -  return "Hello, world!" 
13+ 12    -  return "Hello, world!" 
14−    13 +  content := strings.ToUpper("Hello, World!")
14+    13 +  content := strings.ToUpper("Hello, World!") 
15−    14 +  return content 
15+    14 +  return content 
16− 13  15  } 
16+ 13  15  } 
internal/exp/diffview/testdata/TestDiffView/Unified/MultipleHunks/LightMode.golden+16−16
@@ -1,16 +1,16 @@
1−  …   …  @@ -2,6 +2,7 @@  
1+  …   …  @@ -2,6 +2,7 @@  
2−  2   2   
2+  2   2   
3−  3   3  import ( 
3+  3   3  import ( 
4−  4   4  "fmt" 
4+  4   4  "fmt" 
5−     5 +  "strings" 
5+     5 +  "strings" 
6−  5   6  ) 
6+  5   6  ) 
7−  6   7   
7+  6   7   
8−  7   8  func main() { 
8+  7   8  func main() { 
9−  …   …  @@ -9,5 +10,6 @@  
9+  …   …  @@ -9,5 +10,6 @@  
10−  9  10  } 
10+  9  10  } 
11− 10  11   
11+ 10  11   
12− 11  12  func getContent() string { 
12+ 11  12  func getContent() string { 
13− 12    -  return "Hello, world!" 
13+ 12    -  return "Hello, world!" 
14−    13 +  content := strings.ToUpper("Hello, World!")
14+    13 +  content := strings.ToUpper("Hello, World!") 
15−    14 +  return content 
15+    14 +  return content 
16− 13  15  } 
16+ 13  15  } 
internal/exp/diffview/testdata/TestDiffView/Unified/Narrow/DarkMode.golden+7−7
@@ -1,7 +1,7 @@
1− …  …  @@ -1,3 +1,3 @@ 
1+ …  …  @@ -1,3 +1,3 @@  
2− 1    - a 
2+ 1    - a 
3− 2    - b 
3+ 2    - b 
4− 3    - c 
4+ 3    - c 
5−    1 + d 
5+    1 + d 
6−    2 + e 
6+    2 + e 
7−    3 + f 
7+    3 + f 
internal/exp/diffview/testdata/TestDiffView/Unified/Narrow/LightMode.golden+7−7
@@ -1,7 +1,7 @@
1− …  …  @@ -1,3 +1,3 @@ 
1+ …  …  @@ -1,3 +1,3 @@  
2− 1    - a 
2+ 1    - a 
3− 2    - b 
3+ 2    - b 
4− 3    - c 
4+ 3    - c 
5−    1 + d 
5+    1 + d 
6−    2 + e 
6+    2 + e 
7−    3 + f 
7+    3 + f 
internal/exp/diffview/testdata/TestDiffView/Unified/NoLineNumbers/DarkMode.golden+8−8
@@ -1,8 +1,8 @@
1− @@ -5,5 +5,6 @@  
1+ @@ -5,5 +5,6 @@  
2− ) 
2+ ) 
3−  
3+  
4− func main() { 
4+ func main() { 
5−-  fmt.Println("Hello, world!")
5+-  fmt.Println("Hello, world!") 
6−+  content := "Hello, world!" 
6++  content := "Hello, world!" 
7−+  fmt.Println(content) 
7++  fmt.Println(content) 
8− } 
8+ } 
internal/exp/diffview/testdata/TestDiffView/Unified/NoLineNumbers/LightMode.golden+8−8
@@ -1,8 +1,8 @@
1− @@ -5,5 +5,6 @@  
1+ @@ -5,5 +5,6 @@  
2− ) 
2+ ) 
3−  
3+  
4− func main() { 
4+ func main() { 
5−-  fmt.Println("Hello, world!")
5+-  fmt.Println("Hello, world!") 
6−+  content := "Hello, world!" 
6++  content := "Hello, world!" 
7−+  fmt.Println(content) 
7++  fmt.Println(content) 
8− } 
8+ }