♻️ Use modal for boolean input

This commit is contained in:
Dan Jones 2023-09-04 15:10:02 -05:00
commit 9f9660b391

View file

@ -2,20 +2,23 @@ package boolean
import "github.com/rivo/tview" import "github.com/rivo/tview"
func Choose(title string) bool { func Choose(text string) bool {
choice := false choice := false
app := tview.NewApplication() app := tview.NewApplication()
list := tview.NewList(). modal := tview.NewModal()
AddItem("Yes", "", 'y', func() { if text != "" {
choice = true modal.SetText(text)
app.Stop() }
}).
AddItem("No", "", 'n', func() { modal.AddButtons([]string{"Yes", "No"}).
choice = false SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Yes" {
choice = true
}
app.Stop() app.Stop()
}) })
list.Box.SetBorder(true).SetTitle(title)
if err := app.SetRoot(list, false).EnableMouse(true).Run(); err != nil { if err := app.SetRoot(modal, false).EnableMouse(true).Run(); err != nil {
panic(err) panic(err)
} }