MCPcopy
hub / github.com/operator-framework/operator-sdk / Generate

Function Generate

internal/helm/internal/diff/diff.go:26–50  ·  view source on GitHub ↗

Generate generates a diff between a and b, in color.

(a, b string)

Source from the content-addressed store, hash-verified

24
25// Generate generates a diff between a and b, in color.
26func Generate(a, b string) string {
27 dmp := diffmatchpatch.New()
28
29 wSrc, wDst, warray := dmp.DiffLinesToRunes(a, b)
30 diffs := dmp.DiffMainRunes(wSrc, wDst, false)
31 diffs = dmp.DiffCharsToLines(diffs, warray)
32 var buff bytes.Buffer
33 for _, diff := range diffs {
34 text := diff.Text
35
36 switch diff.Type {
37 case diffmatchpatch.DiffInsert:
38 _, _ = buff.WriteString("\x1b[32m")
39 _, _ = buff.WriteString(prefixLines(text, "+"))
40 _, _ = buff.WriteString("\x1b[0m")
41 case diffmatchpatch.DiffDelete:
42 _, _ = buff.WriteString("\x1b[31m")
43 _, _ = buff.WriteString(prefixLines(text, "-"))
44 _, _ = buff.WriteString("\x1b[0m")
45 case diffmatchpatch.DiffEqual:
46 _, _ = buff.WriteString(prefixLines(text, " "))
47 }
48 }
49 return buff.String()
50}
51
52func prefixLines(s, prefix string) string {
53 var buf bytes.Buffer

Callers 1

ReconcileMethod · 0.92

Calls 2

prefixLinesFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected