♻️ 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"
func Choose(title string) bool {
func Choose(text string) bool {
choice := false
app := tview.NewApplication()
list := tview.NewList().
AddItem("Yes", "", 'y', func() {
modal := tview.NewModal()
if text != "" {
modal.SetText(text)
}
modal.AddButtons([]string{"Yes", "No"}).
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
if buttonLabel == "Yes" {
choice = true
app.Stop()
}).
AddItem("No", "", 'n', func() {
choice = false
}
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)
}