forked from jpbruinsslot/slack-term
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
58 lines (45 loc) · 1.24 KB
/
debug.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
package components
import "github.com/erroneousboat/termui"
// Debug can be used to relay debugging information in the Debug component,
// see event.go on how to use it
type Debug struct {
Par *termui.Par
List *termui.List
}
func CreateDebugComponent(inputHeight int) *Debug {
debug := &Debug{
List: termui.NewList(),
}
debug.List.BorderLabel = "Debug"
debug.List.Height = termui.TermHeight() - inputHeight
return debug
}
// Buffer implements interface termui.Bufferer
func (d *Debug) Buffer() termui.Buffer {
return d.List.Buffer()
}
// GetHeight implements interface termui.GridBufferer
func (d *Debug) GetHeight() int {
return d.List.Block.GetHeight()
}
// SetWidth implements interface termui.GridBufferer
func (d *Debug) SetWidth(w int) {
d.List.SetWidth(w)
}
// SetX implements interface termui.GridBufferer
func (d *Debug) SetX(x int) {
d.List.SetX(x)
}
// SetY implements interface termui.GridBufferer
func (d *Debug) SetY(y int) {
d.List.SetY(y)
}
// Println will add the text to the Debug component
func (d *Debug) Println(text string) {
d.List.Items = append(d.List.Items, text)
// When at the end remove first item
if len(d.List.Items) > d.List.InnerBounds().Max.Y-1 {
d.List.Items = d.List.Items[1:]
}
termui.Render(d)
}