-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_info_page.go
98 lines (79 loc) · 2.17 KB
/
server_info_page.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/solidpulse/natsdash/ds"
)
type ServerInfoPage struct {
*tview.Flex
Data *ds.Data
form *tview.Form
app *tview.Application // Add this line
}
func NewServerInfoPage(app *tview.Application, data *ds.Data) *ServerInfoPage {
cfp := &ServerInfoPage{
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
app: app, // Add this line
}
cfp.Data = data
cfp.setupUI()
cfp.setupInputCapture()
return cfp
}
func (cfp *ServerInfoPage) setupUI() {
// Header setup
headerRow := createServerInfoHeaderRow()
cfp.AddItem(headerRow, 0, 4, false)
txtView := createTextView("Coming soon...", tcell.ColorWhite)
cfp.AddItem(txtView, 0, 8, false)
// // Footer setup
// footer := tview.NewFlex().SetBorder(true)
// cfp.AddItem(footer, 0, 1, false)
cfp.SetBorderPadding(1, 1, 1, 1)
}
func (cfp *ServerInfoPage) redraw(ctx *ds.Context) {
// go func() {
// cfp.form.GetFormItem(0).(*tview.InputField).SetText("Connecting...")
// }()
// go func() {
// if ctx.Conn != nil {
// conn, err := natsutil.Connect(ctx.URL)
// if err != nil {
// cfp.form.GetFormItem(0).(*tview.TextView).SetText(err.Error())
// } else {
// ctx.Conn = conn
// }
// } else {
// cfp.form.GetFormItem(0).(*tview.TextView).SetText("Connected")
// }
// }()
}
func (cfp *ServerInfoPage) setupInputCapture() {
cfp.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyEsc {
cfp.goBackToContextPage()
return nil
}
return event
})
}
func (cfp *ServerInfoPage) goBackToContextPage() {
pages.SwitchToPage("contexts")
_, b := pages.GetFrontPage()
b.(*ContextPage).Redraw()
cfp.app.SetFocus(b) // Add this line
}
func createServerInfoHeaderRow() *tview.Flex {
headerRow := tview.NewFlex()
headerRow.SetBorder(false)
headerRow.
SetDirection(tview.FlexColumn).
SetBorderPadding(1, 0, 1, 1)
headerRow1 := tview.NewFlex()
headerRow1.SetDirection(tview.FlexRow)
headerRow1.SetBorder(false)
headerRow1.AddItem(createTextView("[Esc] Back", tcell.ColorWhite), 0, 1, false)
headerRow.AddItem(headerRow1, 0, 1, false)
headerRow.SetTitle("NATS-DASH")
return headerRow
}