2018-01-12 07:12:42 +00:00
|
|
|
|
// Demo code for unicode support (demonstrates wide Chinese characters).
|
2018-01-12 03:03:29 +00:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/rivo/tview"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
app := tview.NewApplication()
|
|
|
|
|
pages := tview.NewPages()
|
|
|
|
|
|
|
|
|
|
form := tview.NewForm()
|
|
|
|
|
form.AddDropDown("称谓", []string{"先生", "女士", "博士", "老师", "师傅"}, 0, nil).
|
|
|
|
|
AddInputField("姓名", "", 20, nil, nil).
|
|
|
|
|
AddCheckbox("年龄 18+", false, nil).
|
|
|
|
|
AddPasswordField("密码", "", 10, '*', nil).
|
|
|
|
|
AddButton("保存", func() {
|
2018-01-13 12:07:05 +00:00
|
|
|
|
_, title := form.GetFormItem(0).(*tview.DropDown).GetCurrentOption()
|
|
|
|
|
userName := form.GetFormItem(1).(*tview.InputField).GetText()
|
2018-01-12 03:03:29 +00:00
|
|
|
|
|
|
|
|
|
alert(pages, "alert-dialog", fmt.Sprintf("保存成功,%s %s!", userName, title))
|
|
|
|
|
}).
|
|
|
|
|
AddButton("退出", func() {
|
|
|
|
|
app.Stop()
|
|
|
|
|
})
|
|
|
|
|
form.SetBorder(true).SetTitle("输入一些内容").SetTitleAlign(tview.AlignLeft)
|
|
|
|
|
pages.AddPage("base", form, true, true)
|
|
|
|
|
|
2018-03-05 15:37:10 +00:00
|
|
|
|
if err := app.SetRoot(pages, true).Run(); err != nil {
|
2018-01-12 03:03:29 +00:00
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 07:12:42 +00:00
|
|
|
|
// alert shows a confirmation dialog.
|
2018-01-12 03:03:29 +00:00
|
|
|
|
func alert(pages *tview.Pages, id string, message string) *tview.Pages {
|
|
|
|
|
return pages.AddPage(
|
|
|
|
|
id,
|
|
|
|
|
tview.NewModal().
|
|
|
|
|
SetText(message).
|
|
|
|
|
AddButtons([]string{"确定"}).
|
|
|
|
|
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
|
|
|
|
pages.HidePage(id).RemovePage(id)
|
|
|
|
|
}),
|
|
|
|
|
false,
|
|
|
|
|
true,
|
|
|
|
|
)
|
|
|
|
|
}
|