Adding the peripheralDeviceClerk to the UI
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"esdi/peripheral"
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/ui"
|
||||
"fmt"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
@@ -15,16 +17,18 @@ type Ctrls struct {
|
||||
}
|
||||
|
||||
type MainController struct {
|
||||
App *tview.Application
|
||||
Dom *dom.DOM
|
||||
EvBus *events.Bus
|
||||
App *tview.Application
|
||||
Dom *dom.DOM
|
||||
EvBus *events.Bus
|
||||
DevClerk *peripheral.PeripheralDeviceClerk
|
||||
}
|
||||
|
||||
func NewMainController() *MainController {
|
||||
mc := &MainController{
|
||||
App: tview.NewApplication(),
|
||||
Dom: dom.NewDOM(),
|
||||
EvBus: events.NewBus(),
|
||||
App: tview.NewApplication(),
|
||||
Dom: dom.NewDOM(),
|
||||
EvBus: events.NewBus(),
|
||||
DevClerk: peripheral.NewPeripheralDeviceClerk(),
|
||||
}
|
||||
|
||||
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.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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user