|
|
|
@ -8,24 +8,21 @@ import (
|
|
|
|
|
"github.com/rivo/tview"
|
|
|
|
|
_ "github.com/gdamore/tcell/v2"
|
|
|
|
|
)
|
|
|
|
|
// gonna start from scratch :/
|
|
|
|
|
|
|
|
|
|
type TUI struct {
|
|
|
|
|
*Display
|
|
|
|
|
*LocalView
|
|
|
|
|
//*LocalView
|
|
|
|
|
*TUIClient
|
|
|
|
|
SelectedReactor <-chan uint32
|
|
|
|
|
Err chan error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewTUI(ip string, port int, ch chan error) *TUI {
|
|
|
|
|
r := make(map[uint32]*Reactor)
|
|
|
|
|
//r := make(map[uint32]*Reactor)
|
|
|
|
|
t := &TUI{}
|
|
|
|
|
l := new(LocalView)
|
|
|
|
|
l.Reactors = r
|
|
|
|
|
t.LocalView = l
|
|
|
|
|
c := make(chan uint32)
|
|
|
|
|
t.Display = NewDisplay(c)
|
|
|
|
|
t.SelectedReactor = c
|
|
|
|
|
//l := new(LocalView)
|
|
|
|
|
//l.Reactors = r
|
|
|
|
|
//t.LocalView = l
|
|
|
|
|
t.Err = ch
|
|
|
|
|
client := NewTUIClient(ip, port)
|
|
|
|
|
t.TUIClient = client
|
|
|
|
@ -34,25 +31,22 @@ func NewTUI(ip string, port int, ch chan error) *TUI {
|
|
|
|
|
|
|
|
|
|
func (t *TUI) Start() {
|
|
|
|
|
// setup tview app and wait for user connection in standin modal
|
|
|
|
|
t.Display.Start()
|
|
|
|
|
t.Connect()
|
|
|
|
|
if err := t.TUIClient.Start(); err != nil {
|
|
|
|
|
t.Err <- err
|
|
|
|
|
}
|
|
|
|
|
go t.Monitor()
|
|
|
|
|
go t.Listen()
|
|
|
|
|
t.CreateDisplay()
|
|
|
|
|
t.Display.Start()
|
|
|
|
|
//go t.Refresh()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *TUI) Refresh() {
|
|
|
|
|
for {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (t *TUI) Listen() {
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case <-t.SelectedReactor:
|
|
|
|
|
//blah
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (t *TUI) CreateDisplay() {
|
|
|
|
|
c := make(chan uint32)
|
|
|
|
|
t.Display = NewDisplay(c)
|
|
|
|
|
t.SelectedReactor = c
|
|
|
|
|
t.ReactorList.AddItem("REACTOR IS ONLINE"," ",0,nil)
|
|
|
|
|
t.Flex.AddItem(t.ReactorList,0,1,true).
|
|
|
|
|
AddItem(t.DeviceList,0,2,false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *TUI) Monitor() {
|
|
|
|
@ -74,7 +68,9 @@ func (t *TUI) Monitor() {
|
|
|
|
|
//t.DisplayReactorDevices(devs)
|
|
|
|
|
case <-timer:
|
|
|
|
|
// time to ping for status
|
|
|
|
|
go t.UpdateReactors()
|
|
|
|
|
t.App.QueueUpdateDraw(func() {
|
|
|
|
|
t.UpdateReactors()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -85,9 +81,9 @@ func (t *TUI) UpdateDevices(r uint32) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for a, d := range devs {
|
|
|
|
|
go t.LocalView.UpdateReactorDevices(r,a,d)
|
|
|
|
|
}
|
|
|
|
|
//for a, d := range devs {
|
|
|
|
|
// go t.LocalView.UpdateReactorDevices(r,a,d)
|
|
|
|
|
//}
|
|
|
|
|
t.DisplayReactorDevices(devs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -97,10 +93,10 @@ func (t *TUI) UpdateReactors() {
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for id, r := range reactors {
|
|
|
|
|
go t.LocalView.UpdateReactors(id, r)
|
|
|
|
|
}
|
|
|
|
|
t.DisplayReactors(reactors)
|
|
|
|
|
//for id, r := range reactors {
|
|
|
|
|
// go t.LocalView.UpdateReactors(id, r)
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -119,21 +115,22 @@ func NewDisplay(ch chan uint32) *Display {
|
|
|
|
|
d.Flex = tview.NewFlex()
|
|
|
|
|
d.ReactorList = tview.NewList().ShowSecondaryText(false)
|
|
|
|
|
d.DeviceList = tview.NewList().ShowSecondaryText(false)
|
|
|
|
|
d.ReactorList.SetTitle("Reactors").SetBorder(true)
|
|
|
|
|
d.DeviceList.SetTitle("Devices").SetBorder(true)
|
|
|
|
|
d.SelectedReactor = ch
|
|
|
|
|
d.ReactorList.SetSelectedFunc(d.SelectReactor)
|
|
|
|
|
return d
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *Display) Start() {
|
|
|
|
|
d.Flex.AddItem(d.ReactorList.SetBorder(true).SetTitle("Reactors"),0,1,true)
|
|
|
|
|
d.Flex.AddItem(d.DeviceList.SetBorder(true).SetTitle("Devices"),0,3,false)
|
|
|
|
|
if err := d.App.SetRoot(d.Flex, true).Run(); err != nil {
|
|
|
|
|
d.App.Stop()
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *Display) DisplayReactors(r map[uint32]*Reactor) {
|
|
|
|
|
// function to display reactor list to table
|
|
|
|
|
d.ReactorList.Clear()
|
|
|
|
|
for id, reactor := range r {
|
|
|
|
|
var status string
|
|
|
|
|
if reactor.Status {
|
|
|
|
@ -141,7 +138,7 @@ func (d *Display) DisplayReactors(r map[uint32]*Reactor) {
|
|
|
|
|
} else {
|
|
|
|
|
status = "[red]OFFLINE"
|
|
|
|
|
}
|
|
|
|
|
txt := fmt.Sprintf("Reactor %v is %v", id, status)
|
|
|
|
|
txt := fmt.Sprintf("%v is %v", id, status)
|
|
|
|
|
d.ReactorList.AddItem(txt,string(id),0,nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -157,7 +154,7 @@ func (d *Display) SelectReactor(index int, main, id string, r rune) {
|
|
|
|
|
|
|
|
|
|
func (d *Display) DisplayReactorDevices(devs map[int]*Device) {
|
|
|
|
|
//Function that displays devices to the table
|
|
|
|
|
d.DeviceList.Clear()
|
|
|
|
|
//d.DeviceList.Clear()
|
|
|
|
|
for addr, dev := range devs {
|
|
|
|
|
var status string
|
|
|
|
|
if dev.Status == "ACTIVE" {
|
|
|
|
@ -168,4 +165,5 @@ func (d *Display) DisplayReactorDevices(devs map[int]*Device) {
|
|
|
|
|
txt := fmt.Sprintf("%v is %v at %x",dev.Type,status,addr)
|
|
|
|
|
d.DeviceList.AddItem(txt,"",0,nil)
|
|
|
|
|
}
|
|
|
|
|
d.App.Draw()
|
|
|
|
|
}
|
|
|
|
|