2017-12-15 14:29:21 +00:00
|
|
|
package main
|
|
|
|
|
2017-12-15 22:03:01 +00:00
|
|
|
import (
|
|
|
|
"github.com/gdamore/tcell"
|
|
|
|
"github.com/rivo/tview"
|
|
|
|
)
|
2017-12-15 14:29:21 +00:00
|
|
|
|
|
|
|
func main() {
|
2017-12-15 22:03:01 +00:00
|
|
|
app := tview.NewApplication()
|
2017-12-20 19:54:49 +00:00
|
|
|
pages := tview.NewPages()
|
2017-12-16 21:48:26 +00:00
|
|
|
var list *tview.List
|
2017-12-15 22:03:01 +00:00
|
|
|
|
2017-12-20 19:54:49 +00:00
|
|
|
form := tview.NewForm().
|
2017-12-18 19:04:52 +00:00
|
|
|
AddInputField("First name", "", 20, nil).
|
|
|
|
AddInputField("Last name", "", 20, nil).
|
|
|
|
AddInputField("Age", "", 4, nil).
|
|
|
|
AddDropDown("Select", []string{"One", "Two", "Three"}, 1, func(text string, index int) {
|
|
|
|
if text == "Three" {
|
|
|
|
app.Stop()
|
|
|
|
}
|
|
|
|
}).
|
2017-12-20 19:54:49 +00:00
|
|
|
AddCheckbox("Check", false, nil).
|
|
|
|
AddButton("Save", func() {
|
|
|
|
previous := app.GetFocus()
|
|
|
|
modal := tview.NewModal().
|
|
|
|
SetText("Would you really like to save this customer to the database?").
|
|
|
|
AddButtons([]string{"Save", "Cancel"}).
|
|
|
|
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
|
|
|
pages.RemovePage("confirm")
|
|
|
|
app.SetFocus(previous)
|
|
|
|
app.Draw()
|
|
|
|
})
|
|
|
|
pages.AddPage("confirm", modal, true)
|
|
|
|
app.SetFocus(modal)
|
|
|
|
app.Draw()
|
|
|
|
}).
|
2017-12-16 21:48:26 +00:00
|
|
|
AddButton("Cancel", nil).
|
2017-12-20 19:54:49 +00:00
|
|
|
AddButton("Go to list", func() { app.SetFocus(list) }).
|
|
|
|
SetCancelFunc(func() {
|
|
|
|
app.Stop()
|
|
|
|
})
|
|
|
|
form.SetTitle("Customer").SetBorder(true)
|
2017-12-16 21:48:26 +00:00
|
|
|
|
|
|
|
list = tview.NewList().
|
2017-12-20 19:54:49 +00:00
|
|
|
AddItem("Edit a form", "You can do whatever you want", 'e', func() { app.SetFocus(form) }).
|
2017-12-18 19:04:52 +00:00
|
|
|
AddItem("Quit the program", "Do it!", 0, func() { app.Stop() })
|
2017-12-20 19:54:49 +00:00
|
|
|
|
|
|
|
frame := tview.NewFrame(list).AddText("Choose!", true, tview.AlignCenter, tcell.ColorRed)
|
|
|
|
frame.SetBorder(true)
|
|
|
|
|
|
|
|
flex := tview.NewFlex().
|
|
|
|
AddItem(form, 0).
|
|
|
|
AddItem(tview.NewFlex().
|
|
|
|
SetDirection(tview.FlexRow).
|
|
|
|
AddItem(frame, 0).
|
|
|
|
AddItem(tview.NewBox().SetBorder(true).SetTitle("Third"), 0), 0).
|
|
|
|
AddItem(tview.NewBox().SetBorder(true).SetTitle("Fourth"), 0).
|
|
|
|
AddItem(tview.NewBox().SetBorder(true).SetTitle("Fifth"), 20)
|
2017-12-15 14:29:21 +00:00
|
|
|
|
|
|
|
inputField := tview.NewInputField().
|
|
|
|
SetLabel("Type something: ").
|
|
|
|
SetFieldLength(10).
|
|
|
|
SetAcceptanceFunc(tview.InputFieldFloat)
|
|
|
|
inputField.SetBorder(true).SetTitle("Type!")
|
|
|
|
|
2017-12-20 19:54:49 +00:00
|
|
|
final := tview.NewFlex().
|
|
|
|
SetFullScreen(true).
|
|
|
|
SetDirection(tview.FlexRow).
|
|
|
|
AddItem(flex, 0).
|
|
|
|
AddItem(inputField, 3)
|
|
|
|
|
|
|
|
pages.AddPage("flex", final, true)
|
2017-12-15 14:29:21 +00:00
|
|
|
|
2017-12-20 19:54:49 +00:00
|
|
|
app.SetRoot(pages, false).SetFocus(list)
|
2017-12-15 14:29:21 +00:00
|
|
|
|
|
|
|
if err := app.Run(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|