-
Notifications
You must be signed in to change notification settings - Fork 25
/
diff.go
38 lines (35 loc) · 825 Bytes
/
diff.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"github.com/as/edit"
"github.com/as/rgba"
"github.com/as/text"
"github.com/as/ui/tag"
"github.com/as/ui/win"
)
var (
diffIns = edit.MustCompile(`,x,.+\n,x,^\\+.+\n,h`)
diffDel = edit.MustCompile(`,x,.+\n,x,^-.+\n,h`)
)
func Diff(t *tag.Tag) {
w, _ := t.Window.(*win.Win)
if w == nil {
return
}
w.FuncInstall(func(w *win.Win) {
fr := w.Frame
buf := text.BufferFrom(w.Bytes()[w.Origin() : w.Origin()+fr.Len()])
ed, _ := text.Open(buf)
diffIns.Run(ed)
diffDel.Run(ed)
pal := fr.Color.Palette
pal.Text = rgba.Black
pal.Back = rgba.Green
for _, dot := range diffIns.Emit.Dot {
w.Frame.Recolor(fr.PointOf(dot.Q0), dot.Q0, dot.Q1, pal)
}
pal.Back = rgba.Red
for _, dot := range diffDel.Emit.Dot {
w.Frame.Recolor(fr.PointOf(dot.Q0), dot.Q0, dot.Q1, pal)
}
})
}