2
0
mirror of https://github.com/skanehira/tson synced 2024-11-15 12:13:04 +00:00

improve input modal

This commit is contained in:
skanehira 2019-10-30 21:47:05 +09:00
parent df24d86d4e
commit 5a12ecefba

View File

@ -39,8 +39,16 @@ func (g *Gui) Run(i interface{}) error {
return nil return nil
} }
func (g *Gui) Modal(p tview.Primitive, width, height int) tview.Primitive {
return tview.NewGrid().
SetColumns(0, width, 0).
SetRows(0, height, 0).
AddItem(p, 1, 1, 1, 1, 0, 0, true)
}
func (g *Gui) Input(text string, doneFunc func(text string)) { func (g *Gui) Input(text string, doneFunc func(text string)) {
input := tview.NewInputField().SetText(text) input := tview.NewInputField().SetText(text)
input.SetBorder(true)
input.SetLabel("field:").SetLabelWidth(6).SetDoneFunc(func(key tcell.Key) { input.SetLabel("field:").SetLabelWidth(6).SetDoneFunc(func(key tcell.Key) {
if key == tcell.KeyEnter { if key == tcell.KeyEnter {
doneFunc(input.GetText()) doneFunc(input.GetText())
@ -48,5 +56,5 @@ func (g *Gui) Input(text string, doneFunc func(text string)) {
} }
}) })
g.Pages.AddPage("input", input, true, true).SendToFront("input").ShowPage("main") g.Pages.AddAndSwitchToPage("input", g.Modal(input, 0, 3), true).ShowPage("main")
} }