From 9f9660b391f2d4f9a7b8862067017380ec7b9703 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 4 Sep 2023 15:10:02 -0500 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Use=20modal=20for=20boolea?= =?UTF-8?q?n=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input/boolean/boolean.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/input/boolean/boolean.go b/input/boolean/boolean.go index 0d43ced..7b31bfe 100644 --- a/input/boolean/boolean.go +++ b/input/boolean/boolean.go @@ -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() { - choice = true - app.Stop() - }). - AddItem("No", "", 'n', func() { - choice = false + 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() }) - 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) }