primitive

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RichList

type RichList struct {
	*cview.Box
	// contains filtered or unexported fields
}

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

See https://code.rocketnine.space/tslocum/cview/wiki/List for an example.

func NewRichList

func NewRichList() *RichList

NewRichList returns a new list.

func (*RichList) AddItem

func (l *RichList) AddItem(mainText string) *RichList

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

func (*RichList) Clear

func (l *RichList) Clear() *RichList

Clear removes all items from the list.

func (*RichList) Draw

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

Draw draws this primitive onto the screen.

func (*RichList) FindItems

func (l *RichList) FindItems(mainSearch string, 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 (*RichList) GetCurrentItem

func (l *RichList) GetCurrentItem() int

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

func (*RichList) GetItemCount

func (l *RichList) GetItemCount() int

GetItemCount returns the number of items in the list.

func (*RichList) GetItemText

func (l *RichList) GetItemText(index int) (main string)

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

func (*RichList) InputHandler

func (l *RichList) InputHandler() func(event *tcell.EventKey, setFocus func(p cview.Primitive))

InputHandler returns the handler for this primitive.

func (*RichList) InsertItem

func (l *RichList) InsertItem(index int, mainText string) *RichList

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 (*RichList) RemoveItem

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

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 (*RichList) SetChangedFunc

func (l *RichList) SetChangedFunc(handler func(index int, mainText string)) *RichList

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 (*RichList) SetCurrentItem

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

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 (*RichList) SetHighlightFullLine

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

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 (*RichList) SetHighlightedMainTextFunc

func (l *RichList) SetHighlightedMainTextFunc(handler func(index int, mainText string) string) *RichList

func (*RichList) SetInfiniteScroll

func (l *RichList) SetInfiniteScroll(infiniteScroll bool) *RichList

SetInfiniteScroll sets a flag which determines whether the scroll should be endless or not.

func (*RichList) SetItemText

func (l *RichList) SetItemText(index int, main string) *RichList

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

func (*RichList) SetMainTextColor

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

SetMainTextColor sets the color of the items' main text.

func (*RichList) SetPrefixWithLineNumber

func (l *RichList) SetPrefixWithLineNumber(prefixWithLineNumber bool) *RichList

func (*RichList) SetSelectedBackgroundColor

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

SetSelectedBackgroundColor sets the background color of selected items.

func (*RichList) SetUnfocusedSelectedBackgroundColor

func (l *RichList) SetUnfocusedSelectedBackgroundColor(color tcell.Color) *RichList

SetUnfocusedSelectedBackgroundColor sets the background color of unfocused selected items.

Jump to

Keyboard shortcuts

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