ui

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 57 Imported by: 0

Documentation

Overview

Package ui implements the Bubbletea terminal application model for toe

Index

Constants

View Source
const (
	AboutVersion     i18n.Key = "about.version"
	AboutDevelopment i18n.Key = "about.development"
)
View Source
const (
	// CompletionAcceptAction accepts the selected completion item
	CompletionAcceptAction = "completion_accept"

	// CompletionCancelAction dismisses the completion popup
	CompletionCancelAction = "completion_cancel"

	// CompletionPreviousAction selects the previous completion item
	CompletionPreviousAction = "completion_previous"

	// CompletionNextAction selects the next completion item
	CompletionNextAction = "completion_next"

	// CompletionPageUpAction moves selection up by one completion page
	CompletionPageUpAction = "completion_page_up"

	// CompletionPageDownAction moves selection down by one completion page
	CompletionPageDownAction = "completion_page_down"

	// CompletionFirstAction selects the first completion item
	CompletionFirstAction = "completion_first"

	// CompletionLastAction selects the last completion item
	CompletionLastAction = "completion_last"
)
View Source
const (
	// DefaultCompletionDelay is the idle time before an automatic request,
	// long enough that a fast typist does not queue one per keystroke
	DefaultCompletionDelay = 250

	// DefaultCompletionTriggerLen is the automatic completion threshold
	DefaultCompletionTriggerLen = 2
)
View Source
const (
	DefaultPickerSplitRatio = 0.5
	MinPickerSplitRatio     = 0.2
	MaxPickerSplitRatio     = 0.8
)
View Source
const PickerMaxPreview = 10 * 1024 * 1024

PickerMaxPreview is the largest file size a picker will preview inline

Variables

View Source
var (
	ErrNoFocusedDocument = errors.New("no focused document")
	ErrNoFocusedView     = errors.New("no focused view")
	ErrUnknownVariable   = errors.New("unknown variable")
	ErrInvalidUnicode    = errors.New("invalid Unicode codepoint")
	ErrShellExpansion    = errors.New("shell expansion failed")
	ErrInvalidRegister   = errors.New("invalid register")
)
View Source
var ErrInvalidImage = errors.New("invalid image")

ErrInvalidImage reports a file that cannot be decoded as an image

View Source
var ErrScrollbackNoMatch = errors.New("pattern not found in scrollback")

Functions

func CloseAllTerminalPanes

func CloseAllTerminalPanes(e *view.Editor)

CloseAllTerminalPanes kills every open terminal's shell so the process does not orphan them on exit

func CompletionModule added in v0.2.1

func CompletionModule(model Model) command.Module

CompletionModule returns the completion-popup navigation commands. It lives beside completionComponent because the popup implements every action here by intercepting the resolved command name

func DiagnosticMessageText added in v0.2.4

func DiagnosticMessageText(message string) string

DiagnosticMessageText flattens a server's message onto one line and shortens the qualified names in it

func FromTeaKey

func FromTeaKey(k tea.KeyPressMsg) command.KeyEvent

FromTeaKey converts a Bubbletea v2 KeyPressMsg to a KeyEvent

func GotoDocument added in v0.3.2

func GotoDocument(
	e *view.Editor, id view.DocumentId, sel GotoSelector,
	accept PickerAcceptAction,
) (*view.View, bool)

GotoDocument navigates the pane to an open document, placing the selection the selector resolves and scrolling it into view

func GotoJump added in v0.3.2

func GotoJump(
	e *view.Editor, index int, accept PickerAcceptAction,
) (*view.View, bool)

GotoJump navigates to the jump list entry at index, moving the list head onto it instead of recording a new jump, so the history either side of it survives. A split accept opens a new pane and records a jump as usual

func GotoPath added in v0.3.2

func GotoPath(
	e *view.Editor, path string, sel GotoSelector, accept PickerAcceptAction,
) (*view.View, bool)

GotoPath navigates the pane to a file, switching to it when it is already open, placing the selection the selector resolves and scrolling it into view. Image and binary files open as their own panes and take no selection

func NewTokenExpander

func NewTokenExpander(e *view.Editor) command.TokenExpander

NewTokenExpander returns a TokenExpander that resolves percent-expansions using the current editor state (selections, registers, variables, shell)

func OpenPath

func OpenPath(
	e *view.Editor, path string, action PickerAcceptAction,
) (*view.View, bool, error)

OpenPath opens a text document, image pane, or binary dump at path

func PickerNamePath added in v0.2.4

func PickerNamePath(rel string) (string, int)

PickerNamePath renders a path name-first, trailing the directory holding it, and returns the rune offset where that directory begins

func PickerTrailingPath added in v0.2.4

func PickerTrailingPath(text, rel string) (string, int)

PickerTrailingPath trails a path behind a row's own text, and returns the rune offset where that path begins

func SkipPickerPath

func SkipPickerPath(args SkipPickerPathArgs) bool

SkipPickerPath reports whether a walked entry should be excluded from a picker's file listing under the given ignore rules

func SortPickerItems

func SortPickerItems(items []*PickerItem)

SortPickerItems sorts items by sort key, falling back to display text, the default ordering for static picker sources

func TrueColorSupported added in v0.1.35

func TrueColorSupported() bool

TrueColorSupported reports whether the terminal can render 24-bit color, based on well-known environment variables

Types

type BinaryPane added in v0.1.21

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

BinaryPane displays a read-only, responsive hexadecimal dump

func NewBinaryPane added in v0.1.21

func NewBinaryPane(e *view.Editor, path string) (*BinaryPane, error)

NewBinaryPane opens path as a read-only binary dump

func (*BinaryPane) Area added in v0.1.21

func (p *BinaryPane) Area() geom.Area

Area returns the screen rectangle assigned by the layout tree

func (*BinaryPane) ConsumeDirty added in v0.1.21

func (p *BinaryPane) ConsumeDirty() bool

ConsumeDirty reports and clears whether the pane changed

func (*BinaryPane) Cursor added in v0.1.21

func (p *BinaryPane) Cursor(*Context) (tea.Cursor, bool)

Cursor reports that a binary pane has no text cursor

func (*BinaryPane) Discard added in v0.1.21

func (p *BinaryPane) Discard()

Discard releases this displaced binary pane

func (*BinaryPane) HandleEvent added in v0.1.21

func (p *BinaryPane) HandleEvent(
	cx *Context, msg tea.Msg,
) (EventResult, bool)

HandleEvent scrolls the binary dump

func (*BinaryPane) ID added in v0.1.21

func (p *BinaryPane) ID() view.Id

ID returns the pane identifier

func (*BinaryPane) MarkDirty added in v0.1.21

func (p *BinaryPane) MarkDirty()

MarkDirty flags the pane as needing a repaint

func (*BinaryPane) Mode added in v0.1.21

func (p *BinaryPane) Mode() view.Mode

Mode reports binary dump mode

func (*BinaryPane) Path added in v0.1.21

func (p *BinaryPane) Path() string

Path returns the binary file path

func (*BinaryPane) SaveSession added in v0.1.21

func (p *BinaryPane) SaveSession(w *view.SessionWriter)

SaveSession stores the binary path and viewport offset

func (*BinaryPane) SetArea added in v0.1.21

func (p *BinaryPane) SetArea(a geom.Area)

SetArea sets the screen rectangle assigned by the layout tree

func (*BinaryPane) SetID added in v0.1.21

func (p *BinaryPane) SetID(id view.Id)

SetID sets the pane identifier

func (*BinaryPane) Shutdown added in v0.1.21

func (p *BinaryPane) Shutdown()

Shutdown releases external resources owned by this pane

func (*BinaryPane) Split added in v0.1.21

func (p *BinaryPane) Split() (view.Pane, error)

Split returns another pane displaying the same binary dump

type BufferOverlayComponent

type BufferOverlayComponent interface {
	Component
	Layout(*Context, geom.Size) (geom.Area, bool)
	PaintBuffer(*Context, geom.Area) *tui.Buffer
}

BufferOverlayComponent extends Component for overlay layers that own their own cell buffer instead of drawing into the shared one

type BufferRenderer

type BufferRenderer interface {
	Component
	Render(*Context, geom.Size) *tui.Buffer
}

BufferRenderer exposes the raw cell buffer a base component rendered into, so overlay layers can draw directly onto it

type Callback

type Callback func(*Context, *Compositor) tea.Cmd

Callback lets a component push, pop, or mutate compositor layers without direct coupling, the compositor executes it after event propagation completes

type CompletionOptions added in v0.1.13

type CompletionOptions struct {
	Auto       bool `toml:"auto"`
	Delay      int  `toml:"delay"`
	TriggerLen int  `toml:"trigger-len"`
}

CompletionOptions controls the completion popup that appears while typing, without an explicit completion keypress

func DefaultCompletionOptions added in v0.1.13

func DefaultCompletionOptions() CompletionOptions

DefaultCompletionOptions returns the automatic completion defaults

type Component

type Component interface {
	HandleEvent(*Context, tea.Msg) (EventResult, tea.Cmd)
	Cursor(*Context, geom.Size) (tea.Cursor, bool)
}

Component is the interface every compositor layer must implement

type Compositor

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

Compositor manages the editor's layered components

func (*Compositor) Cursor

func (c *Compositor) Cursor(cx *Context) (cur tea.Cursor, ok bool)

Cursor returns the cursor of the topmost layer that wants one

func (*Compositor) HandleEvent

func (c *Compositor) HandleEvent(cx *Context, msg tea.Msg) tea.Cmd

HandleEvent offers a message to each layer from the top down

func (*Compositor) Pop

func (c *Compositor) Pop()

Pop removes the topmost layer

func (*Compositor) Push

func (c *Compositor) Push(layer Component)

Push adds a layer above the current top

func (*Compositor) Render

func (c *Compositor) Render(cx *Context) string

Render paints every layer bottom up into one frame

type Context

type Context struct {
	Editor  *view.Editor
	Keymaps *command.Keymaps
	Syntax  *syntax.Cache
	// contains filtered or unexported fields
}

Context holds shared mutable state accessible to all compositor layers

func (*Context) StyleGen

func (c *Context) StyleGen() int

StyleGen returns a counter that increments whenever the active theme changes, letting cached overlay buffers know they must repaint even without their own content changing

func (*Context) Theme

func (c *Context) Theme() *theme.Theme

Theme returns the active theme, reloading it if the configured name changed, falling back to the embedded default on load failure

func (*Context) ThemeFor added in v0.1.25

func (c *Context) ThemeFor(focused bool) *theme.Theme

ThemeFor returns the active theme, or its dimmed variant for an unfocused pane

type Draggable

type Draggable interface {
	BeginDrag(*Context, geom.Point, tea.KeyMod) bool
	ContinueDrag(*Context, geom.Point) tea.Cmd
	EndDrag(*Context, geom.Point) tea.Cmd
	CancelDrag()
	DragTick(cx *Context, gen int, toLow bool) tea.Cmd
}

Draggable is a pane that handles mouse drags itself. Drags span several events with cross-event state, so they stay separate from PaneInput

type DynamicPickerSource

type DynamicPickerSource interface {
	PickerSource
	Search(query string)
}

DynamicPickerSource extends PickerSource with query-driven search

type EditorComponent

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

func (*EditorComponent) Cursor

func (e *EditorComponent) Cursor(
	cx *Context, screen geom.Size,
) (tea.Cursor, bool)

Cursor returns the focused pane's cursor position and shape

func (*EditorComponent) HandleEvent

func (e *EditorComponent) HandleEvent(
	cx *Context, msg tea.Msg,
) (EventResult, tea.Cmd)

HandleEvent routes keys, mouse, and editor messages to the panes

func (*EditorComponent) MacroRecordAction

func (e *EditorComponent) MacroRecordAction(
	ed *view.Editor,
) command.Continuation

MacroRecordAction starts or stops macro recording. When not recording, prompts for a register key and begins recording. When already recording, stops and saves the macro to the chosen register

func (*EditorComponent) MacroReplayAction

func (e *EditorComponent) MacroReplayAction(
	_ *view.Editor,
) command.Continuation

MacroReplayAction prompts for a register key and replays the macro stored there count times

func (*EditorComponent) Render

func (e *EditorComponent) Render(cx *Context, screen geom.Size) *tui.Buffer

Render returns the editor's cell buffer for the compositor to blit overlays onto, skipping an ANSI round-trip

type EventResult

type EventResult struct {
	Consumed bool
	Callback Callback
}

EventResult is returned by every Component.HandleEvent call

type FileBackedPickerSource added in v0.1.27

type FileBackedPickerSource interface {
	PickerSource
	// ItemForPath returns the current row for path and whether the source
	// contains it
	ItemForPath(e *view.Editor, path string) (*PickerItem, bool)
}

FileBackedPickerSource is a picker whose rows are workspace files, each reconciled one changed path at a time

type GotoSelector added in v0.3.2

type GotoSelector func(core.Rope) (core.Selection, bool)

GotoSelector resolves the selection to place once the destination document is open; a nil selector leaves the document's selection alone

func GotoLines added in v0.3.2

func GotoLines(lines *core.Span) GotoSelector

GotoLines returns a selector covering the first line of lines

func GotoSelection added in v0.3.2

func GotoSelection(sel core.Selection) GotoSelector

GotoSelection returns a selector that always resolves to sel

type IgnoreTarget added in v0.2.0

type IgnoreTarget struct {
	Root string
	Path string
}

IgnoreTarget is the walk root and the path being tested against the ignore rules that apply to it

type Image

type Image struct {
	image.Image
	// contains filtered or unexported fields
}

Image holds decoded image data, its content identifier, and the decoded source format (e.g. "png") for transmission fast paths

func LoadImage

func LoadImage(path string) (*Image, error)

LoadImage reads path and returns a decoded image

func (*Image) ContentID

func (i *Image) ContentID() uint32

ContentID returns a stable identifier for the decoded image bytes

func (*Image) Size

func (i *Image) Size() geom.Size

Size returns the image bounds in pixels

type ImagePane

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

ImagePane displays an image in the editor's pane tree, zooming and panning it in response to keys and mouse, and shows no text cursor

func NewImagePane

func NewImagePane(e *view.Editor, path string) (*ImagePane, error)

NewImagePane loads path into an image pane

func (*ImagePane) Area

func (p *ImagePane) Area() geom.Area

Area returns the screen rectangle assigned by the layout tree

func (*ImagePane) ConsumeDirty

func (p *ImagePane) ConsumeDirty() bool

ConsumeDirty reports and clears whether the pane changed

func (*ImagePane) Cursor

func (p *ImagePane) Cursor(*Context) (tea.Cursor, bool)

Cursor reports that an image pane shows no text cursor

func (*ImagePane) Discard

func (p *ImagePane) Discard()

Discard releases this displaced image pane

func (*ImagePane) HandleEvent

func (p *ImagePane) HandleEvent(
	cx *Context, msg tea.Msg,
) (EventResult, bool)

HandleEvent handles image mouse input: a left click zooms in, a right or modified left click zooms out, a bare wheel pans, and a modified wheel zooms. Everything else falls through to the editor

func (*ImagePane) ID

func (p *ImagePane) ID() view.Id

ID returns the pane identifier

func (*ImagePane) Image

func (p *ImagePane) Image() *Image

Image returns the decoded image

func (*ImagePane) MarkDirty

func (p *ImagePane) MarkDirty()

MarkDirty flags the pane as needing a repaint

func (*ImagePane) Mode

func (p *ImagePane) Mode() view.Mode

Mode reports image mode

func (*ImagePane) OnDisplace added in v0.1.16

func (p *ImagePane) OnDisplace()

OnDisplace drops the decoded bitmap while the pane is stashed behind another pane, freeing its memory

func (*ImagePane) OnRevert added in v0.1.16

func (p *ImagePane) OnRevert()

OnRevert re-decodes the backing file when the pane returns to view

func (*ImagePane) Pan added in v0.1.3

func (p *ImagePane) Pan() geom.Point

Pan returns the view offset from center, in grid cells

func (*ImagePane) PanBy added in v0.1.3

func (p *ImagePane) PanBy(delta geom.Point)

PanBy shifts the view by the given cell delta

func (*ImagePane) PanDown added in v0.1.3

func (p *ImagePane) PanDown()

PanDown shifts the viewport one step down

func (*ImagePane) PanLeft added in v0.1.3

func (p *ImagePane) PanLeft()

PanLeft shifts the viewport one step left

func (*ImagePane) PanRight added in v0.1.3

func (p *ImagePane) PanRight()

PanRight shifts the viewport one step right

func (*ImagePane) PanUp added in v0.1.3

func (p *ImagePane) PanUp()

PanUp shifts the viewport one step up

func (*ImagePane) Path

func (p *ImagePane) Path() string

Path returns the loaded image path

func (*ImagePane) Reload

func (p *ImagePane) Reload() error

Reload re-decodes the backing file after an external change; the new bytes yield a new ContentID, so the display path retransmits automatically

func (*ImagePane) ResetZoom

func (p *ImagePane) ResetZoom()

ResetZoom restores the fitted image scale and recenters the view

func (*ImagePane) SaveSession

func (p *ImagePane) SaveSession(w *view.SessionWriter)

SaveSession stores the image path so the pane can be reopened

func (*ImagePane) SetArea

func (p *ImagePane) SetArea(a geom.Area)

SetArea sets the screen rectangle assigned by the layout tree

func (*ImagePane) SetID

func (p *ImagePane) SetID(id view.Id)

SetID sets the pane identifier

func (*ImagePane) Shutdown

func (p *ImagePane) Shutdown()

Shutdown releases external resources owned by this pane

func (*ImagePane) Split

func (p *ImagePane) Split() (view.Pane, error)

Split returns another pane displaying the same image

func (*ImagePane) Zoom

func (p *ImagePane) Zoom() int

Zoom returns the image scale as a percentage of its fitted size

func (*ImagePane) ZoomIn

func (p *ImagePane) ZoomIn()

ZoomIn increases the image scale

func (*ImagePane) ZoomOut

func (p *ImagePane) ZoomOut()

ZoomOut decreases the image scale

type MatchResult added in v0.1.19

type MatchResult struct {
	Score   int
	Indices []int
}

MatchResult is a source's verdict on one item: its rank against the query, and the rune offsets to highlight in the matched column

type Model

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

Model is the root Bubbletea model, a thin wrapper around Compositor

func New

func New(e *view.Editor, km *command.Keymaps) Model

New creates an initialized Model for the given editor and keymaps

func (Model) AboutAction added in v0.2.0

func (m Model) AboutAction(_ *view.Editor)

AboutAction opens the about popup

func (Model) Animation added in v0.1.32

func (m Model) Animation() bool

Animation reports whether UI animations (such as auto-size growth) play

func (Model) AutoSize added in v0.1.28

func (m Model) AutoSize() bool

AutoSize reports whether focused panes widen to fit their content

func (Model) Close added in v0.1.27

func (m Model) Close()

Close releases the model's long-lived resources, such as file watches

func (Model) CmdModeAction

func (m Model) CmdModeAction(_ *view.Editor)

CmdModeAction opens the command prompt

func (Model) CodeActionPickerAction

func (m Model) CodeActionPickerAction(e *view.Editor)

CodeActionPickerAction opens a menu of code actions at the cursor

func (Model) CommandPaletteAction

func (m Model) CommandPaletteAction(e *view.Editor)

CommandPaletteAction opens the command palette

func (Model) CommandPalettePicker added in v0.3.0

func (m Model) CommandPalettePicker(e *view.Editor) *Picker

CommandPalettePicker opens a picker listing all registered commands

func (Model) CompletionAction

func (m Model) CompletionAction(e *view.Editor)

CompletionAction requests completions at the cursor

func (Model) CompletionOptions added in v0.1.13

func (m Model) CompletionOptions() CompletionOptions

CompletionOptions returns the UI-owned automatic completion settings

func (Model) ExecTypable

func (m Model) ExecTypable(input string) Model

ExecTypable runs a typed command line, reporting unknown commands

func (Model) GotoDeclarationAction

func (m Model) GotoDeclarationAction(e *view.Editor)

GotoDeclarationAction jumps to the declaration of the symbol at the cursor

func (Model) GotoDefinitionAction

func (m Model) GotoDefinitionAction(e *view.Editor)

GotoDefinitionAction jumps to the definition of the symbol at the cursor

func (Model) GotoImplementationAction

func (m Model) GotoImplementationAction(e *view.Editor)

GotoImplementationAction jumps to implementations of the symbol at the cursor

func (Model) GotoReferenceAction

func (m Model) GotoReferenceAction(e *view.Editor)

GotoReferenceAction lists references to the symbol at the cursor

func (Model) GotoTypeDefinitionAction

func (m Model) GotoTypeDefinitionAction(e *view.Editor)

GotoTypeDefinitionAction jumps to the type of the symbol at the cursor

func (Model) HoverAction

func (m Model) HoverAction(e *view.Editor)

HoverAction requests documentation for the symbol at the cursor

func (Model) Init

func (m Model) Init() tea.Cmd

Init fires the startup cmd if one was set before the program started

func (Model) LastPickerAction

func (m Model) LastPickerAction(e *view.Editor)

LastPickerAction reopens the picker used most recently

func (Model) MacroRecordAction

func (m Model) MacroRecordAction(e *view.Editor) command.Continuation

MacroRecordAction starts or stops recording a macro

func (Model) MacroReplayAction

func (m Model) MacroReplayAction(e *view.Editor) command.Continuation

MacroReplayAction replays the recorded macro

func (Model) PickerAction

func (m Model) PickerAction(fn PickerFunc) command.Action

PickerAction returns an action opening the picker fn builds

func (Model) PickerLayoutOptions

func (m Model) PickerLayoutOptions() PickerLayoutOptions

PickerLayoutOptions returns the UI-owned picker layout settings

func (Model) RegexAction

func (m Model) RegexAction(prompt i18n.Key, fn promptHandler) command.Action

RegexAction returns an action prompting for a pattern, then running fn

func (Model) RenameSymbolAction

func (m Model) RenameSymbolAction(e *view.Editor)

RenameSymbolAction prompts for a new name and applies the server's edits

func (Model) ResizeViewAction

func (m Model) ResizeViewAction(e *view.Editor) command.Continuation

ResizeViewAction starts interactive split resizing

func (Model) SearchAction

func (m Model) SearchAction(forward bool) command.Action

SearchAction returns an action opening the search prompt

func (Model) SelectReferencesAction

func (m Model) SelectReferencesAction(e *view.Editor)

SelectReferencesAction selects every reference to the symbol at the cursor

func (Model) SetAnimation added in v0.1.32

func (m Model) SetAnimation(enabled bool)

SetAnimation controls whether UI animations play; when off they snap to their final state

func (Model) SetAutoSize added in v0.1.28

func (m Model) SetAutoSize(enabled bool)

SetAutoSize controls whether focused panes widen to fit their content

func (Model) SetCompletionOptions added in v0.1.13

func (m Model) SetCompletionOptions(opts CompletionOptions)

SetCompletionOptions applies UI-owned automatic completion settings

func (Model) SetPickerLayoutOptions

func (m Model) SetPickerLayoutOptions(opts PickerLayoutOptions)

SetPickerLayoutOptions applies UI-owned picker layout settings

func (Model) ShellAction

func (m Model) ShellAction(prompt i18n.Key, fn promptHandler) command.Action

ShellAction returns an action prompting for a command, then running fn

func (Model) SignatureHelpAction

func (m Model) SignatureHelpAction(e *view.Editor)

SignatureHelpAction requests parameter hints for the call at the cursor

func (Model) SymbolPickerAction

func (m Model) SymbolPickerAction(e *view.Editor)

SymbolPickerAction opens a picker over the focused document's symbols

func (Model) TerminalAction

func (m Model) TerminalAction(e *view.Editor)

TerminalAction opens the user's shell in the focused pane

func (Model) TerminalSearchAction

func (m Model) TerminalSearchAction(e *view.Editor)

TerminalSearchAction opens a prompt that jumps the focused terminal's scrollback to the nearest match above the current view

func (Model) Update

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

Update delegates all events to the compositor

func (Model) View

func (m Model) View() tea.View

View renders the current frame via the compositor

func (Model) WithInitialPicker

func (m Model) WithInitialPicker(fn PickerFunc) Model

WithInitialPicker returns a model that opens a picker on start

func (Model) WithStartupCmd

func (m Model) WithStartupCmd(cmd tea.Cmd) Model

WithStartupCmd returns a model that runs cmd once on start

func (Model) WithStartupMessage

func (m Model) WithStartupMessage(msg string) Model

WithStartupMessage sets a status bar message for the first frame

func (Model) WorkspaceSymbolPickerAction

func (m Model) WorkspaceSymbolPickerAction(e *view.Editor)

WorkspaceSymbolPickerAction opens a picker over workspace symbols

type NavigablePickerSource interface {
	PickerSource
	Navigate(*view.Editor, *PickerItem) PickerFunc
}

NavigablePickerSource extends PickerSource for pickers that can drill into sub-pickers. Navigate returns a PickerFunc to replace the current picker, or nil to fall through to Accept

type PaneCursor

type PaneCursor interface {
	Cursor(*Context) (tea.Cursor, bool)
}

PaneCursor is a pane that positions its own cursor

type PaneInput

type PaneInput interface {
	HandleEvent(*Context, tea.Msg) (EventResult, bool)
}

PaneInput is a pane that handles bubbletea key and mouse events itself. It receives the event first; an unconsumed event (handled=false) falls through to the editor's default keymap/document handling

type Pasteable

type Pasteable interface {
	Paste(text string)
}

Pasteable is a pane that consumes a paste itself instead of the document/selection paste

type Picker

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

Picker holds the runtime state for an open picker overlay

func LSPWorkspaceCommandPicker

func LSPWorkspaceCommandPicker(e *view.Editor) *Picker

LSPWorkspaceCommandPicker opens commands exposed by language servers

func NewChangedFilePicker

func NewChangedFilePicker(e *view.Editor) *Picker

NewChangedFilePicker lists workspace files the version-control system reports as changed

func NewPicker

func NewPicker(e *view.Editor, source PickerSource) *Picker

NewPicker constructs a Picker for the given source, triggering Load immediately. The returned feedCmd (if any) must be dispatched by the caller after mounting the component

func (*Picker) MatchCount

func (p *Picker) MatchCount() int

MatchCount reports how many items currently match the query

func (*Picker) SelectIndex

func (p *Picker) SelectIndex(i int)

SelectIndex moves the cursor to i when it is a valid match index

type PickerAcceptAction

type PickerAcceptAction int
const (
	PickerAcceptReplace PickerAcceptAction = iota
	PickerAcceptHorizontalSplit
	PickerAcceptVerticalSplit
)

type PickerBase

type PickerBase struct {
	Ident       string
	Label       string
	Cols        []string
	MatchCol    int
	Proportions []int
}

PickerBase is an optional starting point a source can embed for default id, title, column, and fuzzy-match behavior; a source is free to implement those methods itself instead

func (PickerBase) ColumnProportions

func (p PickerBase) ColumnProportions() []int

ColumnProportions are the relative widths of the columns

func (PickerBase) Columns

func (p PickerBase) Columns() []string

Columns are the picker's column headings

func (PickerBase) ID

func (p PickerBase) ID() string

ID is the picker's identifier, used to restore the last picker

func (PickerBase) MatchColumn

func (p PickerBase) MatchColumn() int

MatchColumn is the column the filter query matches against

func (PickerBase) PrepareMatcher added in v0.1.19

func (p PickerBase) PrepareMatcher(query string) PickerMatcher

PrepareMatcher prepares a query for matching multiple items

func (PickerBase) Title added in v0.1.41

func (p PickerBase) Title() string

Title is the picker's display title, drawn in the frame's top border

type PickerComponent

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

PickerComponent renders and handles an interactive picker

func (*PickerComponent) Cursor

func (p *PickerComponent) Cursor(
	cx *Context, _ geom.Size,
) (cur tea.Cursor, ok bool)

Cursor returns the caret position within the filter input

func (*PickerComponent) HandleEvent

func (p *PickerComponent) HandleEvent(
	cx *Context, msg tea.Msg,
) (EventResult, tea.Cmd)

HandleEvent drives filtering, selection, and acceptance

func (*PickerComponent) Layout

func (p *PickerComponent) Layout(
	cx *Context, screen geom.Size,
) (geom.Area, bool)

Layout centres the picker, sizing the preview to the space left

func (*PickerComponent) PaintBuffer

func (p *PickerComponent) PaintBuffer(cx *Context, pl geom.Area) *tui.Buffer

PaintBuffer draws the picker list, its input, and any preview

type PickerFunc

type PickerFunc func(e *view.Editor) *Picker

PickerFunc constructs a Picker from the editor

type PickerIgnore

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

func LoadIgnoreFiles

func LoadIgnoreFiles(
	target IgnoreTarget, opts PickerIgnoreOptions,
) []PickerIgnore

LoadIgnoreFiles collects .ignore, .toe/ignore, and .gitignore rules that apply to path, nearest directory last

type PickerIgnoreOptions

type PickerIgnoreOptions struct {
	Hidden      bool
	Parents     bool
	IgnoreFiles bool
}

func DefaultPickerIgnoreOptions

func DefaultPickerIgnoreOptions() PickerIgnoreOptions

DefaultPickerIgnoreOptions is the ignore behavior file-walking pickers use when a caller does not need to customize it

type PickerItem

type PickerItem struct {
	Display     string
	Columns     []string
	StyleScopes []string
	SecFrom     int
	SortKey     string

	Group     int
	Section   bool
	Directory bool

	Preview  PreviewRenderer
	Location PickerLocation
	Payload  any

	DiffHunks   []view.DiffHunk
	DiffPreview bool
	DiffKind    view.FileChangeKind
	BasePath    string
}

PickerItem is a single row shown in the picker list. A Section row labels the group its Group ordinal names; it never matches a query and the cursor skips it

type PickerItemSlab added in v0.1.38

type PickerItemSlab = core.Slab[PickerItem]

PickerItemSlab is a Slab specialized for PickerItem

type PickerLayoutOptions

type PickerLayoutOptions struct {
	SplitRatios map[string]float64 `toml:"split"`
	Scales      map[string]float64 `toml:"scales"`
}

PickerLayoutOptions holds the per-overlay list/preview split ratios and size scales, keyed by picker or prompt id

func (PickerLayoutOptions) SplitRatioFor

func (o PickerLayoutOptions) SplitRatioFor(key string) float64

SplitRatioFor returns the saved split ratio for a picker key

type PickerLoad added in v0.2.0

type PickerLoad struct {
	Items []*PickerItem
	Feed  <-chan *PickerItem
	Stop  StopFunc
}

PickerLoad is what a source returns from Load: the rows known up front, an optional channel of rows discovered asynchronously, and the cancel for that feed

type PickerLocation

type PickerLocation struct {
	Target PickerTarget
	Lines  *core.Span
}

PickerLocation holds a target and an optional line range

type PickerMatcher added in v0.1.19

type PickerMatcher func(*PickerItem) (MatchResult, bool)

PickerMatcher matches picker items against a prepared query

type PickerPreviewSkipper

type PickerPreviewSkipper interface {
	SkipPreview()
}

PickerPreviewSkipper marks picker sources that never render previews

type PickerSource

type PickerSource interface {
	ID() string
	Title() string
	Columns() []string
	MatchColumn() int
	ColumnProportions() []int
	Load(*view.Editor) PickerLoad
	Accept(*view.Editor, *PickerItem, PickerAcceptAction)
}

PickerSource is implemented by every picker data source

type PickerTarget

type PickerTarget struct {
	Path string
	ID   view.DocumentId
}

PickerTarget identifies a document by path or in-memory ID

func (PickerTarget) Valid

func (p PickerTarget) Valid() bool

Valid reports whether the target refers to a real document or path

type PreviewRenderer

type PreviewRenderer func(geom.Size) string

PreviewRenderer renders a picker item's preview at the given size

type PromptComponent

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

PromptComponent renders and handles an interactive prompt

func (*PromptComponent) Cursor

func (p *PromptComponent) Cursor(
	cx *Context, _ geom.Size,
) (cur tea.Cursor, ok bool)

Cursor returns the caret position within the input line

func (*PromptComponent) HandleEvent

func (p *PromptComponent) HandleEvent(
	cx *Context, msg tea.Msg,
) (EventResult, tea.Cmd)

HandleEvent drives editing, history, and completion of the input line

func (*PromptComponent) Layout

func (p *PromptComponent) Layout(
	cx *Context, screen geom.Size,
) (geom.Area, bool)

Layout claims a centered popup over the frame

func (*PromptComponent) PaintBuffer

func (p *PromptComponent) PaintBuffer(cx *Context, pl geom.Area) *tui.Buffer

PaintBuffer draws the prompt popup, its input line and its completions

type SkipPickerPathArgs

type SkipPickerPathArgs struct {
	Rel     string
	Path    string
	Entry   os.DirEntry
	Ignores []PickerIgnore
	Opts    PickerIgnoreOptions
}

SkipPickerPathArgs holds the entry a picker file-walk is considering and the ignore state to test it against

type SnapshotPickerSource added in v0.1.36

type SnapshotPickerSource interface {
	PickerSource
	Items(e *view.Editor) []*PickerItem
}

SnapshotPickerSource returns its whole row set synchronously, so a refresh can replace the list without a visible rebuild

type StaticPickerSource

type StaticPickerSource interface {
	PickerSource
	PrepareMatcher(query string) PickerMatcher
}

StaticPickerSource extends PickerSource with fuzzy-match filtering

type StopFunc

type StopFunc func()

StopFunc cancels an in-progress feed or search

type TerminalPane

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

TerminalPane is a view.Pane backed by a real PTY and a VT100/xterm emulator, so full-screen programs (editors, pagers, TUIs) render correctly

func NewTerminalPane

func NewTerminalPane(
	e *view.Editor, shell string, size geom.Size,
) (*TerminalPane, error)

NewTerminalPane spawns shell in a PTY and pumps its output into a VT emulator sized w by h

func NewTerminalPaneInDir

func NewTerminalPaneInDir(
	e *view.Editor, args TerminalPaneArgs,
) (*TerminalPane, error)

NewTerminalPaneInDir spawns the shell in the given directory

func (*TerminalPane) Area

func (t *TerminalPane) Area() geom.Area

Area returns the screen rectangle assigned by the layout engine

func (*TerminalPane) BeginDrag

func (t *TerminalPane) BeginDrag(
	cx *Context, at geom.Point, mod tea.KeyMod,
) bool

BeginDrag starts a selection if the shell hasn't grabbed mouse tracking, or forwards the click to it otherwise

func (*TerminalPane) CancelDrag

func (t *TerminalPane) CancelDrag()

CancelDrag stops any pending auto-scroll tick, without side effects

func (*TerminalPane) Closed

func (t *TerminalPane) Closed() <-chan struct{}

Closed delivers a signal once the shell process has exited

func (*TerminalPane) ConsumeBell

func (t *TerminalPane) ConsumeBell(focused bool) bool

ConsumeBell reports whether the bell has rung since it was last consumed. A rung bell only clears when read while focused, so it stays visible in the status line until the pane is actually looked at

func (*TerminalPane) ConsumeDirty

func (t *TerminalPane) ConsumeDirty() bool

ConsumeDirty reports whether the pane has changed since the last call, clearing the flag

func (*TerminalPane) ConsumeNotifications added in v0.3.2

func (t *TerminalPane) ConsumeNotifications() []string

ConsumeNotifications returns the desktop notifications the shell has requested since the last call, clearing them

func (*TerminalPane) ContinueDrag

func (t *TerminalPane) ContinueDrag(cx *Context, at geom.Point) tea.Cmd

ContinueDrag extends the selection to (x, y), auto-scrolling and scheduling further ticks if the drag has crossed the pane's top or bottom edge

func (*TerminalPane) Cursor

func (t *TerminalPane) Cursor(cx *Context) (tea.Cursor, bool)

Cursor reports the shell's cursor position, translated to screen space

func (*TerminalPane) Discard

func (t *TerminalPane) Discard()

Discard terminates this terminal when its slot is vacated without reverting

func (*TerminalPane) DragTick

func (t *TerminalPane) DragTick(_ *Context, gen int, toLow bool) tea.Cmd

DragTick continues scrolling toward toLow if gen still matches the scheduling tick, or is a no-op if a newer drag has since superseded it

func (*TerminalPane) Emulator

func (t *TerminalPane) Emulator() *vt.SafeEmulator

Emulator returns the underlying VT emulator for rendering and input

func (*TerminalPane) EndDrag

func (t *TerminalPane) EndDrag(cx *Context, at geom.Point) tea.Cmd

EndDrag finalizes the selection at (x, y), copying it to the clipboard

func (*TerminalPane) HandleEvent

func (t *TerminalPane) HandleEvent(
	cx *Context, msg tea.Msg,
) (EventResult, bool)

HandleEvent routes key and mouse events to the shell

func (*TerminalPane) HoldResize added in v0.2.4

func (t *TerminalPane) HoldResize()

HoldResize defers PTY resizing until TerminalPane.ResumeResize, since a shell redraws its prompt on every SIGWINCH, and a storm of them leaves multi-line prompts stacked up the scrollback

func (*TerminalPane) ID

func (t *TerminalPane) ID() view.Id

ID returns the pane identifier

func (*TerminalPane) IngestOutput

func (t *TerminalPane) IngestOutput(data []byte)

IngestOutput applies a chunk of output as if it had just been read from the PTY, letting tests simulate shell output without a real child process

func (*TerminalPane) MarkDirty

func (t *TerminalPane) MarkDirty()

MarkDirty flags the pane as needing a repaint on the next frame

func (*TerminalPane) Mode

func (t *TerminalPane) Mode() view.Mode

Mode reports view.ModeTerminal, since a terminal pane has no insert/select/normal distinction

func (*TerminalPane) MouseEnabled

func (t *TerminalPane) MouseEnabled() bool

MouseEnabled reports whether the program running in the shell has requested mouse tracking (e.g. vim, htop, tmux)

func (*TerminalPane) Paste

func (t *TerminalPane) Paste(text string)

Paste sends text to the shell, bracketing it with paste-mode escapes if the running program requested bracketed paste

func (*TerminalPane) Path

func (t *TerminalPane) Path() string

Path returns the shell working directory most recently reported by OSC 7

func (*TerminalPane) ResumeResize added in v0.2.4

func (t *TerminalPane) ResumeResize()

ResumeResize re-enables PTY resizing, pushing the size the pane reached while held

func (*TerminalPane) SaveSession

func (t *TerminalPane) SaveSession(w *view.SessionWriter)

SaveSession stores a terminal slot so a fresh shell can be reopened

func (*TerminalPane) ScrollLines

func (t *TerminalPane) ScrollLines(n int)

ScrollLines moves the view n lines back into scrollback (n < 0 moves toward live output); a no-op while the alt screen is active

func (*TerminalPane) ScrollOffset

func (t *TerminalPane) ScrollOffset() int

ScrollOffset returns the number of lines scrolled back from live output

func (*TerminalPane) ScrollToBottom

func (t *TerminalPane) ScrollToBottom()

ScrollToBottom returns the view to live output

func (*TerminalPane) SearchScrollback

func (t *TerminalPane) SearchScrollback(pattern string) bool

SearchScrollback jumps to the nearest line above the current view containing pattern (case-insensitive), reporting whether one was found

func (*TerminalPane) SendKey

func (t *TerminalPane) SendKey(k uv.KeyEvent)

SendKey forwards a key event to the shell. Printable text bypasses vt's encoder, which silently drops runes whose Mod is non-zero (e.g. shifted). Any keypress returns the view to live output, like a real terminal

func (*TerminalPane) SendMouse

func (t *TerminalPane) SendMouse(m uv.MouseEvent)

SendMouse forwards a mouse event to the shell

func (*TerminalPane) SetArea

func (t *TerminalPane) SetArea(a geom.Area)

SetArea updates the pane's screen rectangle and resizes the PTY and emulator to match, reflowing the shell, unless resizing is held

func (*TerminalPane) SetID

func (t *TerminalPane) SetID(id view.Id)

SetID sets the pane identifier (called by the tree on insertion)

func (*TerminalPane) SetRedraw added in v0.1.10

func (t *TerminalPane) SetRedraw(fn func())

SetRedraw installs the hook the shell calls to wake the render loop when it mutates the pane off the event loop; the tree wires it on insertion

func (*TerminalPane) Shutdown

func (t *TerminalPane) Shutdown()

Shutdown terminates this terminal, releasing its PTY

func (*TerminalPane) Split

func (t *TerminalPane) Split() (view.Pane, error)

Split starts another terminal using the same shell

func (*TerminalPane) Stop

func (t *TerminalPane) Stop() error

Stop terminates the shell process and releases the PTY

func (*TerminalPane) Title

func (t *TerminalPane) Title() string

Title returns the terminal title most recently set by the shell or the program running in it (OSC 0/2), or "" if none has been set yet

type TerminalPaneArgs added in v0.2.0

type TerminalPaneArgs struct {
	Shell string
	Dir   string
	Size  geom.Size
}

TerminalPaneArgs names the shell to spawn and the directory to run it in

Source Files

Jump to

Keyboard shortcuts

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