-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.go
61 lines (54 loc) · 1.23 KB
/
draw.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
package ui
import (
"fmt"
"os"
"github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
"github.com/pkg/browser"
)
func DrawUI(feedCount int, l *widgets.List, FeedItemUrls map[int]string, TextColor int) {
feedCountWord := " feed"
if feedCount > 1 {
feedCountWord = " feeds"
}
l.Title = "Monitoring " + fmt.Sprint(feedCount) + feedCountWord
l.Rows = []string{}
l.TextStyle = termui.NewStyle(termui.StandardColors[TextColor])
l.WrapText = false
l.SetRect(0, 0, 50, 16)
termui.Render(l)
uiEvents := termui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
os.Exit(0)
case "j", "<Down>":
l.ScrollDown()
case "k", "<Up>":
l.ScrollUp()
case "z":
l.TextStyle = NextTheme(l.TextStyle)
case "<Enter>":
browser.OpenURL(FeedItemUrls[l.SelectedRow])
case "<Resize>":
payload := e.Payload.(termui.Resize)
l.SetRect(0, 0, payload.Width, payload.Height)
}
termui.Render(l)
}
}
func NextTheme(currentStyle termui.Style) termui.Style {
var index int
for i, item := range termui.StandardStyles {
if item == currentStyle {
index = i
break
}
}
if len(termui.StandardStyles) > index+1 {
return termui.StandardStyles[index+1]
} else {
return termui.StandardStyles[0]
}
}