Big One
This commit is contained in:
+36
-15
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user