cview/demos/unicode/main.go

51 lines
1.3 KiB
Go
Raw Normal View History

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"
"code.rocketnine.space/tslocum/cview"
2018-01-12 03:03:29 +00:00
)
func main() {
app := cview.NewApplication()
2020-10-15 16:12:10 +00:00
panels := cview.NewPanels()
2018-01-12 03:03:29 +00:00
form := cview.NewForm()
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()))
})
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)
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) {
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-16 01:50:10 +00:00
panels.AddPanel(id, modal, false, true)
2018-01-12 03:03:29 +00:00
}