♻️ Use modal for boolean input
This commit is contained in:
parent
810dbe691e
commit
9f9660b391
1 changed files with 13 additions and 10 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue