package main
import (
)
var (
maxHeight = flag.Int("max-height", 10, "maximum height")
horizontal = flag.Bool("horizontal", false, "use horizontal listbox layout")
)
func () tk.Widget {
:= tk.TestItems{Prefix: "list item "}
:= tk.NewComboBox(tk.ComboBoxSpec{
CodeArea: tk.CodeAreaSpec{
Prompt: func() ui.Text {
return ui.Concat(ui.T(" NUMBER ", ui.Bold, ui.BgMagenta), ui.T(" "))
},
},
ListBox: tk.ListBoxSpec{
State: tk.ListBoxState{Items: &},
Placeholder: ui.T("(no items)"),
Horizontal: *horizontal,
},
OnFilter: func( tk.ComboBox, string) {
if , := strconv.Atoi(); == nil {
.NItems =
}
},
})
return
}
func () {
flag.Parse()
:= makeWidget()
:= cli.NewTTY(os.Stdin, os.Stderr)
, := .Setup()
if != nil {
fmt.Fprintln(os.Stderr, )
return
}
defer ()
defer .CloseReader()
for {
, := .Size()
if > *maxHeight {
= *maxHeight
}
.UpdateBuffer(nil, .Render(, ), false)
, := .ReadEvent()
if != nil {
:= term.NewBufferBuilder().Write(.Error(), ui.FgRed).Buffer()
.UpdateBuffer(nil, , true)
break
}
:= .Handle()
if ! && == term.K('D', ui.Ctrl) {
.UpdateBuffer(nil, term.NewBufferBuilder().Buffer(), true)
break
}
}
}