components

package
v1.0.42971-pre Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyCtrlC     = "ctrl+c"
	KeyEnter     = "enter"
	KeyEsc       = "esc"
	KeyTab       = "tab"
	KeyShiftTab  = "shift+tab"
	KeyBackspace = "backspace"
	KeyHome      = "home"
	KeyEnd       = "end"
	KeyPgUp      = "pgup"
	KeyPgDown    = "pgdown"
	KeyUp        = "up"
	KeyDown      = "down"
	KeySlash     = "/"

	// Letter keys. The value is the literal bubbletea reports; uppercase
	// variants are the shifted key (e.g. "N" for shift+n).
	KeyQ      = "q"
	KeyR      = "r"
	KeyS      = "s"
	KeyShiftS = "S"
	KeyN      = "n"
	KeyShiftN = "N"
	KeyG      = "g"
	KeyShiftG = "G"
)

Key constants map bubbletea key-press string representations to named values.

View Source
const (

	// PreviewFrameWidth is how many columns the frame steals from the box's
	// outer width before content. Callers subtract it from the pane width to get
	// the column count content must wrap to (e.g. glamour word-wrap width).
	PreviewFrameWidth = previewBorderSize + previewPaddingX

	// PreviewFrameHeight is the rows the frame consumes, so callers can size the
	// box to leave room for surrounding chrome.
	PreviewFrameHeight = previewBorderSize // top+bottom border
)

previewFramePadding is the columns/rows lipgloss border + horizontal padding add around the content. The border costs 1 cell on each side (2 cols, 2 rows) and the padding adds 1 col on each side (2 cols).

View Source
const PagerFooterHeight = 2

PagerFooterHeight is the number of rows PagerModel reserves below the viewport for its footer (one blank separator row + the help/status line). Callers use it to decide whether content fits on one screen without paging.

Variables

View Source
var LinkStyle = lipgloss.NewStyle().
	Foreground(lipgloss.Color("#00ADD8")).
	Underline(true)

Functions

func NewSpinner

func NewSpinner(color bool) spinner.Model

Types

type PagerModel

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

PagerModel is a scrollable full-screen pager with less-style search built in. It wraps a viewport, owns the search engine, and renders a footer showing the scroll position, key hints and search state. It handles scrolling (↑/↓, page keys via the viewport), jump-to-top/bottom (g/G, home/end) and the whole "/" search interaction (typing, up/down to recall recent patterns, n/N navigation, match highlighting, scroll-to-match).

It deliberately does NOT handle the lifecycle keys (q, esc, ctrl+c): those mean different things to different hosts — quit here, go back to a picker there — so the embedding model owns them. The typical host loop is:

if !pager.Searching() {
    switch key {
    case "ctrl+c", "q": quit
    case "esc":
        if pager.SearchActive() { pager = pager.ClearSearch(); return }
        quit / go back
    }
}
pager, cmd = pager.Update(msg)

Guarding on Searching() first is important: while the "/" prompt is open those keys are text to be typed (or the prompt's own cancel/commit), not lifecycle actions, so they must fall through to Update.

Build with NewPager; the zero value is not usable. Content is supplied with SetContent / SetContentFollowingTail, or recomputed per width by a WithReflow callback on resize.

func NewPager

func NewPager() PagerModel

NewPager returns an empty pager. Chain WithHint / WithReflow / WithContent to configure it before use.

func (PagerModel) ClearSearch

func (m PagerModel) ClearSearch() PagerModel

ClearSearch dismisses the committed search, dropping its highlights, and leaves the viewport scrolled where it is.

func (PagerModel) GotoBottom

func (m PagerModel) GotoBottom() PagerModel

GotoBottom scrolls to the bottom of the content.

func (PagerModel) GotoTop

func (m PagerModel) GotoTop() PagerModel

GotoTop scrolls to the top of the content.

func (PagerModel) Init

func (m PagerModel) Init() tea.Cmd

func (PagerModel) Ready

func (m PagerModel) Ready() bool

Ready reports whether a terminal size has been seen, so the pager can render.

func (PagerModel) ResetSearch

func (m PagerModel) ResetSearch() PagerModel

ResetSearch clears the committed search (query, matches, prompt) and re-applies plain content, while preserving the in-memory recall history. Use it when opening fresh content that should start unsearched but still offer previous patterns for recall at the "/" prompt.

func (PagerModel) ScrollPercent

func (m PagerModel) ScrollPercent() float64

ScrollPercent is the viewport's scroll position in the range [0, 1].

func (PagerModel) SearchActive

func (m PagerModel) SearchActive() bool

SearchActive reports whether a committed search is present to dismiss (a query with matches, or a not-found notice). Hosts use it to decide whether Esc should clear the search or fall through to their own quit/back action.

func (PagerModel) Searching

func (m PagerModel) Searching() bool

Searching reports whether the "/" input prompt is currently active.

func (PagerModel) SetContent

func (m PagerModel) SetContent(raw string) PagerModel

SetContent replaces the paged content, preserving the scroll position, and re-applies any active search highlight.

func (PagerModel) SetContentFollowingTail

func (m PagerModel) SetContentFollowingTail(raw string) PagerModel

SetContentFollowingTail is like SetContent but keeps the view pinned to the bottom when it was already there, so streamed output that a reader is watching live keeps scrolling while a reader who has scrolled up to read is left alone.

func (PagerModel) SetSize

func (m PagerModel) SetSize(width, height int) PagerModel

SetSize applies a terminal size, sizing the viewport (reserving the footer), re-wrapping via the reflow callback when set, and re-applying search highlights. It is equivalent to feeding the pager a tea.WindowSizeMsg.

func (PagerModel) Update

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

Update handles scrolling, jump keys and the whole "/" search interaction. It leaves q/esc/ctrl+c untouched (except while the search prompt is open, where esc/enter cancel/commit the pattern) so the host can bind them. See PagerModel.

func (PagerModel) View

func (m PagerModel) View(status string) tea.View

View renders the viewport above the footer, on the alternate screen. status is an optional, already-styled segment shown at the left of the footer before the search state (e.g. a "streaming…" indicator); pass "" for none. It returns an empty view until a terminal size is known.

func (PagerModel) WithContent

func (m PagerModel) WithContent(raw string) PagerModel

WithContent seeds the initial content. It is rendered once a size is known.

func (PagerModel) WithHint

func (m PagerModel) WithHint(hint string) PagerModel

WithHint sets the footer key-hint text (e.g. "↑/↓ scroll · / search · q quit").

func (PagerModel) WithReflow

func (m PagerModel) WithReflow(reflow func(width int) string) PagerModel

WithReflow installs a callback that recomputes the content for a given width, invoked on every resize. Use it for content that must be re-wrapped to the terminal width (rendered markdown). Content that should merely soft-wrap needs no reflow; set it with SetContent instead.

type PreviewModel

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

PreviewModel is a display-only pane that frames pre-rendered content inside a bordered box. It does no rendering of its own — callers supply already-styled content (e.g. glamour-rendered markdown) and the box size, and PreviewModel only draws the frame. It is used as the right-hand pane of the theme picker to show sample markdown rendered in the highlighted theme.

PreviewModel is not a standalone bubbletea program: it has no Update loop and View returns a plain string so a parent model can compose it horizontally with other panes.

func NewPreviewModel

func NewPreviewModel() PreviewModel

NewPreviewModel returns an empty preview pane.

func (PreviewModel) ContentHeight

func (m PreviewModel) ContentHeight() int

ContentHeight is the row count available for content inside the frame. Callers use it to vertically place content (e.g. to center a loading placeholder).

func (PreviewModel) ContentWidth

func (m PreviewModel) ContentWidth() int

ContentWidth is the column count available for content inside the frame. Callers wrap their content (e.g. via glamour) to this width.

func (PreviewModel) View

func (m PreviewModel) View() string

View renders the bordered content box as a plain string for a parent model to place. Returns "" until a size has been set.

func (PreviewModel) WithContent

func (m PreviewModel) WithContent(content string) PreviewModel

WithContent returns a copy of the pane displaying content. Content is assumed to be pre-wrapped to ContentWidth(); anything wider is clipped by the box.

func (PreviewModel) WithSize

func (m PreviewModel) WithSize(width, height int) PreviewModel

WithSize returns a copy of the pane sized to the given outer width and height (in terminal cells), border and padding included.

type SelectModel

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

SelectModel is a single-choice picker rendered as a vertical list with a cursor (›) marking the focused option. ↑/↓ or k/j move; Enter confirms; Esc/Ctrl+C cancels. When the option list is taller than the available height the list scrolls to keep the cursor visible (see WithHeight).

func NewSelectModel

func NewSelectModel(prompt string, options []string) SelectModel

func (SelectModel) Done

func (m SelectModel) Done() bool

Done reports whether the user has confirmed a selection.

func (SelectModel) Init

func (m SelectModel) Init() tea.Cmd

func (SelectModel) Selected

func (m SelectModel) Selected() int

Selected returns the index chosen by the user. Only valid when Done().

func (SelectModel) Update

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

func (SelectModel) View

func (m SelectModel) View() tea.View

func (SelectModel) WithCursor

func (m SelectModel) WithCursor(i int) SelectModel

WithCursor returns a copy of the model with the initial cursor positioned at index i, clamped to the available options. Use this to pre-select a default choice.

func (SelectModel) WithHeight

func (m SelectModel) WithHeight(rows int) SelectModel

WithHeight sets the number of terminal rows available to the picker. When the option list is taller than this, the list scrolls to keep the cursor visible and a position indicator ("(3–12 of 40)") is appended to the hint. Zero (the default) imposes no limit and renders every option.

func (SelectModel) WithHint

func (m SelectModel) WithHint(hint string) SelectModel

WithHint returns a copy of the model with a custom footer hint line.

func (SelectModel) WithIcons

func (m SelectModel) WithIcons(icons []string) SelectModel

WithIcons attaches an optional status icon to each option. icons is parallel to the options passed to NewSelectModel; an empty string means "no icon" for that row. Each icon is rendered in a fixed column before the label and is emitted verbatim — already styled by the caller if color is wanted — outside the cursor/selection styling, so a status color survives even on the highlighted or chosen row. Rows align one column further in when any option carries an icon.

func (SelectModel) WithNote

func (m SelectModel) WithNote(note string) SelectModel

WithNote returns a copy of the model with an informational note rendered between the title and the options (e.g. a run's config error). An empty note renders nothing. The note is emitted verbatim — style it in the caller if color is wanted — and may span multiple lines, which are reserved for when the option list scrolls.

type TokenModel

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

func NewTokenModel

func NewTokenModel() TokenModel

func (TokenModel) Init

func (m TokenModel) Init() tea.Cmd

func (TokenModel) Token

func (m TokenModel) Token() string

func (TokenModel) Update

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

func (TokenModel) View

func (m TokenModel) View() tea.View

Jump to

Keyboard shortcuts

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