Adding the peripheralDeviceClerk to the UI
This commit is contained in:
@@ -2,9 +2,11 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"esdi/peripheral"
|
||||||
"esdi/tui/internal/dom"
|
"esdi/tui/internal/dom"
|
||||||
"esdi/tui/internal/events"
|
"esdi/tui/internal/events"
|
||||||
"esdi/tui/internal/ui"
|
"esdi/tui/internal/ui"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
@@ -15,16 +17,18 @@ type Ctrls struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MainController struct {
|
type MainController struct {
|
||||||
App *tview.Application
|
App *tview.Application
|
||||||
Dom *dom.DOM
|
Dom *dom.DOM
|
||||||
EvBus *events.Bus
|
EvBus *events.Bus
|
||||||
|
DevClerk *peripheral.PeripheralDeviceClerk
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMainController() *MainController {
|
func NewMainController() *MainController {
|
||||||
mc := &MainController{
|
mc := &MainController{
|
||||||
App: tview.NewApplication(),
|
App: tview.NewApplication(),
|
||||||
Dom: dom.NewDOM(),
|
Dom: dom.NewDOM(),
|
||||||
EvBus: events.NewBus(),
|
EvBus: events.NewBus(),
|
||||||
|
DevClerk: peripheral.NewPeripheralDeviceClerk(),
|
||||||
}
|
}
|
||||||
|
|
||||||
mc.EvBus.On(ui.RedrawEv{}, func(e any) {
|
mc.EvBus.On(ui.RedrawEv{}, func(e any) {
|
||||||
@@ -39,5 +43,21 @@ func NewMainController() *MainController {
|
|||||||
mc.EvBus.Emit(ui.PrintLogEv{Log: e.(ui.LogEv).Log})
|
mc.EvBus.Emit(ui.PrintLogEv{Log: e.(ui.LogEv).Log})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mc.EvBus.On(ui.FindCDashDisplay{}, func(e any) {
|
||||||
|
err := mc.DevClerk.FindDevices()
|
||||||
|
if err != nil {
|
||||||
|
mc.EvBus.Emit(ui.LogEv{Log: "Error finding devices: " + err.Error() + "\n"})
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(mc.DevClerk.Devices) == 0 {
|
||||||
|
mc.EvBus.Emit(ui.LogEv{Log: " there are no devices\n"})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, d := range mc.DevClerk.Devices {
|
||||||
|
msg := fmt.Sprintf(" [%2d] %s\n", d.ID, d.Name)
|
||||||
|
mc.EvBus.Emit(ui.LogEv{Log: msg})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return mc
|
return mc
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,6 @@ func Start() error {
|
|||||||
|
|
||||||
controllers.NewLayoutController(mc.EvBus)
|
controllers.NewLayoutController(mc.EvBus)
|
||||||
|
|
||||||
// Make the output window
|
|
||||||
err := views.BuildOutputWindow(mc.EvBus, mc.Dom)
|
|
||||||
if err != nil {
|
|
||||||
panic("failed to create output window")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the main view
|
// Set the main view
|
||||||
mainUINode, err := views.BuildMainFlex(mc.EvBus, mc.Dom)
|
mainUINode, err := views.BuildMainFlex(mc.EvBus, mc.Dom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -41,3 +41,11 @@ type ErrorCreateWindowEv struct {
|
|||||||
type ErrorFormParseEv struct {
|
type ErrorFormParseEv struct {
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Layout events --------------------------------------------------------------
|
||||||
|
|
||||||
|
// Device events
|
||||||
|
|
||||||
|
type FindCDashDisplay struct{}
|
||||||
|
|
||||||
|
// Device events --------------------------------------------------------------
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"esdi/tui/internal/events"
|
"esdi/tui/internal/events"
|
||||||
"esdi/tui/internal/ui"
|
"esdi/tui/internal/ui"
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -59,14 +60,14 @@ func buildRightSideFlex(bus *events.Bus, doc *dom.DOM) (*dom.UINode, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
outputWin := doc.GetElemByID(outputPaneID)
|
// outputWin := doc.GetElemByID(outputPaneID)
|
||||||
if outputWin == nil {
|
// if outputWin == nil {
|
||||||
panic("failed to attach output win to UI")
|
// panic("failed to attach output win to UI")
|
||||||
}
|
// }
|
||||||
|
|
||||||
flex.
|
flex.
|
||||||
AddItem(apiToolPagesNode.Self, 0, 5, false).
|
AddItem(apiToolPagesNode.Self, 0, 5, false)
|
||||||
AddItem(outputWin, 0, 2, false)
|
// AddItem(outputWin, 0, 2, false)
|
||||||
|
|
||||||
return flexNode, nil
|
return flexNode, nil
|
||||||
}
|
}
|
||||||
@@ -85,7 +86,14 @@ func BuildMainFlex(bus *events.Bus, doc *dom.DOM) (*tview.Flex, error) {
|
|||||||
AddItem("layout", "build a layout for CDashDisplay", 0, func() {
|
AddItem("layout", "build a layout for CDashDisplay", 0, func() {
|
||||||
layoutToolUIOnSelect(bus, doc)
|
layoutToolUIOnSelect(bus, doc)
|
||||||
})
|
})
|
||||||
deviceAPIList.SetBorder(true).SetTitle("list")
|
deviceAPIList.SetBorder(true).SetTitle("list").
|
||||||
|
SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey {
|
||||||
|
switch ev.Rune() {
|
||||||
|
case 'r':
|
||||||
|
bus.Emit(ui.FindCDashDisplay{})
|
||||||
|
}
|
||||||
|
return ev
|
||||||
|
})
|
||||||
|
|
||||||
apiListWindowUINode, err := doc.NewUINode(deviceAPIListID, doc.GetRootElem(),
|
apiListWindowUINode, err := doc.NewUINode(deviceAPIListID, doc.GetRootElem(),
|
||||||
deviceAPIList)
|
deviceAPIList)
|
||||||
@@ -102,5 +110,19 @@ func BuildMainFlex(bus *events.Bus, doc *dom.DOM) (*tview.Flex, error) {
|
|||||||
AddItem(apiListWindowUINode.Self, 0, 1, false).
|
AddItem(apiListWindowUINode.Self, 0, 1, false).
|
||||||
AddItem(rightSideFlex.Self, 0, 4, false)
|
AddItem(rightSideFlex.Self, 0, 4, false)
|
||||||
|
|
||||||
return mainFlex, nil
|
// Output window
|
||||||
|
err = BuildOutputWindow(bus, doc)
|
||||||
|
if err != nil {
|
||||||
|
panic("failed to create output window")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flex with debug window
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
flexWithOutputWindow := tview.NewFlex().SetDirection(tview.FlexRow)
|
||||||
|
flexWithOutputWindow.
|
||||||
|
AddItem(mainFlex, 0, 5, true).
|
||||||
|
AddItem(doc.GetElemByID(outputPaneID), 0, 2, false)
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return flexWithOutputWindow, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user