-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
105 lines (87 loc) · 2.23 KB
/
util.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
termbox "github.com/nsf/termbox-go"
)
var (
defaultBgColor = termbox.ColorDefault
defaultFgColor = termbox.ColorDefault
defaultCursorColor = termbox.ColorGreen | termbox.AttrBold | termbox.AttrReverse
defaultTildeColor = termbox.ColorGreen | termbox.AttrBold
defaultFilepathColor = termbox.ColorCyan | termbox.AttrBold
defaultLineColor = termbox.ColorYellow | termbox.AttrBold
defaultRemovedColor = termbox.ColorYellow | termbox.AttrBold
defaultAddedColor = termbox.ColorGreen | termbox.AttrBold
defaultStatusColor = termbox.ColorCyan | termbox.AttrBold
)
func tbPrint(x, y int, fg, bg termbox.Attribute, msg string) {
for _, c := range msg {
termbox.SetCell(x, y, c, fg, bg)
x++
}
}
func hiPrint(x, y int, hi termbox.Attribute, format string, a ...interface{}) int {
fg := termbox.ColorDefault
bg := termbox.ColorDefault
curfg := fg
s := fmt.Sprintf(format, a...)
for _, c := range s {
if c == '<' {
curfg = hi
} else if c == '>' {
curfg = fg
} else {
termbox.SetCell(x, y, c, curfg, bg)
x++
}
}
return x
}
// type Debug struct {
// msgs []string
// }
// func (d Debug) Add(format string, a ...interface{}) {
// s := fmt.Sprintf(format, a...)
// d.msgs = append(d.msgs, s)
// }
// func (d Debug) Print() {
// _, h := termbox.Size()
// x := 0
// tbPrint(x, h-1, termbox.ColorDefault, termbox.ColorDefault, fmt.Sprintf("%d", len(d.msgs)))
// // for _, s := range d.msgs {
// // tbPrint(x, h-1, termbox.ColorDefault, termbox.ColorDefault, s)
// // x += len(s)
// // }
// // d.msgs = make([]string, 1)
// }
// func debugPrint(format string, a ...interface{}) {
// s := fmt.Sprintf(format, a...)
// _, h := termbox.Size()
// tbPrint(0, h-1, termbox.ColorRed, termbox.ColorDefault, s)
// }
// func (d Debug) Print(format string, a ...interface{}) {
// s := fmt.Sprintf(format, a...)
// _, h := termbox.Size()
// tbPrint(0, h-1, termbox.ColorDefault, termbox.ColorDefault, s)
// }
func termboxPoll() chan termbox.Event {
evCh := make(chan termbox.Event)
go func() {
for {
evCh <- termbox.PollEvent()
}
}()
return evCh
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func max(a, b int) int {
if a > b {
return a
}
return b
}