Reimplementing a whole lot of things here

This commit is contained in:
2026-03-02 22:40:06 +00:00
parent fe5505435b
commit e0f21f5d2f
12 changed files with 380 additions and 251 deletions
+28
View File
@@ -4,6 +4,7 @@ package controllers
import (
"esdi/tui/internal/dom"
"esdi/tui/internal/events"
"fmt"
"log/slog"
"github.com/rivo/tview"
@@ -15,3 +16,30 @@ type Controller struct {
App *tview.Application
Dom *dom.DOM
}
func ListFormButtonLabels(form *tview.Form) []string {
list := make([]string, form.GetButtonCount())
for idx := range form.GetButtonCount() {
btn := form.GetButton(idx)
list = append(list, btn.GetLabel())
}
return list
}
func SetFormButtonCallback(form *tview.Form, btnLabel string, fn func()) error {
btnIndex := form.GetButtonIndex(btnLabel)
if btnIndex == -1 {
availableButtons := ListFormButtonLabels(form)
return fmt.Errorf("no button with label: `%s` : [%v]", availableButtons)
}
button := form.GetButton(btnIndex)
if button == nil {
return fmt.Errorf("not button with ID %d in form", btnIndex)
}
button.SetSelectedFunc(fn)
return nil
}