Documentation
¶
Overview ¶
Package tui provides pi's differential terminal renderer and components.
Index ¶
- Constants
- Variables
- func AllocateImageID() uint32
- func ApplyBackgroundToLine(line string, width int, background StyleFunc) string
- func CalculateImageRows(image ImageDimensions, targetWidthCells int, cell CellDimensions) int
- func DecodeKittyPrintable(data string) string
- func DecodePrintableKey(data string) string
- func DeleteAllKittyImages() string
- func DeleteKittyImage(imageID uint32) string
- func EncodeITerm2(base64Data string, width, height any, name string, ...) string
- func EncodeKitty(base64Data string, columns, rows int, imageID uint32, moveCursor bool) string
- func FindWordBackward(text string, cursor int) int
- func FindWordForward(text string, cursor int) int
- func FuzzyFilter[T any](items []T, query string, getText func(T) string) []T
- func Hyperlink(text, url string) string
- func ImageFallback(mimeType string, dimensions *ImageDimensions, filename string) string
- func IsImageLine(line string) bool
- func IsKeyRelease(data string) bool
- func IsKeyRepeat(data string) bool
- func IsKittyProtocolActive() bool
- func IsMouseReport(data string) bool
- func IsOsc11BackgroundColorResponse(data string) bool
- func MatchesKey(data string, keyID KeyID) bool
- func NormalizeAppleTerminalInput(data string, appleTerminal, shiftPressed bool) string
- func NormalizeTerminalOutput(text string) string
- func ParseKey(data string) string
- func ResetCapabilitiesCache()
- func SetCapabilities(capabilities TerminalCapabilities)
- func SetCellDimensions(dimensions CellDimensions)
- func SetKeybindings(manager *KeybindingsManager)
- func SetKittyProtocolActive(active bool)
- func SliceByColumn(line string, startCol, length int, strict bool) string
- func TruncateToWidth(text string, maxWidth int, ellipsis string, pad bool) string
- func VisibleWidth(text string) int
- func WrapTextWithANSI(text string, width int) []string
- type AutocompleteItem
- type AutocompleteProvider
- type AutocompleteSuggestions
- type Box
- type CancellableLoader
- type CellDimensions
- type CombinedAutocompleteProvider
- func (provider *CombinedAutocompleteProvider) ApplyCompletion(lines []string, cursorLine, cursorCol int, item AutocompleteItem, ...) CompletionResult
- func (provider *CombinedAutocompleteProvider) GetSuggestions(ctx context.Context, lines []string, cursorLine, cursorCol int, force bool) *AutocompleteSuggestions
- func (provider *CombinedAutocompleteProvider) ShouldTriggerFileCompletion(lines []string, cursorLine, cursorCol int) bool
- type CompletionResult
- type Component
- type Container
- func (container *Container) AddChild(component Component)
- func (container *Container) ChildChanged(component Component)
- func (container *Container) Children() []Component
- func (container *Container) Clear()
- func (container *Container) EndsWith(components ...Component) bool
- func (container *Container) Invalidate()
- func (container *Container) LineCount(width int) int
- func (container *Container) RemoveChild(component Component)
- func (container *Container) Render(width int) []string
- func (container *Container) RenderLines(width, start, end int) []string
- type DefaultTextStyle
- type Editor
- func (editor *Editor) AddToHistory(text string)
- func (editor *Editor) GetAutocompleteMaxVisible() int
- func (editor *Editor) GetBorderColor() StyleFunc
- func (editor *Editor) GetCursor() (line, col int)
- func (editor *Editor) GetExpandedText() string
- func (editor *Editor) GetLines() []string
- func (editor *Editor) GetPaddingX() int
- func (editor *Editor) GetText() string
- func (editor *Editor) HandleInput(event KeyEvent)
- func (editor *Editor) HandleMouse(event MouseEvent) bool
- func (editor *Editor) HasHiddenLinesAbove(width int) bool
- func (editor *Editor) InsertTextAtCursor(text string)
- func (editor *Editor) Invalidate()
- func (editor *Editor) IsShowingAutocomplete() bool
- func (editor *Editor) Render(width int) []string
- func (editor *Editor) SetAutocompleteMaxVisible(maxVisible int)
- func (editor *Editor) SetAutocompleteProvider(provider AutocompleteProvider)
- func (editor *Editor) SetBorderColor(color StyleFunc)
- func (editor *Editor) SetFocused(focused bool)
- func (editor *Editor) SetPaddingX(padding int)
- func (editor *Editor) SetText(text string)
- type EditorTheme
- type FileCompletionGate
- type Focusable
- type FuzzyMatch
- type Image
- type ImageCellSize
- type ImageDimensions
- type ImageOptions
- type ImageProtocol
- type ImageRenderOptions
- type ImageRenderResult
- type ImageTheme
- type Input
- type InputHandler
- type InputListener
- type InputListenerResult
- type Invalidatable
- type KeyEvent
- type KeyEventType
- type KeyID
- type KeyReleaseConsumer
- type KeybindingConflict
- type KeybindingDefinition
- type KeybindingsConfig
- type KeybindingsManager
- func GetKeybindings() *KeybindingsManager
- func NewDefaultKeybindings(user KeybindingsConfig) *KeybindingsManager
- func NewKeybindingsFromFile(definitions []KeybindingDefinition, path string) *KeybindingsManager
- func NewKeybindingsManager(definitions []KeybindingDefinition, user KeybindingsConfig) *KeybindingsManager
- func (manager *KeybindingsManager) Conflicts() []KeybindingConflict
- func (manager *KeybindingsManager) Definition(id string) (KeybindingDefinition, bool)
- func (manager *KeybindingsManager) Keys(id string) []KeyID
- func (manager *KeybindingsManager) Matches(data, id string) bool
- func (manager *KeybindingsManager) Reload()
- func (manager *KeybindingsManager) ResolvedBindings() KeybindingsConfig
- func (manager *KeybindingsManager) SetUserBindings(user KeybindingsConfig)
- func (manager *KeybindingsManager) UserBindings() KeybindingsConfig
- type KeyboardProtocolNegotiation
- type LineSegments
- type Loader
- type LoaderIndicatorOptions
- type Markdown
- type MarkdownOptions
- type MarkdownTheme
- type MouseEvent
- type MouseEventType
- type MouseHandler
- type OverlayAnchor
- type OverlayHandle
- type OverlayLayout
- type OverlayMargin
- type OverlayOptions
- type OverlayUnfocusOptions
- type ProcessTerminal
- func (terminal *ProcessTerminal) ClearFromCursor()
- func (terminal *ProcessTerminal) ClearLine()
- func (terminal *ProcessTerminal) ClearScreen()
- func (terminal *ProcessTerminal) Columns() int
- func (terminal *ProcessTerminal) DrainInput(maxDuration, idleDuration time.Duration)
- func (terminal *ProcessTerminal) HideCursor()
- func (terminal *ProcessTerminal) KittyProtocolActive() bool
- func (terminal *ProcessTerminal) MoveBy(lines int)
- func (terminal *ProcessTerminal) Rows() int
- func (terminal *ProcessTerminal) Run(onInput func(string), onResize func(), body func()) (err error)
- func (terminal *ProcessTerminal) SetProgress(active bool)
- func (terminal *ProcessTerminal) SetTitle(title string)
- func (terminal *ProcessTerminal) ShowCursor()
- func (terminal *ProcessTerminal) Start(onInput func(string), onResize func()) error
- func (terminal *ProcessTerminal) Stop() error
- func (terminal *ProcessTerminal) Write(data string)
- type RenderRequester
- type RgbColor
- type SelectItem
- type SelectList
- func (list *SelectList) GetSelectedItem() (SelectItem, bool)
- func (list *SelectList) HandleInput(event KeyEvent)
- func (list *SelectList) HandleMouse(event MouseEvent) bool
- func (list *SelectList) Invalidate()
- func (list *SelectList) Render(width int) []string
- func (list *SelectList) SetFilter(filter string)
- func (list *SelectList) SetSelectedIndex(index int)
- type SelectListLayoutOptions
- type SelectListTheme
- type SelectListTruncatePrimaryContext
- type SettingItem
- type SettingsList
- type SettingsListOptions
- type SettingsListTheme
- type SettingsStyleFunc
- type SizeValue
- type SlashCommand
- type Spacer
- type StdinBuffer
- type StyleFunc
- type TUI
- func (ui *TUI) AddInputListener(listener InputListener) func()
- func (ui *TUI) ClearOnShrink() bool
- func (ui *TUI) ForceRender()
- func (ui *TUI) FullRedraws() int
- func (ui *TUI) HasOverlay() bool
- func (ui *TUI) HideOverlay()
- func (ui *TUI) Invalidate()
- func (ui *TUI) OnTerminalColorSchemeChange(listener func(TerminalColorScheme)) func()
- func (ui *TUI) QueryTerminalBackgroundColor(timeout time.Duration) <-chan *RgbColor
- func (ui *TUI) QueryTerminalColorScheme(timeout time.Duration) <-chan TerminalColorScheme
- func (ui *TUI) RenderNow()
- func (ui *TUI) RequestRender()
- func (ui *TUI) SetClearOnShrink(enabled bool)
- func (ui *TUI) SetFocus(component Component)
- func (ui *TUI) SetSelectionHandler(handler func(string))
- func (ui *TUI) SetShowHardwareCursor(enabled bool)
- func (ui *TUI) SetTerminalColorSchemeNotifications(enabled bool)
- func (ui *TUI) SetViewport(body, chrome Component)
- func (ui *TUI) ShowHardwareCursor() bool
- func (ui *TUI) ShowOverlay(component Component, options ...OverlayOptions) OverlayHandle
- func (ui *TUI) Start() error
- func (ui *TUI) Stop() error
- func (ui *TUI) Terminal() Terminal
- type Terminal
- type TerminalCapabilities
- type TerminalColorScheme
- type Text
- type TextChunk
- type TriggerCharacterProvider
- type TruncatedText
- type VisualTruncateResult
Constants ¶
const CursorMarker = "\x1b_pi:c\x07"
CursorMarker is a zero-width APC sequence. Focused text components place it at their logical cursor so the renderer can position the hardware cursor for IME candidate windows without displaying it.
Variables ¶
var TUIKeybindingDefinitions = []KeybindingDefinition{ {ID: "tui.editor.cursorUp", DefaultKeys: []KeyID{"up"}, Description: "Move cursor up"}, {ID: "tui.editor.cursorDown", DefaultKeys: []KeyID{"down"}, Description: "Move cursor down"}, {ID: "tui.editor.cursorLeft", DefaultKeys: []KeyID{"left", "ctrl+b"}, Description: "Move cursor left"}, {ID: "tui.editor.cursorRight", DefaultKeys: []KeyID{"right", "ctrl+f"}, Description: "Move cursor right"}, {ID: "tui.editor.cursorWordLeft", DefaultKeys: []KeyID{"alt+left", "ctrl+left", "alt+b"}, Description: "Move cursor word left"}, {ID: "tui.editor.cursorWordRight", DefaultKeys: []KeyID{"alt+right", "ctrl+right", "alt+f"}, Description: "Move cursor word right"}, {ID: "tui.editor.cursorLineStart", DefaultKeys: []KeyID{"home", "ctrl+a"}, Description: "Move to line start"}, {ID: "tui.editor.cursorLineEnd", DefaultKeys: []KeyID{"end", "ctrl+e"}, Description: "Move to line end"}, {ID: "tui.editor.jumpForward", DefaultKeys: []KeyID{"ctrl+]"}, Description: "Jump forward to character"}, {ID: "tui.editor.jumpBackward", DefaultKeys: []KeyID{"ctrl+alt+]"}, Description: "Jump backward to character"}, {ID: "tui.editor.pageUp", DefaultKeys: []KeyID{"pageUp"}, Description: "Page up"}, {ID: "tui.editor.pageDown", DefaultKeys: []KeyID{"pageDown"}, Description: "Page down"}, {ID: "tui.editor.deleteCharBackward", DefaultKeys: []KeyID{"backspace"}, Description: "Delete character backward"}, {ID: "tui.editor.deleteCharForward", DefaultKeys: []KeyID{"delete", "ctrl+d"}, Description: "Delete character forward"}, {ID: "tui.editor.deleteWordBackward", DefaultKeys: []KeyID{"ctrl+w", "alt+backspace"}, Description: "Delete word backward"}, {ID: "tui.editor.deleteWordForward", DefaultKeys: []KeyID{"alt+d", "alt+delete"}, Description: "Delete word forward"}, {ID: "tui.editor.deleteToLineStart", DefaultKeys: []KeyID{"ctrl+u"}, Description: "Delete to line start"}, {ID: "tui.editor.deleteToLineEnd", DefaultKeys: []KeyID{"ctrl+k"}, Description: "Delete to line end"}, {ID: "tui.editor.yank", DefaultKeys: []KeyID{"ctrl+y"}, Description: "Yank"}, {ID: "tui.editor.yankPop", DefaultKeys: []KeyID{"alt+y"}, Description: "Yank pop"}, {ID: "tui.editor.undo", DefaultKeys: []KeyID{"ctrl+-"}, Description: "Undo"}, {ID: "tui.input.newLine", DefaultKeys: []KeyID{"shift+enter", "ctrl+j"}, Description: "Insert newline"}, {ID: "tui.input.submit", DefaultKeys: []KeyID{"enter"}, Description: "Submit input"}, {ID: "tui.input.tab", DefaultKeys: []KeyID{"tab"}, Description: "Tab / autocomplete"}, {ID: "tui.input.copy", DefaultKeys: []KeyID{"ctrl+c"}, Description: "Copy selection"}, {ID: "tui.select.up", DefaultKeys: []KeyID{"up"}, Description: "Move selection up"}, {ID: "tui.select.down", DefaultKeys: []KeyID{"down"}, Description: "Move selection down"}, {ID: "tui.select.pageUp", DefaultKeys: []KeyID{"pageUp"}, Description: "Selection page up"}, {ID: "tui.select.pageDown", DefaultKeys: []KeyID{"pageDown"}, Description: "Selection page down"}, {ID: "tui.select.confirm", DefaultKeys: []KeyID{"enter"}, Description: "Confirm selection"}, {ID: "tui.select.cancel", DefaultKeys: []KeyID{"escape", "ctrl+c"}, Description: "Cancel selection"}, }
Functions ¶
func AllocateImageID ¶
func AllocateImageID() uint32
func ApplyBackgroundToLine ¶
ApplyBackgroundToLine pads a line before applying its background callback.
func CalculateImageRows ¶
func CalculateImageRows(image ImageDimensions, targetWidthCells int, cell CellDimensions) int
func DecodeKittyPrintable ¶
DecodeKittyPrintable decodes unmodified or Shift-only CSI-u input.
func DecodePrintableKey ¶
func DeleteAllKittyImages ¶
func DeleteAllKittyImages() string
func DeleteKittyImage ¶
func EncodeITerm2 ¶
func EncodeKitty ¶
func FindWordBackward ¶
FindWordBackward exposes upstream's UTF-16-indexed default word movement.
func FindWordForward ¶
FindWordForward exposes upstream's UTF-16-indexed default word movement.
func FuzzyFilter ¶
FuzzyFilter filters and sorts items by fuzzy match quality (best first). Whitespace- and slash-separated query tokens must all match.
func Hyperlink ¶
Hyperlink wraps text in an OSC 8 hyperlink escape sequence. In terminals without hyperlink support the escape codes are ignored and only the plain text is displayed.
func ImageFallback ¶
func ImageFallback(mimeType string, dimensions *ImageDimensions, filename string) string
func IsImageLine ¶
func IsKeyRelease ¶
func IsKeyRepeat ¶
func IsKittyProtocolActive ¶
func IsKittyProtocolActive() bool
func IsMouseReport ¶ added in v0.4.6
IsMouseReport matches every SGR mouse report, including the ones parseMouse rejects, so callers swallow them instead of leaking escape bytes as text.
func IsOsc11BackgroundColorResponse ¶
IsOsc11BackgroundColorResponse recognizes the strict OSC 11 reply frame, including payloads that do not contain a parseable color.
func MatchesKey ¶
MatchesKey checks one raw terminal sequence against a namespaced binding key.
func NormalizeTerminalOutput ¶
NormalizeTerminalOutput applies upstream's display-only Thai/Lao AM decomposition and expands visible tabs without changing terminal strings.
func ResetCapabilitiesCache ¶
func ResetCapabilitiesCache()
func SetCapabilities ¶
func SetCapabilities(capabilities TerminalCapabilities)
func SetCellDimensions ¶
func SetCellDimensions(dimensions CellDimensions)
func SetKeybindings ¶
func SetKeybindings(manager *KeybindingsManager)
func SetKittyProtocolActive ¶
func SetKittyProtocolActive(active bool)
func SliceByColumn ¶
SliceByColumn extracts a range of visible columns from a line. ANSI codes pending at the slice start are re-emitted before the first kept grapheme; strict excludes boundary wide chars that would extend past the range.
func TruncateToWidth ¶
TruncateToWidth keeps a contiguous grapheme prefix and brackets an ellipsis with resets so styles from truncated content cannot bleed into it.
func VisibleWidth ¶
VisibleWidth returns the number of terminal cells occupied by text. Tabs are fixed at three cells and the ANSI, OSC, and APC sequences upstream recognizes are zero-width.
func WrapTextWithANSI ¶
WrapTextWithANSI word-wraps while reopening active SGR and OSC-8 state on physical lines, matching upstream's line-isolated renderer contract.
Types ¶
type AutocompleteItem ¶
type AutocompleteProvider ¶
type AutocompleteProvider interface {
GetSuggestions(ctx context.Context, lines []string, cursorLine, cursorCol int, force bool) *AutocompleteSuggestions
ApplyCompletion(lines []string, cursorLine, cursorCol int, item AutocompleteItem, prefix string) CompletionResult
}
AutocompleteProvider supplies and applies completions. GetSuggestions runs off the input goroutine; ctx is cancelled when the request becomes stale. A nil result means no suggestions.
type AutocompleteSuggestions ¶
type AutocompleteSuggestions struct {
Items []AutocompleteItem
// Prefix is what the suggestions were matched against (e.g. "/" or "src/").
Prefix string
}
type Box ¶
type Box struct {
Children []Component
// contains filtered or unexported fields
}
Box applies horizontal and vertical padding and an optional background to child components.
func (*Box) Invalidate ¶
func (box *Box) Invalidate()
func (*Box) RemoveChild ¶
func (*Box) SetBackground ¶
type CancellableLoader ¶
type CancellableLoader struct {
*Loader
OnAbort func()
// contains filtered or unexported fields
}
CancellableLoader couples Loader with the standard select-cancel binding.
func NewCancellableLoader ¶
func NewCancellableLoader(ui RenderRequester, spinnerColor, messageColor StyleFunc, message string, indicator *LoaderIndicatorOptions) *CancellableLoader
func (*CancellableLoader) Aborted ¶
func (loader *CancellableLoader) Aborted() bool
func (*CancellableLoader) Context ¶
func (loader *CancellableLoader) Context() context.Context
func (*CancellableLoader) Dispose ¶
func (loader *CancellableLoader) Dispose()
func (*CancellableLoader) HandleInput ¶
func (loader *CancellableLoader) HandleInput(event KeyEvent)
type CellDimensions ¶
func GetCellDimensions ¶
func GetCellDimensions() CellDimensions
type CombinedAutocompleteProvider ¶
type CombinedAutocompleteProvider struct {
// contains filtered or unexported fields
}
CombinedAutocompleteProvider stacks slash-command, command-argument, "@" fuzzy-file, and path completion, mirroring upstream provider stacking.
func NewCombinedAutocompleteProvider ¶
func NewCombinedAutocompleteProvider(commands []SlashCommand, basePath, fdPath string) *CombinedAutocompleteProvider
func (*CombinedAutocompleteProvider) ApplyCompletion ¶
func (provider *CombinedAutocompleteProvider) ApplyCompletion(lines []string, cursorLine, cursorCol int, item AutocompleteItem, prefix string) CompletionResult
func (*CombinedAutocompleteProvider) GetSuggestions ¶
func (provider *CombinedAutocompleteProvider) GetSuggestions(ctx context.Context, lines []string, cursorLine, cursorCol int, force bool) *AutocompleteSuggestions
func (*CombinedAutocompleteProvider) ShouldTriggerFileCompletion ¶
func (provider *CombinedAutocompleteProvider) ShouldTriggerFileCompletion(lines []string, cursorLine, cursorCol int) bool
ShouldTriggerFileCompletion vetoes Tab file completion while typing a slash command name at line start.
type CompletionResult ¶
CompletionResult is the new editor text and cursor after a completion.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container renders child components vertically in insertion order.
func NewWindowedContainer ¶ added in v0.3.0
func NewWindowedContainer() *Container
NewWindowedContainer caches child layout so a viewport can render only its visible range. ChildChanged must be called after mutating an existing child.
func (*Container) ChildChanged ¶ added in v0.3.0
ChildChanged invalidates the aggregate layout after an existing child mutates.
func (*Container) EndsWith ¶
EndsWith safely exposes the suffix check needed by upstream components, whose TypeScript container children are directly observable.
func (*Container) Invalidate ¶
func (container *Container) Invalidate()
func (*Container) LineCount ¶ added in v0.3.0
LineCount returns the rendered height without flattening cached child lines.
func (*Container) RemoveChild ¶
func (*Container) RenderLines ¶ added in v0.3.0
RenderLines renders the half-open line range [start, end).
type DefaultTextStyle ¶
type Editor ¶
type Editor struct {
OnSubmit func(string)
OnChange func(string)
DisableSubmit bool
// InputInterceptor is called before default key handling. Return true to
// consume the event and suppress further processing.
InputInterceptor func(KeyEvent) bool
// contains filtered or unexported fields
}
Editor is the multi-line text editor: undo, kill ring, word navigation, paste collapse, prompt history, autocomplete.
func NewEditor ¶
func NewEditor(ui *TUI, theme EditorTheme) *Editor
func (*Editor) AddToHistory ¶
AddToHistory records a prompt for up/down navigation, skipping empties and consecutive duplicates, keeping at most 100 entries.
func (*Editor) GetAutocompleteMaxVisible ¶
func (*Editor) GetBorderColor ¶
func (*Editor) GetExpandedText ¶
GetExpandedText returns the text with paste markers expanded to their actual content (e.g. for an external editor).
func (*Editor) GetPaddingX ¶
func (*Editor) HandleInput ¶
func (*Editor) HandleMouse ¶ added in v0.4.6
func (editor *Editor) HandleMouse(event MouseEvent) bool
HandleMouse places the cursor on a clicked character and accepts a clicked autocomplete suggestion. Border rows and the wheel fall through so the transcript keeps them.
func (*Editor) HasHiddenLinesAbove ¶ added in v0.4.7
HasHiddenLinesAbove predicts whether the next render needs the top scroll border.
func (*Editor) InsertTextAtCursor ¶
InsertTextAtCursor inserts text at the cursor as one undoable unit.
func (*Editor) Invalidate ¶
func (editor *Editor) Invalidate()
func (*Editor) IsShowingAutocomplete ¶
func (*Editor) SetAutocompleteMaxVisible ¶
func (*Editor) SetAutocompleteProvider ¶
func (editor *Editor) SetAutocompleteProvider(provider AutocompleteProvider)
func (*Editor) SetBorderColor ¶
func (*Editor) SetFocused ¶
func (*Editor) SetPaddingX ¶
type EditorTheme ¶
type EditorTheme struct {
BorderColor StyleFunc
SelectList SelectListTheme
}
type FileCompletionGate ¶
type FileCompletionGate interface {
ShouldTriggerFileCompletion(lines []string, cursorLine, cursorCol int) bool
}
FileCompletionGate optionally vetoes explicit-Tab file completion.
type Focusable ¶
type Focusable interface {
Component
InputHandler
SetFocused(bool)
}
Focusable receives input and exposes focus state for cursor-marker emission.
type FuzzyMatch ¶
FuzzyMatch reports whether all query characters appear in order in text. Lower score = better match.
func FuzzyMatchScore ¶
func FuzzyMatchScore(query, text string) FuzzyMatch
FuzzyMatchScore mirrors upstream fuzzyMatch, including the swapped alpha-numeric fallback (e.g. "o1" also tries "1o").
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
func NewImage ¶
func NewImage(base64Data, mimeType string, theme ImageTheme, options *ImageOptions, dimensions *ImageDimensions) *Image
func (*Image) GetImageID ¶
func (*Image) Invalidate ¶
func (image *Image) Invalidate()
type ImageCellSize ¶
func CalculateImageCellSize ¶
func CalculateImageCellSize(image ImageDimensions, maxWidthCells int, maxHeightCells *int, cell CellDimensions) ImageCellSize
type ImageDimensions ¶
func GetGIFDimensions ¶
func GetGIFDimensions(data string) *ImageDimensions
func GetImageDimensions ¶
func GetImageDimensions(data, mimeType string) *ImageDimensions
func GetJPEGDimensions ¶
func GetJPEGDimensions(data string) *ImageDimensions
func GetPNGDimensions ¶
func GetPNGDimensions(data string) *ImageDimensions
func GetWebPDimensions ¶
func GetWebPDimensions(data string) *ImageDimensions
type ImageOptions ¶
type ImageProtocol ¶
type ImageProtocol string
const ( ImageProtocolKitty ImageProtocol = "kitty" ImageProtocolITerm2 ImageProtocol = "iterm2" )
type ImageRenderOptions ¶
type ImageRenderResult ¶
func RenderImage ¶
func RenderImage(data string, dimensions ImageDimensions, options ImageRenderOptions) *ImageRenderResult
type ImageTheme ¶
type ImageTheme struct {
FallbackColor StyleFunc
}
type Input ¶
type Input struct {
OnSubmit func(string)
OnEscape func()
// contains filtered or unexported fields
}
Input is a single-line text input with horizontal scrolling. The cursor is a rune index into the value.
func (*Input) HandleInput ¶
func (*Input) Invalidate ¶
func (input *Input) Invalidate()
func (*Input) SetFocused ¶
type InputHandler ¶
type InputHandler interface {
HandleInput(KeyEvent)
}
InputHandler receives input while its component has focus.
type InputListener ¶
type InputListener func(string) InputListenerResult
type InputListenerResult ¶
type Invalidatable ¶
type Invalidatable interface {
Invalidate()
}
Invalidatable clears render state derived from theme or size changes.
type KeyEvent ¶
type KeyEvent struct {
Raw string
Key string
Type KeyEventType
}
KeyEvent is one terminal input sequence after protocol-aware parsing.
type KeyEventType ¶
type KeyEventType string
const ( KeyPress KeyEventType = "press" KeyRepeat KeyEventType = "repeat" KeyRelease KeyEventType = "release" )
func KeyEventTypeOf ¶
func KeyEventTypeOf(data string) KeyEventType
type KeyReleaseConsumer ¶
type KeyReleaseConsumer interface {
WantsKeyRelease() bool
}
KeyReleaseConsumer opts into Kitty key-release events, which are otherwise filtered before dispatch just as upstream does.
type KeybindingConflict ¶
type KeybindingDefinition ¶
type KeybindingsConfig ¶
func LoadKeybindingsFile ¶
func LoadKeybindingsFile(path string) KeybindingsConfig
LoadKeybindingsFile mirrors upstream's forgiving keybindings.json parser: absent, malformed, and non-object files all resolve to an empty override.
type KeybindingsManager ¶
type KeybindingsManager struct {
// contains filtered or unexported fields
}
func GetKeybindings ¶
func GetKeybindings() *KeybindingsManager
func NewDefaultKeybindings ¶
func NewDefaultKeybindings(user KeybindingsConfig) *KeybindingsManager
func NewKeybindingsFromFile ¶
func NewKeybindingsFromFile(definitions []KeybindingDefinition, path string) *KeybindingsManager
func NewKeybindingsManager ¶
func NewKeybindingsManager(definitions []KeybindingDefinition, user KeybindingsConfig) *KeybindingsManager
func (*KeybindingsManager) Conflicts ¶
func (manager *KeybindingsManager) Conflicts() []KeybindingConflict
func (*KeybindingsManager) Definition ¶
func (manager *KeybindingsManager) Definition(id string) (KeybindingDefinition, bool)
func (*KeybindingsManager) Keys ¶
func (manager *KeybindingsManager) Keys(id string) []KeyID
func (*KeybindingsManager) Matches ¶
func (manager *KeybindingsManager) Matches(data, id string) bool
func (*KeybindingsManager) Reload ¶
func (manager *KeybindingsManager) Reload()
func (*KeybindingsManager) ResolvedBindings ¶
func (manager *KeybindingsManager) ResolvedBindings() KeybindingsConfig
func (*KeybindingsManager) SetUserBindings ¶
func (manager *KeybindingsManager) SetUserBindings(user KeybindingsConfig)
func (*KeybindingsManager) UserBindings ¶
func (manager *KeybindingsManager) UserBindings() KeybindingsConfig
type KeyboardProtocolNegotiation ¶
func ParseKeyboardProtocolNegotiation ¶
func ParseKeyboardProtocolNegotiation(sequence string) (KeyboardProtocolNegotiation, bool)
type LineSegments ¶
LineSegments is the before/after result used by overlay composition.
func ExtractSegments ¶
func ExtractSegments(line string, beforeEnd, afterStart, afterLength int, strictAfter bool) LineSegments
ExtractSegments extracts styled visible columns on each side of an overlay.
type Loader ¶
type Loader struct {
*Text
// contains filtered or unexported fields
}
Loader is an optional animated indicator followed by a message.
func NewLoader ¶
func NewLoader(ui RenderRequester, spinnerColor, messageColor StyleFunc, message string, indicator *LoaderIndicatorOptions) *Loader
func (*Loader) SetIndicator ¶
func (loader *Loader) SetIndicator(indicator *LoaderIndicatorOptions)
func (*Loader) SetMessage ¶
type LoaderIndicatorOptions ¶
type Markdown ¶
type Markdown struct {
// contains filtered or unexported fields
}
func NewMarkdown ¶
func NewMarkdown(text string, paddingX, paddingY int, theme MarkdownTheme, defaultStyle *DefaultTextStyle, options *MarkdownOptions) *Markdown
func (*Markdown) Invalidate ¶
func (markdown *Markdown) Invalidate()
type MarkdownOptions ¶
type MarkdownTheme ¶
type MarkdownTheme struct {
Heading StyleFunc
Link StyleFunc
LinkURL StyleFunc
Code StyleFunc
CodeBlock StyleFunc
CodeBlockBorder StyleFunc
Quote StyleFunc
QuoteBorder StyleFunc
HorizontalRule StyleFunc
ListBullet StyleFunc
Bold StyleFunc
Italic StyleFunc
Strikethrough StyleFunc
Underline StyleFunc
HighlightCode func(code, language string) []string
CodeBlockIndent string
}
type MouseEvent ¶ added in v0.4.6
type MouseEvent struct {
Type MouseEventType
Button int // 0 left, 1 middle, 2 right
Row int
Column int
Shift bool
Alt bool
Ctrl bool
// Clicks is 2 for a second press on the same cell within
// doubleClickInterval. It is only set on MousePress.
Clicks int
}
MouseEvent is one decoded SGR mouse report. Row and Column are zero-based and, once dispatched, local to the receiving component.
type MouseEventType ¶ added in v0.4.6
type MouseEventType uint8
MouseEventType is the gesture an SGR mouse report describes.
const ( MousePress MouseEventType = iota MouseRelease MouseDrag MouseWheelUp MouseWheelDown )
type MouseHandler ¶ added in v0.4.6
type MouseHandler interface {
// HandleMouse reports whether the event was consumed.
HandleMouse(MouseEvent) bool
}
MouseHandler is the optional capability a component advertises to receive mouse input. It is discovered by type assertion so the Component contract stays Render-only and every existing component and extension UI keeps working untouched.
type OverlayAnchor ¶
type OverlayAnchor string
OverlayAnchor positions an overlay within the terminal's available area.
const ( OverlayCenter OverlayAnchor = "center" OverlayTopLeft OverlayAnchor = "top-left" OverlayTopRight OverlayAnchor = "top-right" OverlayBottomLeft OverlayAnchor = "bottom-left" OverlayBottomRight OverlayAnchor = "bottom-right" OverlayTopCenter OverlayAnchor = "top-center" OverlayBottomCenter OverlayAnchor = "bottom-center" OverlayLeftCenter OverlayAnchor = "left-center" OverlayRightCenter OverlayAnchor = "right-center" )
type OverlayHandle ¶
type OverlayHandle interface {
Hide()
SetHidden(bool)
IsHidden() bool
Focus()
Unfocus(...OverlayUnfocusOptions)
IsFocused() bool
}
OverlayHandle controls one overlay after it has been shown.
type OverlayLayout ¶
type OverlayLayout struct {
Width, MinWidth, MaxHeight int
Anchor string
OffsetX, OffsetY int
Row, Column *int
Margin *OverlayMargin
Visible func(width, height int) bool
NonCapturing bool
}
OverlayLayout preserves the existing Go extension adapter while the public TUI surface follows upstream's OverlayOptions. The callback is evaluated on every render so dynamic extension layouts remain responsive.
type OverlayMargin ¶
OverlayMargin reserves terminal cells around an overlay. Negative values are accepted here and clamped to zero during layout, as upstream does.
func UniformOverlayMargin ¶
func UniformOverlayMargin(value int) *OverlayMargin
UniformOverlayMargin returns the number form of upstream's margin option.
type OverlayOptions ¶
type OverlayOptions struct {
Width SizeValue
MinWidth int
MaxHeight SizeValue
Anchor OverlayAnchor
OffsetX int
OffsetY int
Row SizeValue
Col SizeValue
Margin *OverlayMargin
Visible func(termWidth, termHeight int) bool
NonCapturing bool
}
OverlayOptions controls overlay sizing, placement, visibility, and focus capture.
type OverlayUnfocusOptions ¶
type OverlayUnfocusOptions struct {
Target Component
}
OverlayUnfocusOptions selects an explicit focus target, including nil.
type ProcessTerminal ¶
type ProcessTerminal struct {
// contains filtered or unexported fields
}
ProcessTerminal owns raw-mode and protocol state for a pair of terminal files. NewProcessTerminal uses the process standard streams.
func NewProcessTerminal ¶
func NewProcessTerminal() *ProcessTerminal
func NewProcessTerminalFiles ¶
func NewProcessTerminalFiles(input, output *os.File) *ProcessTerminal
func (*ProcessTerminal) ClearFromCursor ¶
func (terminal *ProcessTerminal) ClearFromCursor()
func (*ProcessTerminal) ClearLine ¶
func (terminal *ProcessTerminal) ClearLine()
func (*ProcessTerminal) ClearScreen ¶
func (terminal *ProcessTerminal) ClearScreen()
func (*ProcessTerminal) Columns ¶
func (terminal *ProcessTerminal) Columns() int
func (*ProcessTerminal) DrainInput ¶
func (terminal *ProcessTerminal) DrainInput(maxDuration, idleDuration time.Duration)
func (*ProcessTerminal) HideCursor ¶
func (terminal *ProcessTerminal) HideCursor()
func (*ProcessTerminal) KittyProtocolActive ¶
func (terminal *ProcessTerminal) KittyProtocolActive() bool
func (*ProcessTerminal) MoveBy ¶
func (terminal *ProcessTerminal) MoveBy(lines int)
func (*ProcessTerminal) Rows ¶
func (terminal *ProcessTerminal) Rows() int
func (*ProcessTerminal) Run ¶
func (terminal *ProcessTerminal) Run(onInput func(string), onResize func(), body func()) (err error)
Run restores terminal state even when body panics, then propagates the panic.
func (*ProcessTerminal) SetProgress ¶
func (terminal *ProcessTerminal) SetProgress(active bool)
func (*ProcessTerminal) SetTitle ¶
func (terminal *ProcessTerminal) SetTitle(title string)
func (*ProcessTerminal) ShowCursor ¶
func (terminal *ProcessTerminal) ShowCursor()
func (*ProcessTerminal) Start ¶
func (terminal *ProcessTerminal) Start(onInput func(string), onResize func()) error
func (*ProcessTerminal) Stop ¶
func (terminal *ProcessTerminal) Stop() error
func (*ProcessTerminal) Write ¶
func (terminal *ProcessTerminal) Write(data string)
type RenderRequester ¶
type RenderRequester interface {
RequestRender()
}
RenderRequester is the narrow seam animated components need from TUI.
type RgbColor ¶
RgbColor is an 8-bit terminal color parsed from an OSC 11 response.
func ParseOsc11BackgroundColor ¶
ParseOsc11BackgroundColor parses #RRGGBB, #RRRRGGGGBBBB, rgb:, and rgba: responses, scaling arbitrary hexadecimal channel widths to 8-bit values.
type SelectItem ¶
type SelectList ¶
type SelectList struct {
OnSelect func(SelectItem)
OnCancel func()
OnSelectionChange func(SelectItem)
// contains filtered or unexported fields
}
SelectList renders a scrolling picker with optional description column.
func NewSelectList ¶
func NewSelectList(items []SelectItem, maxVisible int, theme SelectListTheme, layout SelectListLayoutOptions) *SelectList
func (*SelectList) GetSelectedItem ¶
func (list *SelectList) GetSelectedItem() (SelectItem, bool)
GetSelectedItem returns the highlighted item, or false when none.
func (*SelectList) HandleInput ¶
func (list *SelectList) HandleInput(event KeyEvent)
func (*SelectList) HandleMouse ¶ added in v0.4.6
func (list *SelectList) HandleMouse(event MouseEvent) bool
HandleMouse selects the clicked row and confirms on a double click. The scroll-info line below the items is not clickable.
func (*SelectList) Invalidate ¶
func (list *SelectList) Invalidate()
func (*SelectList) Render ¶
func (list *SelectList) Render(width int) []string
func (*SelectList) SetFilter ¶
func (list *SelectList) SetFilter(filter string)
SetFilter keeps items whose value starts with filter (case-insensitive) and resets the selection.
func (*SelectList) SetSelectedIndex ¶
func (list *SelectList) SetSelectedIndex(index int)
type SelectListLayoutOptions ¶
type SelectListLayoutOptions struct {
MinPrimaryColumnWidth int
MaxPrimaryColumnWidth int
TruncatePrimary func(SelectListTruncatePrimaryContext) string
}
SelectListLayoutOptions tunes the primary column; zero values mean unset.
type SelectListTheme ¶
type SelectListTruncatePrimaryContext ¶
type SelectListTruncatePrimaryContext struct {
Text string
MaxWidth int
ColumnWidth int
Item SelectItem
IsSelected bool
}
type SettingItem ¶
type SettingItem struct {
// ID uniquely identifies the setting.
ID string
// Label is the display text (left side).
Label string
// Description is shown when the item is selected.
Description string
// CurrentValue is displayed on the right side.
CurrentValue string
// Values, when set, are cycled through by Enter/Space.
Values []string
// and a done callback; done(nil) cancels and done(&value) selects.
Submenu func(currentValue string, done func(selected *string)) Component
}
type SettingsList ¶
type SettingsList struct {
// contains filtered or unexported fields
}
SettingsList renders label/value rows with cycling values, submenus, and optional fuzzy search.
func NewSettingsList ¶
func NewSettingsList(items []SettingItem, maxVisible int, theme SettingsListTheme, onChange func(id, newValue string), onCancel func(), options SettingsListOptions) *SettingsList
func (*SettingsList) HandleInput ¶
func (list *SettingsList) HandleInput(event KeyEvent)
func (*SettingsList) HandleMouse ¶ added in v0.4.6
func (list *SettingsList) HandleMouse(event MouseEvent) bool
HandleMouse selects the clicked setting and cycles its value on a double click, matching Enter/Space. An open submenu keeps the mouse, as it keeps keyboard input.
func (*SettingsList) Invalidate ¶
func (list *SettingsList) Invalidate()
func (*SettingsList) Render ¶
func (list *SettingsList) Render(width int) []string
func (*SettingsList) UpdateValue ¶
func (list *SettingsList) UpdateValue(id, newValue string)
UpdateValue updates an item's current value.
type SettingsListOptions ¶
type SettingsListOptions struct {
EnableSearch bool
}
type SettingsListTheme ¶
type SettingsListTheme struct {
Label SettingsStyleFunc
Value SettingsStyleFunc
Description StyleFunc
Cursor string
Hint StyleFunc
}
type SettingsStyleFunc ¶
SettingsStyleFunc styles text differently for the selected row.
type SizeValue ¶
type SizeValue struct {
// contains filtered or unexported fields
}
SizeValue is either an absolute terminal-cell value or a percentage. The zero value means that the corresponding overlay option is unset.
func AbsoluteSize ¶
AbsoluteSize creates an absolute overlay size or position.
func PercentSize ¶
PercentSize creates a percentage overlay size or position, where 50 means 50%.
type SlashCommand ¶
type SlashCommand struct {
Name string
Description string
ArgumentHint string
// GetArgumentCompletions returns completions for the command's argument
// text, or nil when unavailable.
GetArgumentCompletions func(argumentPrefix string) []AutocompleteItem
}
SlashCommand describes a command offered by slash completion.
type Spacer ¶
type Spacer struct {
// contains filtered or unexported fields
}
Spacer renders a configurable number of empty rows.
func (*Spacer) Invalidate ¶
func (spacer *Spacer) Invalidate()
type StdinBuffer ¶
type StdinBuffer struct {
// contains filtered or unexported fields
}
StdinBuffer turns arbitrarily chunked terminal bytes into individual escape sequences and bracketed-paste payloads.
func NewStdinBuffer ¶
func NewStdinBuffer(timeout time.Duration, onData, onPaste func(string)) *StdinBuffer
func (*StdinBuffer) Buffered ¶
func (buffer *StdinBuffer) Buffered() string
func (*StdinBuffer) Clear ¶
func (buffer *StdinBuffer) Clear()
func (*StdinBuffer) Close ¶
func (buffer *StdinBuffer) Close()
func (*StdinBuffer) Flush ¶
func (buffer *StdinBuffer) Flush() []string
func (*StdinBuffer) Process ¶
func (buffer *StdinBuffer) Process(data string)
func (*StdinBuffer) ProcessBytes ¶
func (buffer *StdinBuffer) ProcessBytes(data []byte)
ProcessBytes preserves upstream's Buffer input compatibility: a single high byte is decoded as the legacy meta-key form ESC + (byte - 128).
type TUI ¶
type TUI struct {
Container
OnDebug func()
// contains filtered or unexported fields
}
TUI owns focus and performs synchronized line-level differential rendering.
func (*TUI) AddInputListener ¶
func (ui *TUI) AddInputListener(listener InputListener) func()
func (*TUI) ClearOnShrink ¶
func (*TUI) ForceRender ¶
func (ui *TUI) ForceRender()
func (*TUI) FullRedraws ¶
func (*TUI) HasOverlay ¶
HasOverlay reports whether at least one overlay is currently visible.
func (*TUI) HideOverlay ¶
func (ui *TUI) HideOverlay()
HideOverlay removes the most recently created overlay, independent of focus order.
func (*TUI) Invalidate ¶
func (ui *TUI) Invalidate()
func (*TUI) OnTerminalColorSchemeChange ¶
func (ui *TUI) OnTerminalColorSchemeChange(listener func(TerminalColorScheme)) func()
OnTerminalColorSchemeChange registers an insertion-ordered scheme listener.
func (*TUI) QueryTerminalBackgroundColor ¶
QueryTerminalBackgroundColor sends OSC 11 and returns a one-result channel. A nil result means timeout or a strict reply with an unparseable payload.
func (*TUI) QueryTerminalColorScheme ¶
func (ui *TUI) QueryTerminalColorScheme(timeout time.Duration) <-chan TerminalColorScheme
QueryTerminalColorScheme sends the DSR query and resolves from the same notification path used by persistent listeners. An empty result is timeout.
func (*TUI) RequestRender ¶
func (ui *TUI) RequestRender()
func (*TUI) SetClearOnShrink ¶
func (*TUI) SetSelectionHandler ¶ added in v0.3.3
func (*TUI) SetShowHardwareCursor ¶
func (*TUI) SetTerminalColorSchemeNotifications ¶
SetTerminalColorSchemeNotifications enables or disables CSI ? 2031 reports.
func (*TUI) SetViewport ¶ added in v0.3.0
SetViewport keeps chrome pinned below a scrollable body. It is opt-in so embedders retain upstream's inline renderer unless they explicitly own the screen.
func (*TUI) ShowHardwareCursor ¶
func (*TUI) ShowOverlay ¶
func (ui *TUI) ShowOverlay(component Component, options ...OverlayOptions) OverlayHandle
ShowOverlay adds an overlay and returns a permanent control handle. Omitting options applies upstream's centered, width-at-most-80 defaults.
type Terminal ¶
type Terminal interface {
Start(onInput func(string), onResize func()) error
Stop() error
DrainInput(maxDuration, idleDuration time.Duration)
Write(string)
Columns() int
Rows() int
KittyProtocolActive() bool
MoveBy(lines int)
HideCursor()
ShowCursor()
ClearLine()
ClearFromCursor()
ClearScreen()
SetTitle(string)
SetProgress(bool)
}
Terminal is the renderer's minimal terminal contract.
type TerminalCapabilities ¶
type TerminalCapabilities struct {
Images ImageProtocol
TrueColor bool
Hyperlinks bool
}
func DetectCapabilities ¶
func DetectCapabilities(tmuxForwardsHyperlink func() bool) TerminalCapabilities
func GetCapabilities ¶
func GetCapabilities() TerminalCapabilities
type TerminalColorScheme ¶
type TerminalColorScheme string
TerminalColorScheme is a terminal-reported dark or light preference.
const ( TerminalColorSchemeDark TerminalColorScheme = "dark" TerminalColorSchemeLight TerminalColorScheme = "light" )
func ParseTerminalColorSchemeReport ¶
func ParseTerminalColorSchemeReport(data string) (TerminalColorScheme, bool)
ParseTerminalColorSchemeReport parses CSI ? 997 ; 1/2 n reports.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text renders wrapped multi-line text with optional padding and background.
func (*Text) Invalidate ¶
func (text *Text) Invalidate()
func (*Text) SetBackground ¶
type TextChunk ¶
TextChunk is one upstream-compatible UTF-16-indexed wrapped segment.
func WordWrapLine ¶
WordWrapLine exposes upstream's default word-wrapping helper.
type TriggerCharacterProvider ¶
type TriggerCharacterProvider interface {
TriggerCharacters() []string
}
TriggerCharacterProvider optionally contributes extra characters that trigger completion at token boundaries (stacked onto the built-in "@"/"#").
type TruncatedText ¶
type TruncatedText struct {
// contains filtered or unexported fields
}
TruncatedText renders only the first logical line, padded to the viewport.
func NewTruncatedText ¶
func NewTruncatedText(text string, paddingX, paddingY int) *TruncatedText
func (*TruncatedText) Invalidate ¶
func (text *TruncatedText) Invalidate()
func (*TruncatedText) Render ¶
func (text *TruncatedText) Render(width int) []string
type VisualTruncateResult ¶
VisualTruncateResult contains the tail visual lines of wrapped text and the number of visual lines omitted before them.
func TruncateToVisualLines ¶
func TruncateToVisualLines(text string, maxVisualLines, width, paddingX int) VisualTruncateResult
TruncateToVisualLines renders text with Text's width and padding semantics, then retains the last maxVisualLines physical terminal rows.
Source Files
¶
- autocomplete.go
- box.go
- cancellable_loader.go
- component.go
- container.go
- doc.go
- editor.go
- fuzzy.go
- image.go
- input.go
- keybindings.go
- keys.go
- kill_ring.go
- loader.go
- markdown.go
- markdown_blocks.go
- markdown_inline.go
- markdown_table.go
- mouse.go
- overlay.go
- segment.go
- select_list.go
- settings_list.go
- spacer.go
- stdin_buffer.go
- terminal.go
- terminal_colors.go
- terminal_image.go
- terminal_unix.go
- text.go
- truncated_text.go
- tui.go
- undo_stack.go
- visual_truncate.go
- width.go
- word_navigation.go