customshortcutlist

package
v0.0.0-...-4cb4cf9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	*tview.Box
	// contains filtered or unexported fields
}

List displays rows of items, each of which can be selected.

See https://github.com/rivo/tview/wiki/List for an example.

func NewList

func NewList() *List

NewList returns a new form.

func (*List) AddItem

func (l *List) AddItem(mainText, secondaryText string, shortcut rune, selected func()) *List

AddItem calls InsertItem() with an index of -1.

func (*List) Clear

func (l *List) Clear() *List

Clear removes all items from the list.

func (*List) Draw

func (l *List) Draw(screen tcell.Screen)

Draw draws this primitive onto the screen.

func (*List) FindItems

func (l *List) FindItems(mainSearch, secondarySearch string, mustContainBoth, ignoreCase bool) (indices []int)

FindItems searches the main and secondary texts for the given strings and returns a list of item indices in which those strings are found. One of the two search strings may be empty, it will then be ignored. Indices are always returned in ascending order.

If mustContainBoth is set to true, mainSearch must be contained in the main text AND secondarySearch must be contained in the secondary text. If it is false, only one of the two search strings must be contained.

Set ignoreCase to true for case-insensitive search.

func (*List) GetCurrentItem

func (l *List) GetCurrentItem() int

GetCurrentItem returns the index of the currently selected list item, starting at 0 for the first item.

func (*List) GetItemCount

func (l *List) GetItemCount() int

GetItemCount returns the number of items in the list.

func (*List) GetItemText

func (l *List) GetItemText(index int) (main, secondary string)

GetItemText returns an item's texts (main and secondary). Panics if the index is out of range.

func (*List) InputHandler

func (l *List) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))

InputHandler returns the handler for this primitive.

func (*List) InsertItem

func (l *List) InsertItem(index int, mainText, secondaryText string, shortcut rune, selected func()) *List

InsertItem adds a new item to the list at the specified index. An index of 0 will insert the item at the beginning, an index of 1 before the second item, and so on. An index of GetItemCount() or higher will insert the item at the end of the list. Negative indices are also allowed: An index of -1 will insert the item at the end of the list, an index of -2 before the last item, and so on. An index of -GetItemCount()-1 or lower will insert the item at the beginning.

An item has a main text which will be highlighted when selected. It also has a secondary text which is shown underneath the main text (if it is set to visible) but which may remain empty.

The shortcut is a key binding. If the specified rune is entered, the item is selected immediately. Set to 0 for no binding.

The "selected" callback will be invoked when the user selects the item. You may provide nil if no such callback is needed or if all events are handled through the selected callback set with SetSelectedFunc().

The currently selected item will shift its position accordingly. If the list was previously empty, a "changed" event is fired because the new item becomes selected.

func (*List) RemoveItem

func (l *List) RemoveItem(index int) *List

RemoveItem removes the item with the given index (starting at 0) from the list. If a negative index is provided, items are referred to from the back (-1 = last item, -2 = second-to-last item, and so on). Out of range indices are clamped to the beginning/end, i.e. unless the list is empty, an item is always removed.

The currently selected item is shifted accordingly. If it is the one that is removed, a "changed" event is fired.

func (*List) SetChangedFunc

func (l *List) SetChangedFunc(handler func(index int, mainText string, secondaryText string, shortcut rune)) *List

SetChangedFunc sets the function which is called when the user navigates to a list item. The function receives the item's index in the list of items (starting with 0), its main text, secondary text, and its shortcut rune.

This function is also called when the first item is added or when SetCurrentItem() is called.

func (*List) SetCurrentItem

func (l *List) SetCurrentItem(index int) *List

SetCurrentItem sets the currently selected item by its index, starting at 0 for the first item. If a negative index is provided, items are referred to from the back (-1 = last item, -2 = second-to-last item, and so on). Out of range indices are clamped to the beginning/end.

Calling this function triggers a "changed" event if the selection changes.

func (*List) SetDoneFunc

func (l *List) SetDoneFunc(handler func()) *List

SetDoneFunc sets a function which is called when the user presses the Escape key.

func (*List) SetHighlightFullLine

func (l *List) SetHighlightFullLine(highlight bool) *List

SetHighlightFullLine sets a flag which determines whether the colored background of selected items spans the entire width of the view. If set to true, the highlight spans the entire view. If set to false, only the text of the selected item from beginning to end is highlighted.

func (*List) SetItemText

func (l *List) SetItemText(index int, main, secondary string) *List

SetItemText sets an item's main and secondary text. Panics if the index is out of range.

func (*List) SetMainTextColor

func (l *List) SetMainTextColor(color tcell.Color) *List

SetMainTextColor sets the color of the items' main text.

func (*List) SetSecondaryTextColor

func (l *List) SetSecondaryTextColor(color tcell.Color) *List

SetSecondaryTextColor sets the color of the items' secondary text.

func (*List) SetSelectedBackgroundColor

func (l *List) SetSelectedBackgroundColor(color tcell.Color) *List

SetSelectedBackgroundColor sets the background color of selected items.

func (*List) SetSelectedFocusOnly

func (l *List) SetSelectedFocusOnly(focusOnly bool) *List

SetSelectedFocusOnly sets a flag which determines when the currently selected list item is highlighted. If set to true, selected items are only highlighted when the list has focus. If set to false, they are always highlighted.

func (*List) SetSelectedFunc

func (l *List) SetSelectedFunc(handler func(int, string, string, rune)) *List

SetSelectedFunc sets the function which is called when the user selects a list item by pressing Enter on the current selection. The function receives the item's index in the list of items (starting with 0), its main text, secondary text, and its shortcut rune.

func (*List) SetSelectedTextColor

func (l *List) SetSelectedTextColor(color tcell.Color) *List

SetSelectedTextColor sets the text color of selected items.

func (*List) SetShortcutColor

func (l *List) SetShortcutColor(color tcell.Color) *List

SetShortcutColor sets the color of the items' shortcut.

func (*List) SetWrapAround

func (l *List) SetWrapAround(wrapAround bool) *List

SetWrapAround sets the flag that determines whether navigating the list will wrap around. That is, navigating downwards on the last item will move the selection to the first item (similarly in the other direction). If set to false, the selection won't change when navigating downwards on the last item or navigating upwards on the first item.

func (*List) ShowSecondaryText

func (l *List) ShowSecondaryText(show bool) *List

ShowSecondaryText determines whether or not to show secondary item texts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL