This commit is contained in:
2026-01-09 19:05:14 +00:00
parent 56ce6bc58d
commit 583437cd75
13 changed files with 392 additions and 47 deletions
+36 -15
View File
@@ -2,7 +2,10 @@
package tui
import (
"esdi/t/internal/controllers"
dom "esdi/t/internal/dom"
"esdi/t/internal/events"
"esdi/t/internal/ui"
"esdi/t/internal/views"
"fmt"
@@ -11,22 +14,24 @@ import (
)
type TUI struct {
App *tview.Application
Dom *dom.DOM
App *tview.Application
Dom *dom.DOM
Events *events.Bus
}
var (
application *TUI
initiated = false
)
func NewTUI() *TUI {
return &TUI{
App: tview.NewApplication(),
Dom: dom.NewDOM(),
App: tview.NewApplication(),
Dom: dom.NewDOM(),
Events: events.NewBus(),
}
}
func (t *TUI) log(formatter string, args ...any) {
outputWin := t.Dom.GetElemByID("output-window").(*tview.TextView)
fmt.Fprintf(outputWin, formatter, args...)
}
func (t *TUI) Start() error {
// The app starts running here!
//
@@ -40,14 +45,34 @@ func (t *TUI) Start() error {
return event
})
ctx := &views.UIContext{
ctx := &ui.UIContext{
Redraw: func() {
t.App.QueueUpdateDraw(func() {})
},
Log: func(formatter string, args ...any) {
t.log(formatter, args...)
},
ChangeFocus: func(p tview.Primitive) {
t.App.SetFocus(p)
},
}
// Create the controllers
windowingController := &controllers.WindowingController{
Events: t.Events,
Ctx: ctx,
}
views.BindWindowEvents(ctx, t.Events, nil)
// Make the output window
err := views.BuildOutputWindow(t.Dom, ctx)
if err != nil {
panic("failed to create output window")
}
// Set the main view
mainUINode, err := views.BuildMainFlex(t.Dom, ctx)
mainUINode, err := views.BuildMainFlex(t.Dom, ctx, windowingController)
if err != nil {
panic(fmt.Errorf("failed to build main flex - %s", err.Error()))
}
@@ -71,7 +96,3 @@ func (t *TUI) Start() error {
return nil
}
func Init() {
initiated = true
}