list

package
v0.0.0-...-e327841 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeStringerList

func MakeStringerList(list ...string) []fmt.Stringer

MakeStringerList is a shortcut to convert a string List to a List that satisfies the fmt.Stringer Interface

Types

type ConfigError

type ConfigError error

ConfigError is return if there is a error with the configuration of the list Model

type DefaultPrefixer

type DefaultPrefixer struct {
	PrefixWrap bool

	// Make clear where a item begins and where it ends
	FirstSep      string
	Seperator     string
	SeperatorWrap string

	// Mark it so that even without color support all is explicit
	CurrentMarker string

	// enable Linenumber
	Number         bool
	NumberRelative bool
	// contains filtered or unexported fields
}

DefaultPrefixer is the default struct used for Prefixing a line

func NewPrefixer

func NewPrefixer() *DefaultPrefixer

NewPrefixer returns a DefautPrefixer with default values

func (*DefaultPrefixer) InitPrefixer

func (d *DefaultPrefixer) InitPrefixer(value fmt.Stringer, currentItemIndex, cursorIndex, lineOffset, width, height int) int

InitPrefixer sets up all strings used to prefix a given line later by Prefix()

func (*DefaultPrefixer) Prefix

func (d *DefaultPrefixer) Prefix(lineIndex, allLines int) string

Prefix prefixes a given line

type DefaultSuffixer

type DefaultSuffixer struct {
	// contains filtered or unexported fields
}

DefaultSuffixer is more a example than a default but still it highlights the usage and the line. Also if used the line gets padded to the List Width So that it can be horizontally joined with other strings/Views.

func NewSuffixer

func NewSuffixer() *DefaultSuffixer

NewSuffixer returns a simple suffixer

func (*DefaultSuffixer) InitSuffixer

func (e *DefaultSuffixer) InitSuffixer(_ fmt.Stringer, currentItemIndex, cursorIndex, lineOffset, width, height int) int

InitSuffixer returns the visible Width of the strings used to suffix the lines

func (*DefaultSuffixer) Suffix

func (e *DefaultSuffixer) Suffix(line, allLines int) string

Suffix returns a suffix string for the given line

type Model

type Model struct {
	LessFunc   func(fmt.Stringer, fmt.Stringer) bool // function used for sorting
	EqualsFunc func(fmt.Stringer, fmt.Stringer) bool // used after sorting, to be set from the user

	// offset or margin between the cursor and the visible border
	CursorOffset int

	// The visible Area size of the list
	Width, Height int

	// Wrap changes the number of lines which get displayed. 0 means unlimited lines.
	Wrap int

	PrefixGen Prefixer
	SuffixGen Suffixer

	LineStyle    termenv.Style
	CurrentStyle termenv.Style
	// contains filtered or unexported fields
}

Model is a bubbletea List of strings

func NewModel

func NewModel() Model

NewModel returns a Model with some save/sane defaults design to transfer as much internal information to the user

func (*Model) AddItems

func (m *Model) AddItems(itemList []fmt.Stringer) error

AddItems adds the given Items to the list Model. Run Sort() afterwards, if you want to keep the list sorted. If entrys of itemList are nil they will not be added, and a NilValue error is returned through tea.Cmd. Neither the cursor item nor its index will change, but if items where added, tea.Cmd will yield a ListChange Msg. If you add very many Items, the program will get slower, since bubbletea is a elm architektur, Update and View are functions and are call with a copy of the list-Model which takes more time if the Model/List is bigger.

func (*Model) Bottom

func (m *Model) Bottom() error

Bottom moves the cursor to the last item if the list is not empty, else the cursor is not moved and the returning tea.Cmd while yield the according error. If all goes well and the cursor has changed tea.Cmd while yield a CursorItemChange and a CursorIndexChange.

func (*Model) GetAllItems

func (m *Model) GetAllItems() []fmt.Stringer

GetAllItems returns all items in the list in current order

func (*Model) GetCursorIndex

func (m *Model) GetCursorIndex() (int, error)

GetCursorIndex returns the current cursor position within the List, or a NoItems error if the list has no items on which the cursor could be.

func (*Model) GetCursorItem

func (m *Model) GetCursorItem() (fmt.Stringer, error)

GetCursorItem returns the item at the current cursor position within the List or nil.

func (*Model) GetIndex

func (m *Model) GetIndex(toSearch fmt.Stringer) (int, error)

GetIndex returns NotFound error if the Equals Method is not set (SetEquals) else it returns the index of the found item

func (*Model) GetItem

func (m *Model) GetItem(index int) (fmt.Stringer, error)

GetItem returns the item if the index exists a error through tea.Cmd otherwise.

func (Model) Init

func (m Model) Init() tea.Cmd

Init does nothing

func (*Model) Len

func (m *Model) Len() int

Len returns the amount of list-items.

func (Model) Less

func (m Model) Less(i, j int) bool

func (Model) Lines

func (m Model) Lines() ([]string, error)

Lines renders the visible lines of the list by calling the String Methodes of the items and if present the pre- and suffix function. If there is not enough space, or there a no item within the list, nil and a error is returned.

func (*Model) MoveCursor

func (m *Model) MoveCursor(amount int) (int, error)

MoveCursor moves the cursor by amount and returns the absolut index of the cursor after the movement. If any error occurs the cursor is not moved and the returning tea.Cmd while yield the according error. If all goes well and the cursor has changed tea.Cmd while yield a CursorItemChange and a CursorIndexChange.

func (*Model) MoveItem

func (m *Model) MoveItem(amount int) error

MoveItem moves the current item by amount to the end of the list. If the target does not exist a error is returned through tea.Cmd. Else a ListChange and a CursorIndexChange is returned.

func (*Model) RemoveIndex

func (m *Model) RemoveIndex(index int) (fmt.Stringer, error)

RemoveIndex removes and returns the item at the given index if it exists, else a error is returned through the tea.Cmd. If the cursor index or item has changed tea.Cmd while yield a CursorItemChange or a CursorIndexChange. The cursor will hold its numeric position except the list gets to short one which case its on the end of the list.

func (*Model) ResetItems

func (m *Model) ResetItems(newStringers []fmt.Stringer) error

ResetItems replaces all list items with the new items, if a entry is nil its not added. If equals function is set and a new item yields true in comparison to the old cursor item the cursor is set on this (or if equals-func is bad the last-)item. If the Cursor Index or Item has changed the corrisponding tea.Cmd is returned, but in any case a ListChange is returned through the tea.Cmd.

func (*Model) SetCursor

func (m *Model) SetCursor(target int) (int, error)

SetCursor set the cursor to the specified index if possible, but If any error occurs the cursor is not moved and the returning tea.Cmd while yield the according error. If all goes well and the cursor has changed tea.Cmd while yield a CursorItemChange and a CursorIndexChange.

func (*Model) Sort

func (m *Model) Sort()

Sort sorts the list items according to the set less-function or, if not set, after String comparison. Internally the sort.Sort interface is used, so this is not guaranteed to be a stable sort. If you need stable sorting, sort the items your self and reset the list with them. While sorting the cursor item can not change, but the cursor index can.

func (Model) Swap

func (m Model) Swap(i, j int)

func (*Model) Top

func (m *Model) Top() error

Top moves the cursor to the first item if the list is not empty, else the cursor is not moved and the returning tea.Cmd while yield the according error. If all goes well and the cursor has changed tea.Cmd while yield a CursorItemChange and a CursorIndexChange.

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update only handles WindowSizeMsg, everything else has to be implemented by the user.

func (*Model) UpdateItem

func (m *Model) UpdateItem(index int, updater func(fmt.Stringer) (fmt.Stringer, tea.Cmd)) (tea.Cmd, error)

UpdateItem takes a index and updates the item at the index with the given function or if index outside the list returns OutOfBounds error. If the returned fmt.Stringer value is nil, then the item gets removed from the list. If you want to keep the list sorted run Sort() after updating a item. tea.Cmd contains the cmd returned by the updater.

func (*Model) ValidIndex

func (m *Model) ValidIndex(index int) (int, error)

ValidIndex returns a error when the list has no items or the index is out of bounds. And the nearest valid index in case of OutOfBounds error, else the index it self and no error.

func (Model) View

func (m Model) View() string

View renders the List output according to the current model and returns "empty" if the list has no items. This might change in the future.

type MultipleMatches

type MultipleMatches error

MultipleMatches gets return if the search yield more result

type NilValue

type NilValue error

NilValue is returned if there was a request to set nil as value of a list item.

type NoItems

type NoItems error

NoItems is a error returned when the list is empty

type NotFound

type NotFound error

NotFound gets return if the search does not yield a result

type OutOfBounds

type OutOfBounds error

OutOfBounds is return if an index is outside the list boundary's

type Prefixer

type Prefixer interface {
	InitPrefixer(value fmt.Stringer, currentItemIndex, cursorIndex, lineOffset, width, height int) int
	Prefix(currentLine, allLines int) string
}

Prefixer is used to prefix all visible Lines. Init gets called ones on the beginning of the Lines methode and then Prefix ones, per line to draw, to generate according prefixes.

type StringItem

type StringItem string

StringItem is just a convenience to satisfy the fmt.Stringer interface with plain strings

func (StringItem) String

func (s StringItem) String() string

type Suffixer

type Suffixer interface {
	InitSuffixer(value fmt.Stringer, currentItemIndex, cursorIndex, lineOffset, width, height int) int
	Suffix(currentLine, allLines int) string
}

Suffixer is used to suffix all visible Lines. InitSuffixer gets called ones on the beginning of the Lines method and then Suffix ones, per line to draw, to generate according suffixes.

type UnhandledKey

type UnhandledKey error

UnhandledKey is returned when there is no binding for this key press.

Directories

Path Synopsis
example
checkboxes command
editable command
tree command

Jump to

Keyboard shortcuts

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