...

Source file src/github.com/rivo/tview/demos/unicode/main.go

Documentation: github.com/rivo/tview/demos/unicode

     1  // Demo code for unicode support (demonstrates wide Chinese characters).
     2  package main
     3  
     4  import (
     5  	"fmt"
     6  
     7  	"github.com/rivo/tview"
     8  )
     9  
    10  func main() {
    11  	app := tview.NewApplication()
    12  	pages := tview.NewPages()
    13  
    14  	form := tview.NewForm()
    15  	form.AddDropDown("称谓", []string{"先生", "女士", "博士", "老师", "师傅"}, 0, nil).
    16  		AddInputField("姓名", "", 20, nil, nil).
    17  		AddCheckbox("年龄 18+", false, nil).
    18  		AddPasswordField("密码", "", 10, '*', nil).
    19  		AddButton("保存", func() {
    20  			_, title := form.GetFormItem(0).(*tview.DropDown).GetCurrentOption()
    21  			userName := form.GetFormItem(1).(*tview.InputField).GetText()
    22  
    23  			alert(pages, "alert-dialog", fmt.Sprintf("保存成功,%s %s!", userName, title))
    24  		}).
    25  		AddButton("退出", func() {
    26  			app.Stop()
    27  		})
    28  	form.SetBorder(true).SetTitle("输入一些内容").SetTitleAlign(tview.AlignLeft)
    29  	pages.AddPage("base", form, true, true)
    30  
    31  	if err := app.SetRoot(pages, true).Run(); err != nil {
    32  		panic(err)
    33  	}
    34  }
    35  
    36  // alert shows a confirmation dialog.
    37  func alert(pages *tview.Pages, id string, message string) *tview.Pages {
    38  	return pages.AddPage(
    39  		id,
    40  		tview.NewModal().
    41  			SetText(message).
    42  			AddButtons([]string{"确定"}).
    43  			SetDoneFunc(func(buttonIndex int, buttonLabel string) {
    44  				pages.HidePage(id).RemovePage(id)
    45  			}),
    46  		false,
    47  		true,
    48  	)
    49  }
    50  

View as plain text