Documentation
¶
Index ¶
- type CompareFn
- type Highlight
- type KeyMap
- type Model
- func (m *Model[T]) EnsureItemInView(itemIdx, startWidth, endWidth, verticalPad, horizontalPad int)
- func (m *Model[T]) GetHeight() int
- func (m *Model[T]) GetHighlights() []Highlight
- func (m *Model[T]) GetPreFooterLine() string
- func (m *Model[T]) GetSelectedItem() *T
- func (m *Model[T]) GetSelectedItemIdx() int
- func (m *Model[T]) GetSelectionEnabled() bool
- func (m *Model[T]) GetTopItemIdxAndLineOffset() (int, int)
- func (m *Model[T]) GetWidth() int
- func (m *Model[T]) GetWrapText() bool
- func (m *Model[T]) GetXOffsetWidth() int
- func (m *Model[T]) IsCapturingInput() bool
- func (m *Model[T]) SetBottomSticky(bottomSticky bool)
- func (m *Model[T]) SetFooterEnabled(footerEnabled bool)
- func (m *Model[T]) SetHeader(header []string)
- func (m *Model[T]) SetHeight(height int)
- func (m *Model[T]) SetHighlights(highlights []Highlight)
- func (m *Model[T]) SetObjects(objects []T)
- func (m *Model[T]) SetPostHeaderLine(line string)
- func (m *Model[T]) SetPreFooterLine(line string)
- func (m *Model[T]) SetProgressBarEnabled(enabled bool)
- func (m *Model[T]) SetSelectedItemIdx(selectedItemIdx int)
- func (m *Model[T]) SetSelectionComparator(compareFn CompareFn[T])
- func (m *Model[T]) SetSelectionEnabled(selectionEnabled bool)
- func (m *Model[T]) SetStyles(styles Styles)
- func (m *Model[T]) SetTopSticky(topSticky bool)
- func (m *Model[T]) SetWidth(width int)
- func (m *Model[T]) SetWrapText(wrapText bool)
- func (m *Model[T]) SetXOffset(widthOffset int)
- func (m *Model[T]) Update(msg tea.Msg) (*Model[T], tea.Cmd)
- func (m *Model[T]) View() string
- type Object
- type Option
- func WithFileSaving[T Object](saveDir string, saveKey key.Binding) Option[T]
- func WithFooterEnabled[T Object](enabled bool) Option[T]
- func WithKeyMap[T Object](keyMap KeyMap) Option[T]
- func WithProgressBarEnabled[T Object](enabled bool) Option[T]
- func WithSelectionEnabled[T Object](enabled bool) Option[T]
- func WithSelectionStyleOverridesItemStyle[T Object](overrides bool) Option[T]
- func WithStickyBottom[T Object](stickyBottom bool) Option[T]
- func WithStickyTop[T Object](stickyTop bool) Option[T]
- func WithStyles[T Object](styles Styles) Option[T]
- func WithWrapText[T Object](wrap bool) Option[T]
- type Styles
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyMap ¶
type KeyMap struct {
PageDown key.Binding
PageUp key.Binding
HalfPageUp key.Binding
HalfPageDown key.Binding
Up key.Binding
Down key.Binding
Left key.Binding
Right key.Binding
Top key.Binding
Bottom key.Binding
}
KeyMap contains viewport key bindings
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
DefaultKeyMap returns a set of default key bindings for the viewport
type Model ¶
type Model[T Object] struct { // contains filtered or unexported fields }
Model represents a viewport component
func (*Model[T]) EnsureItemInView ¶
EnsureItemInView scrolls or pans the viewport so that the specified portion of an item is visible. If the desired item portion is above or below the current view, it scrolls vertically to bring it into view, leaving verticalPad number of lines of context if possible. If the desired item portion is to the left or right of the current view, it pans horizontally to bring it into view, leaving horizontalPad number of columns of context if possible. Afterwards, it's possible that the selection is out of view of the viewport.
func (*Model[T]) GetHighlights ¶
GetHighlights returns all highlights.
func (*Model[T]) GetPreFooterLine ¶
GetPreFooterLine returns the current pre-footer line.
func (*Model[T]) GetSelectedItem ¶
func (m *Model[T]) GetSelectedItem() *T
GetSelectedItem returns a pointer to the currently selected item
func (*Model[T]) GetSelectedItemIdx ¶
GetSelectedItemIdx returns the currently selected item index
func (*Model[T]) GetSelectionEnabled ¶
GetSelectionEnabled returns whether the viewport allows line selection
func (*Model[T]) GetTopItemIdxAndLineOffset ¶
GetTopItemIdxAndLineOffset returns the current top item index and line offset within that item
func (*Model[T]) GetWrapText ¶
GetWrapText returns whether the viewport wraps text
func (*Model[T]) GetXOffsetWidth ¶
GetXOffsetWidth returns the horizontal offset, in terminal cell width, for panning when text wrapping is disabled
func (*Model[T]) IsCapturingInput ¶
IsCapturingInput returns true when the viewport is in a mode that should capture all input (e.g., filename entry for saving). Callers should forward all messages to the viewport without processing them when this returns true.
func (*Model[T]) SetBottomSticky ¶
SetBottomSticky sets whether selection should stay at bottom when new Item added and selection is at the bottom
func (*Model[T]) SetFooterEnabled ¶
SetFooterEnabled sets whether the viewport shows the footer when it overflows
func (*Model[T]) SetHeader ¶
SetHeader sets the header, an unselectable set of lines at the top of the viewport
func (*Model[T]) SetHighlights ¶
SetHighlights sets specific positions to highlight with custom styles in the viewport.
func (*Model[T]) SetObjects ¶
func (m *Model[T]) SetObjects(objects []T)
SetObjects sets the objects
func (*Model[T]) SetPostHeaderLine ¶
SetPostHeaderLine sets a line to render just below the header. Pass empty string to disable. The line will be truncated to viewport width.
func (*Model[T]) SetPreFooterLine ¶
SetPreFooterLine sets a line to render just above the footer. Pass empty string to disable. The line will be truncated to viewport width.
func (*Model[T]) SetProgressBarEnabled ¶
SetProgressBarEnabled sets whether the footer displays a Unicode progress bar in the footer
func (*Model[T]) SetSelectedItemIdx ¶
SetSelectedItemIdx sets the selected context index. Automatically puts selection in view as necessary
func (*Model[T]) SetSelectionComparator ¶
SetSelectionComparator sets the comparator function for maintaining the current selection when Item changes. If compareFn is non-nil, the viewport will try to maintain the current selection when Item changes.
func (*Model[T]) SetSelectionEnabled ¶
SetSelectionEnabled sets whether the viewport allows line selection
func (*Model[T]) SetTopSticky ¶
SetTopSticky sets whether selection should stay at top when new Item added and selection is at the top
func (*Model[T]) SetWrapText ¶
SetWrapText sets whether the viewport wraps text
func (*Model[T]) SetXOffset ¶
SetXOffset sets the horizontal offset, in terminal cell width, for panning when text wrapping is disabled
type Object ¶
Object is implemented by types that can return an Item It exists to allow the viewport to return the selected object without (de)serializing it
type Option ¶
Option is a functional option for configuring the viewport
func WithFileSaving ¶
WithFileSaving configures automatic file saving when a hotkey is pressed. Files are saved to the specified directory with timestamp-based names.
func WithFooterEnabled ¶
WithFooterEnabled sets whether the viewport shows the footer
func WithKeyMap ¶
WithKeyMap sets the key mapping for the viewport
func WithProgressBarEnabled ¶
WithProgressBarEnabled sets whether the footer displays a Unicode progress bar
func WithSelectionEnabled ¶
WithSelectionEnabled sets whether the viewport allows selection
func WithSelectionStyleOverridesItemStyle ¶
WithSelectionStyleOverridesItemStyle controls whether the selection style replaces the item's existing ANSI styling. When true (default), the selected item is stripped of its original styling and the selection style is applied to all non-highlighted regions. When false, the item keeps its original styling and the selection style is applied only to unstyled regions.
func WithStickyBottom ¶
WithStickyBottom sets whether to automatically scroll to the bottom when content changes
func WithStickyTop ¶
WithStickyTop sets whether to automatically scroll to the top when content changes
func WithStyles ¶
WithStyles sets the styling for the viewport
func WithWrapText ¶
WithWrapText sets whether the viewport wraps text
type Styles ¶
type Styles struct {
// SelectionPrefix is prepended to each visible line of the selected item.
// Non-selected lines get equivalent-width blank padding to maintain alignment.
// Only applied when selection is enabled and this string is non-empty.
// This is the primary mechanism for selection visibility under NO_COLOR.
SelectionPrefix string
SelectedItemStyle lipgloss.Style
}
Styles contains styling configuration for the viewport
func DefaultStyles ¶
func DefaultStyles() Styles
DefaultStyles returns a set of default styles for the viewport. Uses only reverse video — no 256-color or true-color values.