The List widget displays rows of items that can be navigated and selected. Each item can have a main text, an optional secondary text (shown underneath), and an optional shortcut key (a rune) for direct selection.
Navigation and Selection:
- Movement: Use
Down arrow/Tab to move down, Up arrow/Backtab to move up, Home for the first item, and End for the last item. - Pagination: Use
Page down and Page up to scroll through the list. - Selection: Press
Enter, Space, or the item's assigned shortcut key to select an item. Mouse clicks also trigger selection. - Scrolling: Use
Left/Right arrows or mouse scrolling to move horizontally if the list is wider than the available space.
Callbacks:
- Use
SetChangedFunc to be notified when the user navigates to a different item. - Use
SetSelectedFunc to be notified when an item is selected. - Use
SetDoneFunc to handle the Escape key.
list := tview.NewList()
list.AddItem("Main Text", "Secondary Text", 'a', func() {
// This is called when the item is selected
}).SetSelectedFunc(func(index int, mainText, secondaryText string, shortcut rune) {
// This is also called when the item is selected
}).SetChangedFunc(func(index int, mainText, secondaryText string, shortcut rune) {
// This is called when the selection moves
})