-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.go
70 lines (59 loc) · 1.37 KB
/
logs.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
package main
import (
"github.com/nsf/termbox-go"
)
// StatusTab is a tab for displaying logs implementing Tabber.
type StatusTab struct {
a *Apollo
name string
status string
history []string
offset int
}
// NewStatusTab creates a new StatusTab and returns it.
func newStatusTab(a *Apollo) *StatusTab {
t := &StatusTab{
a: a,
name: "(status)",
status: "logs",
history: make([]string, 200),
}
return t
}
// Name returns the name of the tab.
func (t *StatusTab) Name() string {
return t.name
}
// Status returns the status of the tab.
func (t *StatusTab) Status() string {
return t.status
}
// HandleKeyEvent handles the changes in logs offsets.
func (t *StatusTab) HandleKeyEvent(ev *termbox.Event) {
switch ev.Key {
case termbox.KeyPgup:
t.offset += 5
if t.offset > 200-t.a.height+3 {
t.offset = 200 - t.a.height + 3
}
case termbox.KeyPgdn:
t.offset -= 5
if t.offset < 0 {
t.offset = 0
}
}
}
// Draw creates a slice of the logs history and draws it on the screen.
func (t *StatusTab) Draw() {
historySlice := t.history[200-t.a.height+2-t.offset : 200-t.offset]
for j := 1; j < t.a.height-2; j++ {
t.a.drawString(0, j, historySlice[j])
}
}
// Query adds a new string to the list of logs.
func (t *StatusTab) Query(query string) {
if query[0] != '!' {
t.history = t.history[1:]
t.history = append(t.history, query)
}
}