2020-06-19 16:22:20 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
"github.com/rivo/tview"
|
|
|
|
)
|
|
|
|
|
|
|
|
func confirmationPopup(
|
|
|
|
app *tview.Application,
|
|
|
|
pages *tview.Pages,
|
|
|
|
text string,
|
2020-06-19 16:42:30 +08:00
|
|
|
handler func(buttonIndex int, buttonLabel string),
|
2020-06-19 16:22:20 +08:00
|
|
|
) {
|
|
|
|
|
|
|
|
modal := tview.NewModal().
|
2020-06-19 16:42:30 +08:00
|
|
|
SetText(text).
|
|
|
|
SetBackgroundColor(tcell.ColorDefault).
|
|
|
|
AddButtons([]string{"yes", "no"}).
|
|
|
|
SetButtonBackgroundColor(tcell.ColorBlack).
|
|
|
|
SetDoneFunc(handler)
|
2020-06-19 16:22:20 +08:00
|
|
|
|
|
|
|
pages.AddPage("confirmation-popup", center(modal, 40, 10), true, true)
|
|
|
|
app.SetFocus(modal)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func center(p tview.Primitive, width, height int) tview.Primitive {
|
|
|
|
return tview.NewFlex().
|
2020-06-19 16:42:30 +08:00
|
|
|
AddItem(nil, 0, 1, false).
|
|
|
|
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
|
2020-06-19 16:22:20 +08:00
|
|
|
AddItem(nil, 0, 1, false).
|
2020-06-19 16:42:30 +08:00
|
|
|
AddItem(p, height, 1, false).
|
|
|
|
AddItem(nil, 0, 1, false), width, 1, false).
|
|
|
|
AddItem(nil, 0, 1, false)
|
2020-06-19 16:22:20 +08:00
|
|
|
}
|