-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.go
79 lines (68 loc) · 1.62 KB
/
ui.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
71
72
73
74
75
76
77
78
79
package main
import (
"github.com/gdamore/tcell/v2"
)
func UIInit() {
bg := tcell.ColorDarkCyan
fg := tcell.ColorLightPink
// tview.Box method
input_box.SetBorder(true).
SetTitle("URL/IP").
SetBackgroundColor(bg).
SetBorderColor(fg).
SetTitleColor(fg)
// tview.InputField method
input_box.SetLabel("URL/IP: ").
SetFieldBackgroundColor(tcell.ColorRosyBrown).
SetFieldTextColor(tcell.ColorLightGray).
SetLabelColor(fg)
// Handle key
input_box.SetDoneFunc(InputDoneHandle)
input_box.SetInputCapture(InputCaptureHandle)
output_box.SetInputCapture(OutputCaptureHandle)
// tview.Box method
output_box.SetBorder(true).
SetTitle(output_box.Title).
SetBackgroundColor(bg).
SetBorderColor(fg).
SetTitleColor(fg)
}
func InputDoneHandle(key tcell.Key) {
switch key {
case tcell.KeyEnter:
if stop_traceroute && traceroute_thread_cnt == 0 {
stop_traceroute = false
traceroute_thread_cnt++
dest := input_box.GetText()
go TraceRoute(dest)
}
case tcell.KeyTab, tcell.KeyBacktab:
app.SetFocus(output_box)
case tcell.KeyEscape:
app.Stop()
}
}
func InputCaptureHandle(event *tcell.EventKey) *tcell.EventKey {
key := event.Key()
switch key {
case tcell.KeyCtrlD, tcell.KeyCtrlS:
stop_traceroute = true
case tcell.KeyCtrlQ:
app.Stop()
}
return event
}
func OutputCaptureHandle(event *tcell.EventKey) *tcell.EventKey {
key := event.Key()
switch key {
case tcell.KeyTab, tcell.KeyBacktab:
app.SetFocus(input_box)
case tcell.KeyCtrlD, tcell.KeyCtrlS:
stop_traceroute = true
case tcell.KeyCtrlL:
output_box.ClearText()
case tcell.KeyCtrlQ, tcell.KeyEscape:
app.Stop()
}
return event
}