Yeah, I kinda gave up, i will fix it later or something I recon
This commit is contained in:
@@ -2,11 +2,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/models"
|
||||
"esdi/tui/internal/ui"
|
||||
)
|
||||
|
||||
type LayoutController struct {
|
||||
@@ -18,22 +14,17 @@ func NewLayoutController(bus *events.Bus) *LayoutController {
|
||||
EvBus: bus,
|
||||
}
|
||||
|
||||
bus.On(ui.CreateWindowEv{}, func(e any) {
|
||||
ev := e.(ui.CreateWindowEv)
|
||||
lc.createWindow(ev.Window)
|
||||
})
|
||||
|
||||
return lc
|
||||
}
|
||||
|
||||
func (lc *LayoutController) createWindow(win models.Window) {
|
||||
lc.EvBus.Emit(ui.LogEv{
|
||||
Log: fmt.Sprintf("x : %d\n"+
|
||||
"y : %d\n"+
|
||||
"width : %d\n"+
|
||||
"height: %d\n"+
|
||||
"title : %s\n", win.X, win.Y, win.Width, win.Height, win.Title),
|
||||
})
|
||||
|
||||
lc.EvBus.Emit(ui.WindowCreatedEv{Window: win})
|
||||
}
|
||||
// func (lc *LayoutController) createWindow(win models.Window) {
|
||||
// lc.EvBus.Emit(ui.LogEv{
|
||||
// Log: fmt.Sprintf("x : %d\n"+
|
||||
// "y : %d\n"+
|
||||
// "width : %d\n"+
|
||||
// "height: %d\n"+
|
||||
// "title : %s\n", win.X, win.Y, win.Width, win.Height, win.Title),
|
||||
// })
|
||||
//
|
||||
// lc.EvBus.Emit(ui.WindowCreatedEv{})
|
||||
// }
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"esdi/cdashdisplay"
|
||||
helper "esdi/helpers"
|
||||
"esdi/peripheral"
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/ui"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
@@ -17,46 +20,85 @@ type Ctrls struct {
|
||||
}
|
||||
|
||||
type MainController struct {
|
||||
Logger *slog.Logger
|
||||
App *tview.Application
|
||||
Dom *dom.DOM
|
||||
EvBus *events.Bus
|
||||
DevClerk *peripheral.PeripheralDeviceClerk
|
||||
CDash *cdashdisplay.CDashDisplay
|
||||
}
|
||||
|
||||
func NewMainController() *MainController {
|
||||
func NewMainController(logger *slog.Logger) *MainController {
|
||||
mc := &MainController{
|
||||
Logger: logger,
|
||||
App: tview.NewApplication(),
|
||||
Dom: dom.NewDOM(),
|
||||
EvBus: events.NewBus(),
|
||||
DevClerk: peripheral.NewPeripheralDeviceClerk(),
|
||||
CDash: nil,
|
||||
}
|
||||
|
||||
mc.EvBus.On(ui.RedrawEv{}, func(e any) {
|
||||
mc.App.QueueUpdateDraw(func() {})
|
||||
go func() {
|
||||
mc.App.QueueUpdateDraw(func() {})
|
||||
}()
|
||||
})
|
||||
|
||||
mc.EvBus.On(ui.ChangeFocusEv{}, func(e any) {
|
||||
mc.App.SetFocus(e.(ui.ChangeFocusEv).Target)
|
||||
go func() {
|
||||
mc.App.SetFocus(e.(ui.ChangeFocusEv).Target)
|
||||
}()
|
||||
})
|
||||
|
||||
mc.EvBus.On(ui.LogEv{}, func(e any) {
|
||||
mc.EvBus.Emit(ui.PrintLogEv{Log: e.(ui.LogEv).Log})
|
||||
go func() {
|
||||
mc.EvBus.Emit(ui.PrintLogEv{Log: e.(ui.LogEv).Log})
|
||||
}()
|
||||
})
|
||||
|
||||
mc.EvBus.On(ui.CreateWindowEv{}, func(e any) {
|
||||
go func() {
|
||||
win := e.(ui.CreateWindowEv).Window
|
||||
|
||||
uiWindow := cdashdisplay.UIWindow{
|
||||
Dims: cdashdisplay.UIDimensions{
|
||||
X0: win.X,
|
||||
Y0: win.Y,
|
||||
Width: win.Width,
|
||||
Height: win.Height,
|
||||
},
|
||||
Decor: cdashdisplay.DefaultDecorations,
|
||||
Title: helper.B32(win.Title),
|
||||
}
|
||||
|
||||
wID, err := mc.CDash.CreateWindow(uiWindow)
|
||||
if err != nil {
|
||||
mc.EvBus.Emit(ui.PrintLogEv{Log: "failed to create window\n"})
|
||||
return
|
||||
}
|
||||
|
||||
mc.EvBus.Emit(ui.WindowCreatedEv{ID: wID, Title: win.Title})
|
||||
mc.EvBus.Emit(ui.PrintLogEv{Log: "Window created!\n"})
|
||||
}()
|
||||
})
|
||||
|
||||
mc.EvBus.On(ui.DestroyWindowEv{}, func(e any) {
|
||||
mc.Logger.Info(fmt.Sprintf("Called in to destroy win: %d", e.(ui.DestroyWindowEv).ID))
|
||||
mc.CDash.DestroyWindow(e.(ui.DestroyWindowEv).ID)
|
||||
})
|
||||
|
||||
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"})
|
||||
}
|
||||
go func() {
|
||||
mc.Logger.Info("Looking for CDashDisplay")
|
||||
cdashdisplay.SetLogger(mc.Logger.With("[device]", "cdashdisplay"))
|
||||
|
||||
if len(mc.DevClerk.Devices) == 0 {
|
||||
mc.EvBus.Emit(ui.LogEv{Log: " there are no devices\n"})
|
||||
}
|
||||
display, err := cdashdisplay.NewCDashDisplay()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, d := range mc.DevClerk.Devices {
|
||||
msg := fmt.Sprintf(" [%2d] %s\n", d.ID, d.Name)
|
||||
mc.EvBus.Emit(ui.LogEv{Log: msg})
|
||||
}
|
||||
mc.CDash = display
|
||||
}()
|
||||
})
|
||||
|
||||
return mc
|
||||
|
||||
Reference in New Issue
Block a user