Debian Codegraph @

filters/hldiff

raw
1 #!/usr/bin/awk -f
2
3 BEGIN {
4 bright = "\x1B[1m"
5 red = "\x1B[31m"
6 green = "\x1B[32m"
7 cyan = "\x1B[36m"
8 reset = "\x1B[0m"
9
10 hit_diff = 0
11 }
12 {
13 if (hit_diff == 0) {
14 # Strip carriage returns from line
15 gsub(/\r/, "", $0)
16
17 if ($0 ~ /^diff /) {
18 hit_diff = 1;
19 print bright $0 reset
20 } else if ($0 ~ /^.*\|.*(\+|-)/) {
21 left = substr($0, 0, index($0, "|")-1)
22 right = substr($0, index($0, "|"))
23 gsub(/-+/, red "&" reset, right)
24 gsub(/\++/, green "&" reset, right)
25 print left right
26 } else {
27 print $0
28 }
29 } else {
30 # Strip carriage returns from line
31 gsub(/\r/, "", $0)
32
33 if ($0 ~ /^-/) {
34 print red $0 reset
35 } else if ($0 ~ /^\+/) {
36 print green $0 reset
37 } else if ($0 ~ /^ /) {
38 print $0
39 } else if ($0 ~ /^@@ (-[0-9]+,[0-9]+ \+[0-9]+,[0-9]+) @@.*/) {
40 sub(/^@@ (-[0-9]+,[0-9]+ \+[0-9]+,[0-9]+) @@/, cyan "&" reset)
41 print $0
42 } else {
43 print bright $0 reset
44 }
45 }
46 }