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.
58 lines
1.6 KiB
58 lines
1.6 KiB
// Demo code for the List primitive. |
|
package main |
|
|
|
import ( |
|
"gitlab.com/tslocum/cview" |
|
) |
|
|
|
func main() { |
|
app := cview.NewApplication() |
|
list := cview.NewList() |
|
|
|
reset := func() { |
|
list. |
|
Clear(). |
|
AddItem(cview.NewListItem("List item 1").SetSecondaryText("Some explanatory text").SetShortcut('a')). |
|
AddItem(cview.NewListItem("List item 2").SetSecondaryText("Some explanatory text").SetShortcut('b')). |
|
AddItem(cview.NewListItem("List item 3").SetSecondaryText("Some explanatory text").SetShortcut('c')). |
|
AddItem(cview.NewListItem("List item 4").SetSecondaryText("Some explanatory text").SetShortcut('d')). |
|
AddItem(cview.NewListItem("Quit").SetSecondaryText("Press to exit").SetShortcut('q').SetSelectedFunc(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) |
|
} |
|
}
|
|
|