gitui

package
v0.0.0-...-0af0894 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CursorMarker = "\x1b_pi:c\x07"
)

Variables

View Source
var Key = KeyHelper{
	Escape: "escape", Esc: "esc", Enter: "enter", Return: "return", Tab: "tab", Space: "space",
	Backspace: "backspace", Delete: "delete", Insert: "insert", Clear: "clear",
	Home: "home", End: "end", PageUp: "pageUp", PageDown: "pageDown", Up: "up", Down: "down", Left: "left", Right: "right",
	F1: "f1", F2: "f2", F3: "f3", F4: "f4", F5: "f5", F6: "f6", F7: "f7", F8: "f8", F9: "f9", F10: "f10", F11: "f11", F12: "f12",

	Backtick: "`", Hyphen: "-", Equals: "=", LeftBracket: "[", RightBracket: "]",
	Backslash: "\\", Semicolon: ";", Quote: "'", Comma: ",", Period: ".", Slash: "/",
	Exclamation: "!", At: "@", Hash: "#", Dollar: "$", Percent: "%", Caret: "^",
	Ampersand: "&", Asterisk: "*", LeftParen: "(", RightParen: ")",
	Underscore: "_", Plus: "+", Pipe: "|", Tilde: "~",
	LeftBrace: "{", RightBrace: "}", Colon: ":", LessThan: "<", GreaterThan: ">",
	Question: "?",
}
View Source
var TUI_KEYBINDINGS = cloneKeybindingDefinitions(defaultKeybindingDefinitions)

Functions

func AllocateImageID

func AllocateImageID() uint32

func ApplyBackgroundToLine

func ApplyBackgroundToLine(line string, width int, bgFn func(string) string) string

ApplyBackgroundToLine pads line to width and passes it through bgFn.

func CalculateImageRows

func CalculateImageRows(imageDimensions ImageDimensions, targetWidthCells int, cellDimensions ...CellDimensions) int

func DecodeKittyPrintable

func DecodeKittyPrintable(data string) (rune, bool)

func DecodePrintableKey

func DecodePrintableKey(data string) (rune, bool)

func DeleteAllKittyImages

func DeleteAllKittyImages() string

func DeleteKittyImage

func DeleteKittyImage(id uint32) string

func EncodeITerm2

func EncodeITerm2(data []byte, options ImageRenderOptions) string

func EncodeKitty

func EncodeKitty(data []byte, options ImageRenderOptions) string

func FuzzyFilter

func FuzzyFilter[T any](items []T, query string, getText func(T) string) []T

func FuzzyFilterStrings

func FuzzyFilterStrings(items []string, query string) []string
func Hyperlink(text, url string) string

func ImageFallback

func ImageFallback(alt string, args ...any) string

func ImageFallbackDescription

func ImageFallbackDescription(mimeType string, dimensions *ImageDimensions, filename string) string

func IsFocusable

func IsFocusable(component Component) bool

func IsImageLine

func IsImageLine(line string) bool

func IsKeyRelease

func IsKeyRelease(data string) bool

func IsKeyRepeat

func IsKeyRepeat(data string) bool

func IsKittyProtocolActive

func IsKittyProtocolActive() bool

func IsPunctuationChar

func IsPunctuationChar(char rune) bool

func IsWhitespaceChar

func IsWhitespaceChar(char rune) bool

func MatchesKey

func MatchesKey(data, spec string) bool

func NormalizeTerminalOutput

func NormalizeTerminalOutput(s string) string

NormalizeTerminalOutput rewrites codepoints that terminals commonly render as decomposed sequences. This keeps output width accounting aligned with what the terminal displays for Thai and Lao AM vowels.

func RenderImage

func RenderImage(data []byte, options ImageRenderOptions) string

func ResetCapabilitiesCache

func ResetCapabilitiesCache()

func SetCapabilities

func SetCapabilities(c TerminalCapabilities)

func SetCellDimensions

func SetCellDimensions(d CellDimensions)

func SetKeybindings

func SetKeybindings(manager *KeybindingsManager)

func SetKittyProtocolActive

func SetKittyProtocolActive(active bool)

func SliceByColumn

func SliceByColumn(line string, startCol, length int, strict ...bool) string

func TruncateToWidth

func TruncateToWidth(text string, maxWidth int, ellipsis string, pad ...bool) string

TruncateToWidth truncates text to maxWidth terminal cells. ANSI escapes are preserved when possible. The optional pad argument pads the result to maxWidth.

func VisibleWidth

func VisibleWidth(s string) int

VisibleWidth returns the number of terminal cells occupied by s. It strips ANSI escape sequences, treats tabs as three cells, and uses a conservative width table for combining marks, CJK, and emoji.

func WrapTextWithANSI

func WrapTextWithANSI(text string, width int) []string

WrapTextWithANSI wraps text into terminal-width lines while preserving ANSI sequences. Newlines always force a break.

Types

type ANSICode

type ANSICode struct {
	Code   string
	Length int
}

func ExtractAnsiCode

func ExtractAnsiCode(str string, pos int) (ANSICode, bool)

type AutocompleteItem

type AutocompleteItem struct {
	Value       string
	Label       string
	Description string
}

type AutocompleteProvider

type AutocompleteProvider interface {
	Suggestions(text string, cursor int) AutocompleteSuggestions
}

type AutocompleteProviderFunc

type AutocompleteProviderFunc func(text string, cursor int) AutocompleteSuggestions

func (AutocompleteProviderFunc) Suggestions

func (f AutocompleteProviderFunc) Suggestions(text string, cursor int) AutocompleteSuggestions

type AutocompleteSuggestions

type AutocompleteSuggestions struct {
	Items  []AutocompleteItem
	Start  int
	End    int
	Prefix string
}

type Box

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

func NewBox

func NewBox(paddingX, paddingY int, bgFn ...func(string) string) *Box

func (*Box) AddChild

func (b *Box) AddChild(component Component)

func (*Box) Clear

func (b *Box) Clear()

func (*Box) Invalidate

func (b *Box) Invalidate()

func (*Box) RemoveChild

func (b *Box) RemoveChild(component Component)

func (*Box) Render

func (b *Box) Render(width int) []string

func (*Box) SetBackground

func (b *Box) SetBackground(fn func(string) string)

func (*Box) SetBgFn

func (b *Box) SetBgFn(fn func(string) string)

type CancellableLoader

type CancellableLoader struct {
	*Loader

	OnCancel func()
	OnAbort  func()
	// contains filtered or unexported fields
}

func NewCancellableLoader

func NewCancellableLoader(text string, options ...LoaderIndicatorOptions) *CancellableLoader

func (*CancellableLoader) Aborted

func (l *CancellableLoader) Aborted() bool

func (*CancellableLoader) Cancel

func (l *CancellableLoader) Cancel()

func (*CancellableLoader) Cancelled

func (l *CancellableLoader) Cancelled() bool

func (*CancellableLoader) Context

func (l *CancellableLoader) Context() context.Context

func (*CancellableLoader) Dispose

func (l *CancellableLoader) Dispose()

func (*CancellableLoader) HandleInput

func (l *CancellableLoader) HandleInput(data string)

func (*CancellableLoader) Signal

func (l *CancellableLoader) Signal() context.Context

type CellDimensions

type CellDimensions struct {
	Width    int
	Height   int
	WidthPx  int
	HeightPx int
}

func GetCellDimensions

func GetCellDimensions() CellDimensions

type ColumnSlice

type ColumnSlice struct {
	Text  string
	Width int
}

func SliceWithWidth

func SliceWithWidth(line string, startCol, length int, strict ...bool) ColumnSlice

type CombinedAutocompleteProvider

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

func NewCombinedAutocompleteProvider

func NewCombinedAutocompleteProvider(providers ...AutocompleteProvider) *CombinedAutocompleteProvider

func NewCombinedAutocompleteProviderWithCommandItems

func NewCombinedAutocompleteProviderWithCommandItems(basePath string, commands []AutocompleteItem, providers ...AutocompleteProvider) *CombinedAutocompleteProvider

func NewCombinedAutocompleteProviderWithCommands

func NewCombinedAutocompleteProviderWithCommands(basePath string, commands []SlashCommand, providers ...AutocompleteProvider) *CombinedAutocompleteProvider

func (*CombinedAutocompleteProvider) Add

func (*CombinedAutocompleteProvider) ApplyCompletion

func (p *CombinedAutocompleteProvider) ApplyCompletion(lines []string, cursorLine, cursorCol int, item AutocompleteItem, prefix string) CompletionResult

func (*CombinedAutocompleteProvider) GetSuggestions

func (p *CombinedAutocompleteProvider) GetSuggestions(lines []string, cursorLine, cursorCol int, force bool) (*AutocompleteSuggestions, error)

func (*CombinedAutocompleteProvider) GetSuggestionsContext

func (p *CombinedAutocompleteProvider) GetSuggestionsContext(ctx context.Context, lines []string, cursorLine, cursorCol int, force bool) (*AutocompleteSuggestions, error)

func (*CombinedAutocompleteProvider) SetBasePath

func (p *CombinedAutocompleteProvider) SetBasePath(basePath string)

func (*CombinedAutocompleteProvider) SetCommandItems

func (p *CombinedAutocompleteProvider) SetCommandItems(commands []AutocompleteItem)

func (*CombinedAutocompleteProvider) SetCommands

func (p *CombinedAutocompleteProvider) SetCommands(commands []SlashCommand)

func (*CombinedAutocompleteProvider) ShouldTriggerFileCompletion

func (p *CombinedAutocompleteProvider) ShouldTriggerFileCompletion(lines []string, cursorLine, cursorCol int) bool

func (*CombinedAutocompleteProvider) Suggestions

func (p *CombinedAutocompleteProvider) Suggestions(text string, cursor int) AutocompleteSuggestions

type CompletionResult

type CompletionResult struct {
	Lines      []string
	CursorLine int
	CursorCol  int
}

type Component

type Component interface {
	Render(width int) []string
	Invalidate()
}

Component renders terminal lines for a viewport width.

type Container

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

func NewContainer

func NewContainer() *Container

func (*Container) AddChild

func (c *Container) AddChild(component Component)

func (*Container) ChildCount

func (c *Container) ChildCount() int

func (*Container) Children

func (c *Container) Children() []Component

func (*Container) Clear

func (c *Container) Clear()

func (*Container) InsertChild

func (c *Container) InsertChild(index int, component Component)

func (*Container) Invalidate

func (c *Container) Invalidate()

func (*Container) RemoveChild

func (c *Container) RemoveChild(component Component)

func (*Container) RemoveChildAt

func (c *Container) RemoveChildAt(index int) Component

func (*Container) Render

func (c *Container) Render(width int) []string

func (*Container) RenderWithSize

func (c *Container) RenderWithSize(width, height int) []string

func (*Container) SetChildren

func (c *Container) SetChildren(children []Component)

type DefaultTextStyle

type DefaultTextStyle struct {
	Color         func(string) string
	BgColor       func(string) string
	Bold          bool
	Italic        bool
	Strikethrough bool
	Underline     bool
}

type Editor

type Editor struct {
	FocusState

	OnSubmit             func(string)
	OnChange             func(string)
	OnAutocompleteChange func()
	DisableSubmit        bool
	// contains filtered or unexported fields
}

func NewEditor

func NewEditor(theme EditorTheme, options ...EditorOptions) *Editor

func (*Editor) AddToHistory

func (e *Editor) AddToHistory(text string)

func (*Editor) GetAutocompleteMaxVisible

func (e *Editor) GetAutocompleteMaxVisible() int

func (*Editor) GetCursor

func (e *Editor) GetCursor() (line, col int)

func (*Editor) GetExpandedText

func (e *Editor) GetExpandedText() string

func (*Editor) GetLines

func (e *Editor) GetLines() []string

func (*Editor) GetMaxVisibleLines

func (e *Editor) GetMaxVisibleLines() int

func (*Editor) GetPaddingX

func (e *Editor) GetPaddingX() int

func (*Editor) GetText

func (e *Editor) GetText() string

func (*Editor) HandleInput

func (e *Editor) HandleInput(data string)

func (*Editor) InsertTextAtCursor

func (e *Editor) InsertTextAtCursor(text string)

func (*Editor) Invalidate

func (e *Editor) Invalidate()

func (*Editor) IsShowingAutocomplete

func (e *Editor) IsShowingAutocomplete() bool

func (*Editor) PasteToEditor

func (e *Editor) PasteToEditor(text string)

func (*Editor) Render

func (e *Editor) Render(width int) []string

func (*Editor) RenderWithSize

func (e *Editor) RenderWithSize(width, height int) []string

func (*Editor) SetAutocompleteMaxVisible

func (e *Editor) SetAutocompleteMaxVisible(maxVisible int)

func (*Editor) SetAutocompleteProvider

func (e *Editor) SetAutocompleteProvider(provider AutocompleteProvider)

func (*Editor) SetBorderColor

func (e *Editor) SetBorderColor(fn func(string) string)

func (*Editor) SetMaxVisibleLines

func (e *Editor) SetMaxVisibleLines(lines int)

func (*Editor) SetOnChange

func (e *Editor) SetOnChange(fn func(string))

func (*Editor) SetOnSubmit

func (e *Editor) SetOnSubmit(fn func(string))

func (*Editor) SetPaddingX

func (e *Editor) SetPaddingX(padding int)

func (*Editor) SetText

func (e *Editor) SetText(text string)

func (*Editor) Text

func (e *Editor) Text() string

type EditorAppearanceComponent

type EditorAppearanceComponent interface {
	SetPaddingX(padding int)
	SetAutocompleteMaxVisible(maxVisible int)
	SetBorderColor(fn func(string) string)
}

type EditorAutocompleteComponent

type EditorAutocompleteComponent interface {
	SetAutocompleteProvider(provider AutocompleteProvider)
}

type EditorChangeCallbackComponent

type EditorChangeCallbackComponent interface {
	SetOnChange(fn func(string))
}

type EditorComponent

type EditorComponent interface {
	Component
	GetText() string
	SetText(text string)
	HandleInput(data string)
}

EditorComponent is the core contract for editor-like input widgets. Optional Pi editor capabilities are modeled as small extension interfaces below so custom Go editors can implement only the features they support.

type EditorExpandedTextProvider

type EditorExpandedTextProvider interface {
	GetExpandedText() string
}

type EditorHistoryComponent

type EditorHistoryComponent interface {
	AddToHistory(text string)
}

type EditorOptions

type EditorOptions struct {
	PaddingX               int
	AutocompleteMaxVisible int
	AutocompleteDebounce   time.Duration
	MaxVisibleLines        int
}

type EditorSubmitCallbackComponent

type EditorSubmitCallbackComponent interface {
	SetOnSubmit(fn func(string))
}

type EditorTextInserter

type EditorTextInserter interface {
	InsertTextAtCursor(text string)
}

type EditorTheme

type EditorTheme struct {
	Border     func(string) string
	SelectList SelectListTheme
}

type ExtractedSegments

type ExtractedSegments struct {
	Before      string
	BeforeWidth int
	After       string
	AfterWidth  int
}

func ExtractSegments

func ExtractSegments(line string, beforeEnd, afterStart, afterLen int, strictAfter ...bool) ExtractedSegments

type FocusState

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

FocusState can be embedded by focusable components.

func (*FocusState) Focused

func (f *FocusState) Focused() bool

func (*FocusState) SetFocused

func (f *FocusState) SetFocused(focused bool)

type Focusable

type Focusable interface {
	SetFocused(focused bool)
	Focused() bool
}

Focusable is implemented by components that need cursor/focus state.

type FuzzyMatch

type FuzzyMatch struct {
	Matches bool
	Score   float64
}

func FuzzyMatchText

func FuzzyMatchText(query, text string) FuzzyMatch

type Image

type Image struct {
	Data    []byte
	Options ImageOptions
	Theme   ImageTheme
	// contains filtered or unexported fields
}

func NewImage

func NewImage(data []byte, options ImageOptions, theme ...ImageTheme) *Image

func (*Image) GetImageID

func (i *Image) GetImageID() uint32

func (*Image) GetImageId

func (i *Image) GetImageId() uint32

func (*Image) ImageID

func (i *Image) ImageID() uint32

func (*Image) Invalidate

func (i *Image) Invalidate()

func (*Image) Render

func (i *Image) Render(width int) []string

type ImageCellSize

type ImageCellSize struct {
	Columns int
	Rows    int
}

func CalculateImageCellSize

func CalculateImageCellSize(imageDimensions ImageDimensions, maxWidthCells int, args ...any) ImageCellSize

type ImageDimensions

type ImageDimensions struct {
	Width    int
	Height   int
	WidthPx  int
	HeightPx int
}

func GetGifDimensions

func GetGifDimensions(data []byte) (ImageDimensions, error)

func GetImageDimensions

func GetImageDimensions(data []byte) (ImageDimensions, error)

func GetJpegDimensions

func GetJpegDimensions(data []byte) (ImageDimensions, error)

func GetPngDimensions

func GetPngDimensions(data []byte) (ImageDimensions, error)

func GetWebpDimensions

func GetWebpDimensions(data []byte) (ImageDimensions, error)

type ImageOptions

type ImageOptions struct {
	Alt            string
	MimeType       string
	Filename       string
	MaxWidth       int
	MaxHeight      int
	MaxWidthCells  int
	MaxHeightCells int
	ImageID        uint32
	ImageId        uint32
	Dimensions     *ImageDimensions
}

type ImageProtocol

type ImageProtocol string
const (
	ImageProtocolNone  ImageProtocol = "none"
	ImageProtocolKitty ImageProtocol = "kitty"
	ImageProtocolITerm ImageProtocol = "iterm2"
)

type ImageRenderOptions

type ImageRenderOptions struct {
	ID                    uint32
	ImageID               uint32
	ImageId               uint32
	Width                 int
	Height                int
	MaxWidthCells         int
	MaxHeightCells        int
	HeightAuto            bool
	Alt                   string
	Protocol              ImageProtocol
	DisableCursorMovement bool
	MoveCursor            *bool
	Inline                *bool
	PreserveAspectRatio   *bool
}

type ImageRenderResult

type ImageRenderResult struct {
	Sequence string
	Rows     int
	ImageID  uint32
	ImageId  uint32
}

func RenderImageWithDimensions

func RenderImageWithDimensions(data []byte, imageDimensions ImageDimensions, options ImageRenderOptions) *ImageRenderResult

type ImageTheme

type ImageTheme struct {
	Fallback      func(string) string
	FallbackColor func(string) string
}

type Input

type Input struct {
	FocusState

	OnSubmit func(string)
	OnEscape func()
	OnChange func(string)
	// contains filtered or unexported fields
}

func NewInput

func NewInput(placeholder ...string) *Input

func (*Input) GetValue

func (i *Input) GetValue() string

func (*Input) HandleInput

func (i *Input) HandleInput(data string)

func (*Input) Invalidate

func (i *Input) Invalidate()

func (*Input) Render

func (i *Input) Render(width int) []string

func (*Input) SetText

func (i *Input) SetText(text string)

func (*Input) SetValue

func (i *Input) SetValue(text string)

func (*Input) Text

func (i *Input) Text() string

type InputHandler

type InputHandler interface {
	HandleInput(data string)
}

InputHandler is implemented by components that receive focused keyboard input.

type InputListener

type InputListener func(data string) InputListenerResult

type InputListenerResult

type InputListenerResult struct {
	Consume bool
	Data    string
	HasData bool
}

func InputListenerData

func InputListenerData(data string) InputListenerResult

type KeyEvent

type KeyEvent struct {
	Key     KeyID
	Rune    rune
	Ctrl    bool
	Alt     bool
	Shift   bool
	Super   bool
	Type    KeyEventType
	Raw     string
	Unknown bool
}

func ParseKey

func ParseKey(data string) KeyEvent

type KeyEventType

type KeyEventType string
const (
	KeyPress   KeyEventType = "press"
	KeyRepeat  KeyEventType = "repeat"
	KeyRelease KeyEventType = "release"
)

type KeyHelper

type KeyHelper struct {
	Escape, Esc, Enter, Return, Tab, Space             string
	Backspace, Delete, Insert, Clear                   string
	Home, End, PageUp, PageDown, Up, Down, Left, Right string
	F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12  string

	Backtick, Hyphen, Equals, LeftBracket, RightBracket string
	Backslash, Semicolon, Quote, Comma, Period, Slash   string
	Exclamation, At, Hash, Dollar, Percent, Caret       string
	Ampersand, Asterisk, LeftParen, RightParen          string
	Underscore, Plus, Pipe, Tilde                       string
	LeftBrace, RightBrace, Colon, LessThan, GreaterThan string
	Question                                            string
}

func (KeyHelper) Alt

func (KeyHelper) Alt(key string) string

func (KeyHelper) AltCtrl

func (KeyHelper) AltCtrl(key string) string

func (KeyHelper) AltShift

func (KeyHelper) AltShift(key string) string

func (KeyHelper) AltSuper

func (KeyHelper) AltSuper(key string) string

func (KeyHelper) Ctrl

func (KeyHelper) Ctrl(key string) string

func (KeyHelper) CtrlAlt

func (KeyHelper) CtrlAlt(key string) string

func (KeyHelper) CtrlShift

func (KeyHelper) CtrlShift(key string) string

func (KeyHelper) CtrlShiftAlt

func (KeyHelper) CtrlShiftAlt(key string) string

func (KeyHelper) CtrlShiftSuper

func (KeyHelper) CtrlShiftSuper(key string) string

func (KeyHelper) CtrlSuper

func (KeyHelper) CtrlSuper(key string) string

func (KeyHelper) Shift

func (KeyHelper) Shift(key string) string

func (KeyHelper) ShiftAlt

func (KeyHelper) ShiftAlt(key string) string

func (KeyHelper) ShiftCtrl

func (KeyHelper) ShiftCtrl(key string) string

func (KeyHelper) ShiftSuper

func (KeyHelper) ShiftSuper(key string) string

func (KeyHelper) Super

func (KeyHelper) Super(key string) string

func (KeyHelper) SuperAlt

func (KeyHelper) SuperAlt(key string) string

func (KeyHelper) SuperCtrl

func (KeyHelper) SuperCtrl(key string) string

func (KeyHelper) SuperShift

func (KeyHelper) SuperShift(key string) string

type KeyID

type KeyID string
const (
	KeyUp        KeyID = "up"
	KeyDown      KeyID = "down"
	KeyLeft      KeyID = "left"
	KeyRight     KeyID = "right"
	KeyEnter     KeyID = "enter"
	KeyEscape    KeyID = "escape"
	KeyTab       KeyID = "tab"
	KeyBacktab   KeyID = "shift+tab"
	KeyBackspace KeyID = "backspace"
	KeyDelete    KeyID = "delete"
	KeyHome      KeyID = "home"
	KeyEnd       KeyID = "end"
)

type KeyReleaseReceiver

type KeyReleaseReceiver interface {
	WantsKeyRelease() bool
}

type Keybinding

type Keybinding struct {
	ID          string
	Description string
	Keys        []string
}

type KeybindingConflict

type KeybindingConflict struct {
	Key         string
	Actions     []string
	Keybindings []string
}

type KeybindingDefinition

type KeybindingDefinition struct {
	Description string
	Default     []string
}

type KeybindingDefinitions

type KeybindingDefinitions map[string]KeybindingDefinition

type Keybindings

type Keybindings map[string]Keybinding

type KeybindingsConfig

type KeybindingsConfig map[string][]string

type KeybindingsManager

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

func GetKeybindings

func GetKeybindings() *KeybindingsManager

func NewKeybindingsManager

func NewKeybindingsManager(config ...KeybindingsConfig) *KeybindingsManager

func NewKeybindingsManagerWithDefinitions

func NewKeybindingsManagerWithDefinitions(definitions KeybindingDefinitions, userBindings ...KeybindingsConfig) *KeybindingsManager

func (*KeybindingsManager) Bindings

func (m *KeybindingsManager) Bindings() Keybindings

func (*KeybindingsManager) Conflicts

func (m *KeybindingsManager) Conflicts() []KeybindingConflict

func (*KeybindingsManager) Definition

func (m *KeybindingsManager) Definition(action string) (KeybindingDefinition, bool)

func (*KeybindingsManager) GetConflicts

func (m *KeybindingsManager) GetConflicts() []KeybindingConflict

func (*KeybindingsManager) GetDefinition

func (m *KeybindingsManager) GetDefinition(action string) (KeybindingDefinition, bool)

func (*KeybindingsManager) GetKeys

func (m *KeybindingsManager) GetKeys(action string) []string

func (*KeybindingsManager) GetResolvedBindings

func (m *KeybindingsManager) GetResolvedBindings() KeybindingsConfig

func (*KeybindingsManager) GetUserBindings

func (m *KeybindingsManager) GetUserBindings() KeybindingsConfig

func (*KeybindingsManager) Keys

func (m *KeybindingsManager) Keys(action string) []string

func (*KeybindingsManager) Matches

func (m *KeybindingsManager) Matches(data, action string) bool

func (*KeybindingsManager) Set

func (m *KeybindingsManager) Set(action string, keys []string)

func (*KeybindingsManager) SetUserBindings

func (m *KeybindingsManager) SetUserBindings(config KeybindingsConfig)

func (*KeybindingsManager) UserBindings

func (m *KeybindingsManager) UserBindings() KeybindingsConfig

type KillRing

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

KillRing stores Emacs-style kill/yank entries.

Consecutive kills can be accumulated into the newest entry. Backward deletions prepend killed text while forward deletions append it.

func NewKillRing

func NewKillRing() *KillRing

func (*KillRing) Len

func (k *KillRing) Len() int

func (*KillRing) Length

func (k *KillRing) Length() int

func (*KillRing) Peek

func (k *KillRing) Peek() (string, bool)

func (*KillRing) Push

func (k *KillRing) Push(text string, opts KillRingPushOptions)

func (*KillRing) Rotate

func (k *KillRing) Rotate()

type KillRingPushOptions

type KillRingPushOptions struct {
	Prepend    bool
	Accumulate bool
}

type Loader

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

func NewLoader

func NewLoader(text string, options ...LoaderIndicatorOptions) *Loader

func (*Loader) Invalidate

func (l *Loader) Invalidate()

func (*Loader) Render

func (l *Loader) Render(width int) []string

func (*Loader) SetIndicator

func (l *Loader) SetIndicator(options LoaderIndicatorOptions)

func (*Loader) SetMessage

func (l *Loader) SetMessage(message string)

func (*Loader) SetTUI

func (l *Loader) SetTUI(ui *TUI)

func (*Loader) SetText

func (l *Loader) SetText(text string)

func (*Loader) Start

func (l *Loader) Start()

func (*Loader) Stop

func (l *Loader) Stop()

type LoaderIndicatorOptions

type LoaderIndicatorOptions struct {
	Frames                  []string
	Interval                time.Duration
	IntervalMs              int
	TUI                     *TUI
	SpinnerColor            func(string) string
	MessageColor            func(string) string
	RenderIndicatorVerbatim bool
}

type Markdown

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

func NewMarkdown

func NewMarkdown(text string, theme ...MarkdownTheme) *Markdown

func NewMarkdownWithOptions

func NewMarkdownWithOptions(text string, options MarkdownOptions) *Markdown

func (*Markdown) Invalidate

func (m *Markdown) Invalidate()

func (*Markdown) Render

func (m *Markdown) Render(width int) []string

func (*Markdown) SetText

func (m *Markdown) SetText(text string)

type MarkdownOptions

type MarkdownOptions struct {
	Theme            MarkdownTheme
	PaddingX         int
	PaddingY         int
	DefaultTextStyle *DefaultTextStyle
}

type MarkdownTheme

type MarkdownTheme struct {
	Text            func(string) string
	Heading         func(string) string
	Link            func(string) string
	LinkURL         func(string) string
	Code            func(string) string
	CodeBlock       func(string) string
	CodeBlockBorder func(string) string
	Quote           func(string) string
	QuoteBorder     func(string) string
	HR              func(string) string
	ListBullet      func(string) string
	Bold            func(string) string
	Italic          func(string) string
	Strikethrough   func(string) string
	Underline       func(string) string
	HighlightCode   func(code, lang string) []string
	CodeBlockIndent string
}

type OverlayAnchor

type OverlayAnchor string
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(hidden bool)
	IsHidden() bool
	Focus()
	Unfocus()
	IsFocused() bool
}

type OverlayMargin

type OverlayMargin struct {
	Top, Right, Bottom, Left int
}

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
}

type ProcessTerminal

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

ProcessTerminal owns raw terminal setup when stdin is an *os.File, routes input through StdinBuffer, and negotiates Kitty keyboard / modifyOtherKeys sequences the same way pi-tui does at the process boundary.

func NewProcessTerminal

func NewProcessTerminal() *ProcessTerminal

func NewProcessTerminalWithIO

func NewProcessTerminalWithIO(in io.Reader, out io.Writer, cols, rows int) *ProcessTerminal

func (*ProcessTerminal) ClearFromCursor

func (t *ProcessTerminal) ClearFromCursor() error

func (*ProcessTerminal) ClearLine

func (t *ProcessTerminal) ClearLine() error

func (*ProcessTerminal) ClearScreen

func (t *ProcessTerminal) ClearScreen() error

func (*ProcessTerminal) Columns

func (t *ProcessTerminal) Columns() int

func (*ProcessTerminal) DrainInput

func (t *ProcessTerminal) DrainInput(maxDuration, idle time.Duration) error

func (*ProcessTerminal) HideCursor

func (t *ProcessTerminal) HideCursor() error

func (*ProcessTerminal) KittyProtocolActive

func (t *ProcessTerminal) KittyProtocolActive() bool

func (*ProcessTerminal) MoveBy

func (t *ProcessTerminal) MoveBy(lines int) error

func (*ProcessTerminal) Rows

func (t *ProcessTerminal) Rows() int

func (*ProcessTerminal) SetProgress

func (t *ProcessTerminal) SetProgress(active bool) error

func (*ProcessTerminal) SetSize

func (t *ProcessTerminal) SetSize(cols, rows int)

func (*ProcessTerminal) SetTitle

func (t *ProcessTerminal) SetTitle(title string) error

func (*ProcessTerminal) ShowCursor

func (t *ProcessTerminal) ShowCursor() error

func (*ProcessTerminal) Start

func (t *ProcessTerminal) Start(onInput func(string), onResize func())

func (*ProcessTerminal) Stop

func (t *ProcessTerminal) Stop()

func (*ProcessTerminal) Write

func (t *ProcessTerminal) Write(data string) error

type SelectItem

type SelectItem struct {
	Value       string
	Label       string
	Description string
}

type SelectList

type SelectList struct {
	OnSelect          func(SelectItem)
	OnCancel          func()
	OnSelectionChange func(SelectItem)
	// contains filtered or unexported fields
}

func NewSelectList

func NewSelectList(items []SelectItem, maxVisible int, theme SelectListTheme, layout ...SelectListLayoutOptions) *SelectList

func (*SelectList) GetSelectedItem

func (s *SelectList) GetSelectedItem() (SelectItem, bool)

func (*SelectList) HandleInput

func (s *SelectList) HandleInput(data string)

func (*SelectList) Invalidate

func (s *SelectList) Invalidate()

func (*SelectList) Render

func (s *SelectList) Render(width int) []string

func (*SelectList) SelectedItem

func (s *SelectList) SelectedItem() (SelectItem, bool)

func (*SelectList) SetFilter

func (s *SelectList) SetFilter(filter string)

func (*SelectList) SetSelectedIndex

func (s *SelectList) SetSelectedIndex(index int)

type SelectListLayoutOptions

type SelectListLayoutOptions struct {
	MinPrimaryColumnWidth int
	MaxPrimaryColumnWidth int
	TruncatePrimary       func(SelectListTruncatePrimaryContext) string
}

type SelectListTheme

type SelectListTheme struct {
	SelectedPrefix func(string) string
	SelectedText   func(string) string
	Description    func(string) string
	ScrollInfo     func(string) string
	NoMatch        func(string) string
}

type SelectListTruncatePrimaryContext

type SelectListTruncatePrimaryContext struct {
	Text        string
	MaxWidth    int
	ColumnWidth int
	Item        SelectItem
	IsSelected  bool
}

type SettingItem

type SettingItem struct {
	ID           string
	Label        string
	Description  string
	Value        string
	CurrentValue string
	Values       []string
	Submenu      func(currentValue string, done func(selectedValue string, changed bool)) Component
}

type SettingsList

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

func NewSettingsList

func NewSettingsList(items []SettingItem, maxVisible int, theme SettingsListTheme, options ...SettingsListOptions) *SettingsList

func (*SettingsList) HandleInput

func (s *SettingsList) HandleInput(data string)

func (*SettingsList) Invalidate

func (s *SettingsList) Invalidate()

func (*SettingsList) Render

func (s *SettingsList) Render(width int) []string

func (*SettingsList) UpdateValue

func (s *SettingsList) UpdateValue(id string, newValue string)

type SettingsListOptions

type SettingsListOptions struct {
	EnableSearch bool
	OnChange     func(id string, newValue string)
	OnCancel     func()
}

type SettingsListTheme

type SettingsListTheme struct {
	Label        func(text string, selected bool) string
	CurrentValue func(text string, selected bool) string
	Description  func(string) string
	Hint         func(string) string
	Selected     func(string) string
	Value        func(string) string
	Cursor       string
}

type SizeAwareComponent

type SizeAwareComponent interface {
	RenderWithSize(width, height int) []string
}

SizeAwareComponent can opt into terminal-size-aware rendering while keeping the simple Component API available for standalone use.

type SizeValue

type SizeValue struct {
	Value        int
	Percent      bool
	PercentValue float64
}

func Cells

func Cells(value int) SizeValue

func Percent

func Percent(value int) SizeValue

func PercentFloat

func PercentFloat(value float64) SizeValue

type SlashCommand

type SlashCommand struct {
	Name                          string
	Description                   string
	ArgumentHint                  string
	GetArgumentCompletions        func(argumentPrefix string) []AutocompleteItem
	GetArgumentCompletionsContext func(ctx context.Context, argumentPrefix string) ([]AutocompleteItem, error)
}

type Spacer

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

func NewSpacer

func NewSpacer(lines int) *Spacer

func (*Spacer) Invalidate

func (s *Spacer) Invalidate()

func (*Spacer) Render

func (s *Spacer) Render(width int) []string

func (*Spacer) SetLines

func (s *Spacer) SetLines(lines int)

type StdinBuffer

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

func NewStdinBuffer

func NewStdinBuffer(options ...StdinBufferOptions) *StdinBuffer

func (*StdinBuffer) Clear

func (b *StdinBuffer) Clear()

func (*StdinBuffer) Destroy

func (b *StdinBuffer) Destroy()

func (*StdinBuffer) Flush

func (b *StdinBuffer) Flush() []string

func (*StdinBuffer) GetBuffer

func (b *StdinBuffer) GetBuffer() string

func (*StdinBuffer) OnData

func (b *StdinBuffer) OnData(fn func(string))

func (*StdinBuffer) OnPaste

func (b *StdinBuffer) OnPaste(fn func(string))

func (*StdinBuffer) Process

func (b *StdinBuffer) Process(data string)

func (*StdinBuffer) ProcessBytes

func (b *StdinBuffer) ProcessBytes(data []byte)

type StdinBufferEventMap

type StdinBufferEventMap struct {
	Data  func(string)
	Paste func(string)
}

type StdinBufferOptions

type StdinBufferOptions struct {
	Timeout time.Duration
}

type TUI

type TUI struct {
	*Container
	// contains filtered or unexported fields
}

TUI manages component focus, input routing, overlays, and terminal rendering.

func NewTUI

func NewTUI(terminal Terminal, showHardwareCursor ...bool) *TUI

func (*TUI) AddInputListener

func (t *TUI) AddInputListener(listener InputListener) func()

func (*TUI) ClearOnShrink

func (t *TUI) ClearOnShrink() bool

func (*TUI) DrainInput

func (t *TUI) DrainInput(maxDuration, idle time.Duration) error

func (*TUI) FocusedComponent

func (t *TUI) FocusedComponent() Component

func (*TUI) FullRedraws

func (t *TUI) FullRedraws() int

func (*TUI) GetClearOnShrink

func (t *TUI) GetClearOnShrink() bool

func (*TUI) GetFullRedraws

func (t *TUI) GetFullRedraws() int

func (*TUI) GetShowHardwareCursor

func (t *TUI) GetShowHardwareCursor() bool

func (*TUI) HandleInput

func (t *TUI) HandleInput(data string)

func (*TUI) HasOverlay

func (t *TUI) HasOverlay() bool

func (*TUI) HideOverlay

func (t *TUI) HideOverlay()

func (*TUI) Invalidate

func (t *TUI) Invalidate()

func (*TUI) RemoveInputListener

func (t *TUI) RemoveInputListener(listener InputListener)

func (*TUI) RequestRender

func (t *TUI) RequestRender(force ...bool)

func (*TUI) SetClearOnShrink

func (t *TUI) SetClearOnShrink(enabled bool)

func (*TUI) SetFocus

func (t *TUI) SetFocus(component Component)

func (*TUI) SetOnDebug

func (t *TUI) SetOnDebug(fn func())

func (*TUI) SetShowHardwareCursor

func (t *TUI) SetShowHardwareCursor(enabled bool)

func (*TUI) ShowHardwareCursor

func (t *TUI) ShowHardwareCursor() bool

func (*TUI) ShowOverlay

func (t *TUI) ShowOverlay(component Component, options ...OverlayOptions) OverlayHandle

func (*TUI) Start

func (t *TUI) Start()

func (*TUI) Stop

func (t *TUI) Stop()

func (*TUI) Terminal

func (t *TUI) Terminal() Terminal

type Terminal

type Terminal interface {
	Start(onInput func(string), onResize func())
	Stop()
	DrainInput(max, idle time.Duration) error
	Write(data string) error
	Columns() int
	Rows() int
	KittyProtocolActive() bool
	MoveBy(lines int) error
	HideCursor() error
	ShowCursor() error
	ClearLine() error
	ClearFromCursor() error
	ClearScreen() error
	SetTitle(title string) error
	SetProgress(active bool) error
}

Terminal is the output/input boundary used by TUI. Implementations can be a real process terminal, an xterm-headless test adapter, or an in-memory fake.

type TerminalCapabilities

type TerminalCapabilities struct {
	Images     bool
	Protocol   ImageProtocol
	TrueColor  bool
	Hyperlinks bool
}

func DetectCapabilities

func DetectCapabilities() TerminalCapabilities

func GetCapabilities

func GetCapabilities() TerminalCapabilities

type Text

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

func NewText

func NewText(text string, paddingX, paddingY int, bgFn ...func(string) string) *Text

func (*Text) Invalidate

func (t *Text) Invalidate()

func (*Text) Render

func (t *Text) Render(width int) []string

func (*Text) SetCustomBackground

func (t *Text) SetCustomBackground(fn func(string) string)

func (*Text) SetCustomBgFn

func (t *Text) SetCustomBgFn(fn func(string) string)

func (*Text) SetText

func (t *Text) SetText(text string)

type TextChunk

type TextChunk struct {
	Text       string
	StartIndex int
	EndIndex   int
}

func WordWrapLine

func WordWrapLine(line string, maxWidth int) []TextChunk

type TruncatedText

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

func NewTruncatedText

func NewTruncatedText(text string, paddingX, paddingY int, options ...TruncatedTextOptions) *TruncatedText

func (*TruncatedText) Invalidate

func (t *TruncatedText) Invalidate()

func (*TruncatedText) Render

func (t *TruncatedText) Render(width int) []string

func (*TruncatedText) SetText

func (t *TruncatedText) SetText(text string)

type TruncatedTextOptions

type TruncatedTextOptions struct {
	Ellipsis string
	Style    func(string) string
}

type UndoStack

type UndoStack[S any] struct {
	// contains filtered or unexported fields
}

UndoStack stores state snapshots. When constructed with a clone function, Push stores the cloned state so later caller mutations do not alter the snapshot. Without a clone function, S is copied by value.

func NewUndoStack

func NewUndoStack[S any](clone ...func(S) S) *UndoStack[S]

func (*UndoStack[S]) Clear

func (u *UndoStack[S]) Clear()

func (*UndoStack[S]) Len

func (u *UndoStack[S]) Len() int

func (*UndoStack[S]) Length

func (u *UndoStack[S]) Length() int

func (*UndoStack[S]) Pop

func (u *UndoStack[S]) Pop() (S, bool)

func (*UndoStack[S]) Push

func (u *UndoStack[S]) Push(state S)

type VirtualCell

type VirtualCell = vtemu.VirtualCell

type VirtualColor

type VirtualColor = vtemu.VirtualColor

type VirtualTerminal

type VirtualTerminal = vtemu.VirtualTerminal

func NewVirtualTerminal

func NewVirtualTerminal(columns, rows int) *VirtualTerminal

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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