-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogViewer.go
50 lines (43 loc) · 921 Bytes
/
logViewer.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
package main
import (
"bufio"
"os"
"strings"
"github.com/rivo/tview"
)
const (
colorStd = "[white:black]"
colorError = "[red]"
colorFatal = "[yellow:red]"
)
func main() {
app := tview.NewApplication()
textView := tview.NewTextView().
SetDynamicColors(true)
textView.SetBorder(true).
SetTitle("Stdin")
grid := tview.NewGrid().
SetRows(1, -1)
grid.AddItem(textView, 1, 0, 1, 1, 1, 1, true)
go func() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
switch {
case strings.Contains(line, "ERROR"):
line = colorError + line + colorStd
case strings.Contains(line, "FATAL"):
line = colorFatal + line + colorStd
}
app.QueueUpdateDraw(func() {
_, _ = textView.Write([]byte(line + "\n"))
})
}
if err := scanner.Err(); err != nil {
panic(err)
}
}()
if err := app.SetRoot(grid, true).Run(); err != nil {
panic(err)
}
}