Reimplementing a whole lot of things here
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user