Terminal-based user interface toolkit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

// Demo code for the List primitive.
package main
import (
"gitlab.com/tslocum/cview"
)
func main() {
app := cview.NewApplication()
2 years ago
list := cview.NewList()
reset := func() {
list.
Clear().
AddItem("List item 1", "Some explanatory text", 'a', nil).
AddItem("List item 2", "Some explanatory text", 'b', nil).
AddItem("List item 3", "Some explanatory text", 'c', nil).
AddItem("List item 4", "Some explanatory text", 'd', nil).
AddItem("Quit", "Press to exit", 'q', func() {
app.Stop()
})
list.ContextMenuList().SetItemEnabled(3, false)
}
list.AddContextItem("Delete item", 'i', func(index int) {
list.RemoveItem(index)
if list.GetItemCount() == 0 {
list.ContextMenuList().SetItemEnabled(0, false)
list.ContextMenuList().SetItemEnabled(1, false)
}
list.ContextMenuList().SetItemEnabled(3, true)
})
list.AddContextItem("Delete all", 'a', func(index int) {
list.Clear()
list.ContextMenuList().SetItemEnabled(0, false)
list.ContextMenuList().SetItemEnabled(1, false)
list.ContextMenuList().SetItemEnabled(3, true)
})
list.AddContextItem("", 0, nil)
list.AddContextItem("Reset", 'r', func(index int) {
reset()
list.ContextMenuList().SetItemEnabled(0, true)
list.ContextMenuList().SetItemEnabled(1, true)
list.ContextMenuList().SetItemEnabled(3, false)
})
reset()
if err := app.SetRoot(list, true).EnableMouse(true).Run(); err != nil {
panic(err)
}
}