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-16 21:48:26 +00:00
|
|
|
var list *tview.List
|
2017-12-15 22:03:01 +00:00
|
|
|
|
2017-12-16 21:48:26 +00:00
|
|
|
frame := tview.NewFrame(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-15 22:03:01 +00:00
|
|
|
AddButton("Save", func() { app.Stop() }).
|
2017-12-16 21:48:26 +00:00
|
|
|
AddButton("Cancel", nil).
|
|
|
|
AddButton("Go to list", func() { app.SetFocus(list) })).
|
|
|
|
AddText("Customer details", true, tview.AlignLeft, tcell.ColorRed).
|
|
|
|
AddText("Customer details", false, tview.AlignCenter, tcell.ColorRed)
|
2017-12-18 19:04:52 +00:00
|
|
|
frame.SetBorder(true).SetTitle("Customers")
|
2017-12-16 21:48:26 +00:00
|
|
|
|
|
|
|
list = tview.NewList().
|
2017-12-18 19:04:52 +00:00
|
|
|
AddItem("Edit a form", "You can do whatever you want", 'e', func() { app.SetFocus(frame) }).
|
|
|
|
AddItem("Quit the program", "Do it!", 0, func() { app.Stop() })
|
2017-12-16 21:48:26 +00:00
|
|
|
list.SetBorder(true)
|
|
|
|
|
|
|
|
flex := tview.NewFlex(tview.FlexColumn, []tview.Primitive{
|
|
|
|
frame,
|
2017-12-15 14:29:21 +00:00
|
|
|
tview.NewFlex(tview.FlexRow, []tview.Primitive{
|
2017-12-16 21:48:26 +00:00
|
|
|
list,
|
2017-12-15 14:29:21 +00:00
|
|
|
tview.NewBox().SetBorder(true).SetTitle("Third"),
|
|
|
|
}),
|
|
|
|
tview.NewBox().SetBorder(true).SetTitle("Fourth"),
|
|
|
|
})
|
2017-12-16 21:48:26 +00:00
|
|
|
flex.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-16 21:48:26 +00:00
|
|
|
final := tview.NewFlex(tview.FlexRow, []tview.Primitive{flex})
|
2017-12-15 14:29:21 +00:00
|
|
|
final.AddItem(inputField, 3)
|
|
|
|
|
2017-12-16 21:48:26 +00:00
|
|
|
app.SetRoot(final, true).SetFocus(list)
|
2017-12-15 14:29:21 +00:00
|
|
|
|
|
|
|
if err := app.Run(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|