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"
|
|
|
|
|
|
2021-04-03 15:11:20 +00:00
|
|
|
|
"code.rocketnine.space/tslocum/cview"
|
2018-01-12 03:03:29 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2019-12-30 23:12:17 +00:00
|
|
|
|
app := cview.NewApplication()
|
2020-10-15 16:12:10 +00:00
|
|
|
|
panels := cview.NewPanels()
|
2018-01-12 03:03:29 +00:00
|
|
|
|
|
2019-12-30 23:12:17 +00:00
|
|
|
|
form := cview.NewForm()
|
2020-10-07 23:34:21 +00:00
|
|
|
|
form.AddDropDownSimple("称谓", 0, nil, "先生", "女士", "博士", "老师", "师傅")
|
|
|
|
|
form.AddInputField("姓名", "", 20, nil, nil)
|
|
|
|
|
form.AddPasswordField("密码", "", 10, '*', nil)
|
|
|
|
|
form.AddCheckBox("", "年龄 18+", false, nil)
|
|
|
|
|
form.AddButton("保存", func() {
|
|
|
|
|
_, option := form.GetFormItem(0).(*cview.DropDown).GetCurrentOption()
|
|
|
|
|
userName := form.GetFormItem(1).(*cview.InputField).GetText()
|
|
|
|
|
|
2020-10-15 16:12:10 +00:00
|
|
|
|
alert(panels, "alert-dialog", fmt.Sprintf("保存成功,%s %s!", userName, option.GetText()))
|
2020-10-07 23:34:21 +00:00
|
|
|
|
})
|
|
|
|
|
form.AddButton("退出", func() {
|
|
|
|
|
app.Stop()
|
|
|
|
|
})
|
|
|
|
|
form.SetBorder(true)
|
|
|
|
|
form.SetTitle("输入一些内容")
|
|
|
|
|
form.SetTitleAlign(cview.AlignLeft)
|
2020-10-16 01:50:10 +00:00
|
|
|
|
panels.AddPanel("base", form, true, true)
|
2018-01-12 03:03:29 +00:00
|
|
|
|
|
2020-10-15 16:12:10 +00:00
|
|
|
|
app.SetRoot(panels, true)
|
2020-10-07 23:34:21 +00:00
|
|
|
|
if err := app.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.
|
2020-10-15 16:12:10 +00:00
|
|
|
|
func alert(panels *cview.Panels, id string, message string) {
|
2020-10-07 23:34:21 +00:00
|
|
|
|
modal := cview.NewModal()
|
|
|
|
|
modal.SetText(message)
|
|
|
|
|
modal.AddButtons([]string{"确定"})
|
|
|
|
|
modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
2020-10-16 01:50:10 +00:00
|
|
|
|
panels.HidePanel(id)
|
|
|
|
|
panels.RemovePanel(id)
|
2020-10-07 23:34:21 +00:00
|
|
|
|
})
|
|
|
|
|
|
2020-10-16 01:50:10 +00:00
|
|
|
|
panels.AddPanel(id, modal, false, true)
|
2018-01-12 03:03:29 +00:00
|
|
|
|
}
|