| 1 | // Demo code for unicode support (demonstrates wide Chinese characters). |
| 2 | package mainscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/unicode`/ |
| 3 | |
| 4 | import ( |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 6 | |
| 7 | "github.com/darkhz/tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/" |
| 8 | ) |
| 9 | |
| 10 | func mainscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/unicode`/main().() { |
| 11 | app := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewApplicationscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewApplication().() |
| 12 | pages := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewPagesscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewPages().() |
| 13 | |
| 14 | form := tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewFormscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewForm().() |
| 15 | form.AddDropDownscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Form#AddDropDown().("称谓", []string{"先生", "女士", "博士", "老师", "师傅"}, 0, nil). |
| 16 | AddInputFieldscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Form#AddInputField().("姓名", "", 20, nil, nil). |
| 17 | AddCheckboxscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Form#AddCheckbox().("年龄 18+", false, nil). |
| 18 | AddPasswordFieldscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Form#AddPasswordField().("密码", "", 10, '*', nil). |
| 19 | AddButtonscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Form#AddButton().("保存", func() { |
| 20 | _, title := form.GetFormItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Form#GetFormItem().(0).(*tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.DropDownscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/DropDown#).GetCurrentOptionscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/DropDown#GetCurrentOption().() |
| 21 | userName := form.GetFormItemscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Form#GetFormItem().(1).(*tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.InputFieldscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/InputField#).GetTextscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/InputField#GetText().() |
| 22 | |
| 23 | alertscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/unicode`/alert().(pages, "alert-dialog", fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.18 fmt/Sprintf().("保存成功,%s %s!", userName, title)) |
| 24 | }). |
| 25 | AddButtonscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Form#AddButton().("退出", func() { |
| 26 | app.Stopscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Application#Stop().() |
| 27 | }) |
| 28 | form.SetBorderscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetBorder().(true).SetTitlescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetTitle().("输入一些内容").SetTitleAlignscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Box#SetTitleAlign().(tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.AlignLeftscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/AlignLeft.) |
| 29 | pages.AddPagescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#AddPage().("base", form, true, true) |
| 30 | |
| 31 | if err := app.SetRootscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Application#SetRoot().(pages, true).Runscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Application#Run().(); err != nil { |
| 32 | panic(err) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | // alert shows a confirmation dialog. |
| 37 | func alertscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview/demos/unicode`/alert().(pages *tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.Pagesscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#, id string, message string) *tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.Pagesscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages# { |
| 38 | return pages.AddPagescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#AddPage().( |
| 39 | id, |
| 40 | tviewscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/.NewModalscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/NewModal().(). |
| 41 | SetTextscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Modal#SetText().(message). |
| 42 | AddButtonsscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Modal#AddButtons().([]string{"确定"}). |
| 43 | SetDoneFuncscip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Modal#SetDoneFunc().(func(buttonIndex int, buttonLabel string) { |
| 44 | pages.HidePagescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#HidePage().(id).RemovePagescip-go gomod github.com/darkhz/tview . `github.com/darkhz/tview`/Pages#RemovePage().(id) |
| 45 | }), |
| 46 | false, |
| 47 | true, |
| 48 | ) |
| 49 | } |