list

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item interface {
	// FilterValue is the value we use when filtering against this item when
	// we're filtering the list.
	FilterValue() string
}

Item is an item that appears in the list.

type ItemDelegate

type ItemDelegate interface {
	// Render renders the item's view.
	Render(w io.Writer, m Model, index int, item Item)

	// Height is the height of the list item.
	Height() int

	// Spacing is the size of the horizontal gap between list items in cells.
	Spacing() int

	// Update is the update loop for items. All messages in the list's update
	// loop will pass through here except when the user is setting a filter.
	// Use this method to perform item-level updates appropriate to this
	// delegate.
	Update(msg tea.Msg, m *Model) tea.Cmd
}

ItemDelegate encapsulates the general functionality for all list items. The benefit to separating this logic from the item itself is that you can change the functionality of items without changing the actual items themselves.

Note that if the delegate also implements help.KeyMap delegate-related help items will be added to the help view.

type KeyMap

type KeyMap struct {
	// Keybindings used when browsing the list.
	CursorUp    key.Binding
	CursorDown  key.Binding
	CursorLeft  key.Binding
	CursorRight key.Binding
	NextPage    key.Binding
	PrevPage    key.Binding
	GoToStart   key.Binding
	GoToEnd     key.Binding

	// The quit keybinding. This won't be caught when filtering.
	Quit key.Binding

	// The quit-no-matter-what keybinding. This will be caught when filtering.
	ForceQuit key.Binding
}

KeyMap defines keybindings. It satisfies to the help.KeyMap interface, which is used to render the menu.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns a default set of keybindings.

type Model

type Model struct {
	ItemNamePlural string

	Title  string
	Styles Styles

	// Key mappings for navigating the list.
	KeyMap KeyMap

	Paginator paginator.Model
	Help      help.Model
	// contains filtered or unexported fields
}

Model contains the state of this component.

func New

func New(items []Item, delegate ItemDelegate, width, height int) Model

New returns a new model with sensible defaults.

func (Model) Cursor

func (m Model) Cursor() int

Cursor returns the index of the cursor on the current page.

func (*Model) CursorDown

func (m *Model) CursorDown()

CursorDown moves the cursor down. This can also advance the state to the next page.

func (*Model) CursorLeft

func (m *Model) CursorLeft()

func (*Model) CursorRight

func (m *Model) CursorRight()

func (*Model) CursorUp

func (m *Model) CursorUp()

CursorUp moves the cursor up. This can also move the state to the previous page.

func (Model) FullHelp added in v0.1.4

func (m Model) FullHelp() [][]key.Binding

func (Model) GetOffset

func (m Model) GetOffset() int

func (Model) Height

func (m Model) Height() int

Height returns the current height setting.

func (Model) Index

func (m Model) Index() int

Index returns the index of the currently selected item as it appears in the entire slice of items.

func (Model) Items

func (m Model) Items() []Item

Items returns the items in the list.

func (Model) SelectedItem

func (m Model) SelectedItem() Item

SelectedItem returns the current selected item in the list.

func (*Model) SetDelegate

func (m *Model) SetDelegate(d ItemDelegate)

SetDelegate sets the item delegate.

func (*Model) SetHeight

func (m *Model) SetHeight(v int)

SetHeight sets the height of this component.

func (*Model) SetItems

func (m *Model) SetItems(i []Item) tea.Cmd

SetItems sets the items available in the list. This returns a command.

func (*Model) SetShowPagination

func (m *Model) SetShowPagination(v bool)

SetShowPagination hides or shows the paginator. Note that pagination will still be active, it simply won't be displayed.

func (*Model) SetShowTitle

func (m *Model) SetShowTitle(v bool)

SetShowTitle shows or hides the title bar.

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

SetSize sets the width and height of this component.

func (*Model) SetWidth

func (m *Model) SetWidth(v int)

SetWidth sets the width of this component.

func (Model) ShortHelp added in v0.1.4

func (m Model) ShortHelp() []key.Binding

func (*Model) ShowPagination

func (m *Model) ShowPagination() bool

ShowPagination returns whether the pagination is visible.

func (Model) ShowTitle

func (m Model) ShowTitle() bool

ShowTitle returns whether or not the title bar is set to be rendered.

func (Model) Update

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

Update is the Bubble Tea update loop.

func (Model) View

func (m Model) View() string

View renders the component.

func (Model) VisibleItems

func (m Model) VisibleItems() []Item

VisibleItems returns the total items available to be shown.

func (Model) Width

func (m Model) Width() int

Width returns the current width setting.

type Styles

type Styles struct {
	TitleBar lipgloss.Style
	Title    lipgloss.Style

	NoItems lipgloss.Style

	PaginationStyle lipgloss.Style
	HelpStyle       lipgloss.Style

	// Styled characters.
	ActivePaginationDot   lipgloss.Style
	InactivePaginationDot lipgloss.Style
	ArabicPagination      lipgloss.Style
	DividerDot            lipgloss.Style
}

Styles contains style definitions for this list component. By default, these values are generated by DefaultStyles.

func DefaultStyles

func DefaultStyles() (s Styles)

DefaultStyles returns a set of default style definitions for this list component.

Jump to

Keyboard shortcuts

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