-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreen.go
44 lines (36 loc) · 764 Bytes
/
screen.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
package main
import (
"github.com/rivo/tview"
)
type OutputScreen struct {
*tview.TextView
Title string
Text string
}
func NewOutputScreen() *OutputScreen {
return &OutputScreen{
TextView: tview.NewTextView(),
Title: "TraceRoute",
}
}
func (screen *OutputScreen) AddText(s string) *OutputScreen {
if len(screen.Text) == 0 {
screen.Text = s
} else {
screen.Text = screen.Text + "\n" + s
}
return screen
}
func (screen *OutputScreen) UpdateTitle() {
screen.SetTitle(screen.Title)
}
// Concurrency(app.Draw), do not call in main thread
func (screen *OutputScreen) RefreshText() {
screen.SetText(screen.Text)
screen.ScrollToEnd()
app.Draw()
}
func (screen *OutputScreen) ClearText() {
screen.Text = ""
screen.SetText(screen.Text)
}