gomu/popup.go

39 lines
905 B
Go
Raw Normal View History

2020-06-22 00:05:56 +08:00
// Copyright (C) 2020 Raziman
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).
2020-06-24 20:09:47 +08:00
SetBackgroundColor(tcell.ColorDarkCyan).
2020-06-19 16:42:30 +08:00
AddButtons([]string{"yes", "no"}).
2020-06-24 20:09:47 +08:00
SetButtonBackgroundColor(tcell.ColorDarkCyan).
SetButtonTextColor(tcell.ColorBlack).
2020-06-19 16:42:30 +08:00
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
}