Documentation
¶
Index ¶
- func DefaultShell() (string, []string)
- func SendBytes(p *Pty, data []byte) tea.Cmd
- type Cell
- type ClipboardErrorMsg
- type ClipboardTempPolicy
- type Cursor
- type CursorBlinkMsg
- type Emulator
- func (e *Emulator) Blur() tea.Cmd
- func (e *Emulator) CWD() string
- func (e *Emulator) ChatName() string
- func (e *Emulator) Close() error
- func (e *Emulator) CommandHistorySnapshot() []string
- func (e *Emulator) CurrentWorkingDirectory() (WorkingDirectory, bool)
- func (e *Emulator) Focus() tea.Cmd
- func (e *Emulator) Listen() tea.Cmd
- func (e *Emulator) PasteFromClipboard() tea.Cmd
- func (e *Emulator) PtyState() PtyState
- func (e *Emulator) SessionID() string
- func (e *Emulator) SetClipboardTempPolicy(policy ClipboardTempPolicy) error
- func (e *Emulator) SetCommandHistory(history []string)
- func (e *Emulator) SetInitialCWD(dir string)
- func (e *Emulator) SetOnCWDChange(fn func(WorkingDirectory))
- func (e *Emulator) SetOnCommandHistoryChanged(fn func([]string))
- func (e *Emulator) SetOnError(fn func(error))
- func (e *Emulator) SetOnExit(fn func(PtyExitMsg))
- func (e *Emulator) SetOnTitleChange(fn func(string))
- func (e *Emulator) SetScrollbackLimit(limit int)
- func (e *Emulator) SetStartEnv(env []string)
- func (e *Emulator) Start() tea.Cmd
- func (e *Emulator) StartEnv() []string
- func (e *Emulator) StartSync(extraEnv []string) error
- func (e *Emulator) StartWithEnv(extraEnv []string) tea.Cmd
- func (e *Emulator) Stop() error
- func (e *Emulator) Title() string
- func (e *Emulator) Update(msg tea.Msg) tea.Cmd
- func (e *Emulator) View(width, height int) string
- type Parser
- type Pty
- type PtyErrorMsg
- type PtyExitMsg
- type PtyOutputMsg
- type PtyReadyMsg
- type PtyState
- type PtyWarningMsg
- type RenderTickMsg
- type ResizeMsg
- type Screen
- func (s *Screen) CellAt(row, col int) (Cell, bool)
- func (s *Screen) CellsSnapshot() [][]Cell
- func (s *Screen) Clear()
- func (s *Screen) ClearLine()
- func (s *Screen) ClearLineAll()
- func (s *Screen) ClearLineLeft()
- func (s *Screen) ClearScrollback()
- func (s *Screen) ClearSelection()
- func (s *Screen) ClearTabStop(mode int)
- func (s *Screen) ClearToCursor()
- func (s *Screen) ClearWrapPending()
- func (s *Screen) Cols() int
- func (s *Screen) CursorBackward(n int)
- func (s *Screen) CursorBlinkVisible() bool
- func (s *Screen) CursorDown(n int)
- func (s *Screen) CursorForward(n int)
- func (s *Screen) CursorNextLine(n int)
- func (s *Screen) CursorPos() (row, col int)
- func (s *Screen) CursorPrevLine(n int)
- func (s *Screen) CursorState() Cursor
- func (s *Screen) CursorUp(n int)
- func (s *Screen) CursorVisible() bool
- func (s *Screen) DeleteChars(n int)
- func (s *Screen) DeleteLines(n int)
- func (s *Screen) EnterAltScreen()
- func (s *Screen) EraseChars(n int)
- func (s *Screen) ExitAltScreen()
- func (s *Screen) ExtendSelection(row, col int)
- func (s *Screen) Index()
- func (s *Screen) InsertChars(n int)
- func (s *Screen) InsertLines(n int)
- func (s *Screen) LineText(row int) string
- func (s *Screen) NextLine()
- func (s *Screen) Put(r rune)
- func (s *Screen) PutBytes(data []byte) int
- func (s *Screen) Render() string
- func (s *Screen) RepeatPrevious(n int)
- func (s *Screen) Reset()
- func (s *Screen) ResetView()
- func (s *Screen) Resize(rows, cols int)
- func (s *Screen) ResizeChecked(rows, cols int) error
- func (s *Screen) RestoreCursor()
- func (s *Screen) ReverseIndex()
- func (s *Screen) Rows() int
- func (s *Screen) SaveCursor()
- func (s *Screen) ScrollBottom() int
- func (s *Screen) ScrollRegionDown(n int)
- func (s *Screen) ScrollRegionUp(n int)
- func (s *Screen) ScrollTop() int
- func (s *Screen) ScrollUp()
- func (s *Screen) ScrollViewDown(n int)
- func (s *Screen) ScrollViewUp(n int)
- func (s *Screen) SelectionText() []string
- func (s *Screen) SetAutoWrap(active bool)
- func (s *Screen) SetCursor(row, col int)
- func (s *Screen) SetCursorAddress(row, col int)
- func (s *Screen) SetCursorBlinkVisible(visible bool)
- func (s *Screen) SetInsertMode(active bool)
- func (s *Screen) SetOriginMode(active bool)
- func (s *Screen) SetScrollRegion(top, bottom int)
- func (s *Screen) SetScrollbackLimit(limit int)
- func (s *Screen) SetSync(active bool)
- func (s *Screen) SetTabStop()
- func (s *Screen) SoftReset()
- func (s *Screen) StartSelection(row, col int)
- func (s *Screen) TabBackward(count int)
- func (s *Screen) TabForward(count int)
- func (s *Screen) ViewOffset() int
- type StyleBits
- type WorkingDirectory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultShell ¶
DefaultShell returns a usable login shell, preferring absolute paths so it works even when the parent PTY provides a minimal or empty PATH.
Types ¶
type Cell ¶
type Cell struct {
Rune rune
Combining string
FG lipgloss.Color
BG lipgloss.Color
Style StyleBits
Continuation bool
}
Cell is a single character cell on the terminal screen.
type ClipboardErrorMsg ¶
type ClipboardErrorMsg struct {
Err error
}
ClipboardErrorMsg reports a system clipboard failure without terminating PTY.
type ClipboardTempPolicy ¶
ClipboardTempPolicy bounds clipboard image files created for one Emulator.
func DefaultClipboardTempPolicy ¶
func DefaultClipboardTempPolicy() ClipboardTempPolicy
DefaultClipboardTempPolicy returns the default per-emulator clipboard limits.
type CursorBlinkMsg ¶
type CursorBlinkMsg struct{}
CursorBlinkMsg is sent by the host to toggle the cursor blink state. A single host-level timer should broadcast this message to all visible terminal emulators so their cursors blink in sync.
type Emulator ¶
type Emulator struct {
// contains filtered or unexported fields
}
Emulator is a built-in terminal emulator. It runs a shell/command in a PTY and renders the output. It is independent of any UI framework; hosts feed it keyboard/mouse/resize messages and call View(width, height) to render it.
func NewEmulator ¶
func (*Emulator) Blur ¶
Blur marks the emulator as blurred and returns a command that reports blur to the child when DECSET ?1004 is active.
func (*Emulator) CWD ¶
CWD returns the directory path without authority metadata. Use CurrentWorkingDirectory to distinguish local and remote locations.
func (*Emulator) CommandHistorySnapshot ¶
CommandHistorySnapshot returns a copy of the command list. New captures are heuristically scraped from the visible prompt line, not read from shell history.
func (*Emulator) CurrentWorkingDirectory ¶
func (e *Emulator) CurrentWorkingDirectory() (WorkingDirectory, bool)
CurrentWorkingDirectory returns the last OSC 7 location, falling back to the configured initial directory. The boolean is false when neither is known.
func (*Emulator) Focus ¶
Focus marks the emulator as focused and returns a command that reports focus to the child when DECSET ?1004 is active.
func (*Emulator) Listen ¶
Listen returns a command that waits for the next PTY output. At most one returned command may be waiting for a given Emulator.
func (*Emulator) PasteFromClipboard ¶
PasteFromClipboard asynchronously reads the system clipboard and writes its text (or an image temp-file path) to the current PTY.
func (*Emulator) SessionID ¶
SessionID returns the immutable session identifier supplied at construction.
func (*Emulator) SetClipboardTempPolicy ¶
func (e *Emulator) SetClipboardTempPolicy(policy ClipboardTempPolicy) error
PasteFromClipboard asynchronously reads the system clipboard and writes its text (or an image temp-file path) to the current PTY.
func (*Emulator) SetCommandHistory ¶
SetCommandHistory restores a previously saved heuristic command list, keeping only the newest maxCommandHistory entries.
func (*Emulator) SetInitialCWD ¶
SetInitialCWD sets the directory in which the PTY process starts.
func (*Emulator) SetOnCWDChange ¶
func (e *Emulator) SetOnCWDChange(fn func(WorkingDirectory))
SetOnCWDChange registers a callback for validated OSC 7 directory changes.
func (*Emulator) SetOnCommandHistoryChanged ¶
SetOnCommandHistoryChanged registers a callback for heuristic command captures.
func (*Emulator) SetOnError ¶
SetOnError registers a callback for PTY, clipboard, and terminal errors.
func (*Emulator) SetOnExit ¶
func (e *Emulator) SetOnExit(fn func(PtyExitMsg))
SetOnExit registers a callback for a child exit accepted by Update. It runs exactly once when ProcessExited is true; intentional Stop and Close suppress it. Hosts must keep the Listen command chain alive and route messages to Update.
func (*Emulator) SetOnTitleChange ¶
SetOnTitleChange registers a callback for validated OSC 0/2 terminal titles.
func (*Emulator) SetScrollbackLimit ¶
SetScrollbackLimit sets the maximum number of scrollback lines. Non-positive values disable the line-count limit; the Screen cell-count cap remains active. Call before Start or update the existing screen immediately after Start.
func (*Emulator) SetStartEnv ¶
SetStartEnv records extra environment variables to use when the PTY is spawned without explicit env vars (Start, StartWithEnv(nil), StartSync(nil)). Must be called before the process starts; later calls have no effect on an already running PTY.
func (*Emulator) StartEnv ¶
StartEnv returns the env vars recorded via SetStartEnv (nil when unset).
func (*Emulator) StartSync ¶
StartSync spawns the PTY process synchronously with extra environment variables. Unlike StartWithEnv, it does not return a tea.Cmd — the PTY is ready immediately. It returns an error if spawning or initial resizing fails; a resize failure leaves the spawned PTY attached with its last successfully applied size.
func (*Emulator) StartWithEnv ¶
StartWithEnv begins spawning the PTY process with extra environment variables. A non-fatal initial resize failure is reported in PtyReadyMsg.ResizeErr.
func (*Emulator) Stop ¶
Stop terminates the session, removes clipboard files, and shows the idle view.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses ANSI escape sequences and updates a Screen. It is not safe for concurrent use; callbacks run synchronously during Feed and must not re-enter the parser.
func (*Parser) Reset ¶
func (p *Parser) Reset()
Reset restores power-on screen and parser state at the current dimensions.
func (*Parser) SetCWDCallback ¶
func (p *Parser) SetCWDCallback(fn func(WorkingDirectory))
SetCWDCallback sets a callback invoked synchronously by Feed for OSC 7 changes. The callback must return promptly and must not re-enter the parser.
func (*Parser) SetResponseCallback ¶
SetResponseCallback receives terminal-generated replies synchronously during Feed, such as DSR/DA. The callback must not block or re-enter the parser; Emulator queues replies and writes them after releasing its state mutex.
func (*Parser) SetTitleCallback ¶
SetTitleCallback receives OSC 0/2 titles synchronously during Feed.
type Pty ¶
type Pty struct {
// contains filtered or unexported fields
}
Pty wraps a pseudoterminal. Methods are safe for concurrent use; consume output through Listen and call it at most once per active output chain.
func Spawn ¶
Spawn starts a new PTY with the given command, arguments and optional environment variables.
func SpawnInDir ¶
SpawnInDir starts a new PTY in the given working directory.
func (*Pty) Listen ¶
Listen returns a bubbletea command that waits for one ordered PTY read. readLoop already limits reads to 4 KiB; keeping that boundary prevents a 64 KiB Parser.Feed call from blocking the UI update loop. Listen returns a command that emits one PTY output or exit message. Call it serially and keep its returned command chain alive until the PTY exits.
type PtyErrorMsg ¶
type PtyErrorMsg struct {
Err error
}
PtyErrorMsg reports an error from a standalone PTY helper such as SendBytes.
type PtyExitMsg ¶
type PtyExitMsg struct {
SessionID string
Generation uint64
ProcessExited bool
ExitCode int
Signal os.Signal
Err error
}
PtyExitMsg is sent when the PTY process exits.
type PtyOutputMsg ¶
PtyOutputMsg is sent when new data arrives from the PTY.
type PtyReadyMsg ¶
PtyReadyMsg is sent when the PTY is ready for listening. ResizeErr is a non-fatal error applying a requested PTY size after the process started.
type PtyWarningMsg ¶
PtyWarningMsg reports a nonfatal PTY diagnostic such as trace I/O failure.
type RenderTickMsg ¶
type RenderTickMsg struct{ SessionID string }
RenderTickMsg is kept for compatibility with hosts that may still route queued tick messages from an older emulator instance.
type ResizeMsg ¶
ResizeMsg is sent by a host when the emulator's allocated rectangle changes. It carries the content size in cells (without borders or padding).
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
Screen is a 2D grid of cells. It is not safe for concurrent use; callers that share a Screen must serialize access to its methods.
func NewScreen ¶
NewScreen creates a screen with the requested dimensions. Non-positive dimensions are normalized to one cell; dimensions beyond the terminal memory budget fall back to the conventional 24x80 size. Scrollback is capped to defaultScrollbackLimit lines by default.
func (*Screen) CellsSnapshot ¶
CellsSnapshot returns a deep copy of the visible cell grid.
func (*Screen) ClearLine ¶
func (s *Screen) ClearLine()
ClearLine clears the current line from cursor to end.
func (*Screen) ClearLineAll ¶
func (s *Screen) ClearLineAll()
ClearLineAll clears the entire current line.
func (*Screen) ClearLineLeft ¶
func (s *Screen) ClearLineLeft()
ClearLineLeft clears from start of line to cursor.
func (*Screen) ClearScrollback ¶
func (s *Screen) ClearScrollback()
func (*Screen) ClearSelection ¶
func (s *Screen) ClearSelection()
ClearSelection clears any active selection.
func (*Screen) ClearTabStop ¶
ClearTabStop clears the current stop (mode 0) or all stops (mode 3).
func (*Screen) ClearToCursor ¶
func (s *Screen) ClearToCursor()
func (*Screen) ClearWrapPending ¶
func (s *Screen) ClearWrapPending()
ClearWrapPending resets the wrap-pending flag.
func (*Screen) CursorBackward ¶
CursorBackward moves the cursor left n columns.
func (*Screen) CursorBlinkVisible ¶
CursorBlinkVisible reports the host-controlled cursor blink phase.
func (*Screen) CursorDown ¶
CursorDown moves the cursor down n rows.
func (*Screen) CursorForward ¶
CursorForward moves the cursor right n columns.
func (*Screen) CursorNextLine ¶
CursorNextLine moves the cursor down n rows and to column 0.
func (*Screen) CursorPrevLine ¶
CursorPrevLine moves the cursor up n rows and to column 0.
func (*Screen) CursorState ¶
CursorState returns a copy of the cursor position and rendition.
func (*Screen) CursorVisible ¶
CursorVisible reports whether the terminal cursor is enabled.
func (*Screen) DeleteChars ¶
DeleteChars deletes n cells at the cursor and shifts the remainder left.
func (*Screen) DeleteLines ¶
DeleteLines deletes n lines at the cursor inside the active region.
func (*Screen) EnterAltScreen ¶
func (s *Screen) EnterAltScreen()
EnterAltScreen saves the current screen and clears it.
func (*Screen) EraseChars ¶
EraseChars clears n cells starting at the cursor without shifting text.
func (*Screen) ExitAltScreen ¶
func (s *Screen) ExitAltScreen()
ExitAltScreen restores the saved screen.
func (*Screen) ExtendSelection ¶
ExtendSelection updates the selection end to the given cell.
func (*Screen) Index ¶
func (s *Screen) Index()
Index moves the cursor down, scrolling the active region at its bottom.
func (*Screen) InsertChars ¶
InsertChars inserts n blank cells at the cursor.
func (*Screen) InsertLines ¶
InsertLines inserts n blank lines at the cursor inside the active region.
func (*Screen) LineText ¶
LineText returns the plain text of the given screen row, ignoring trailing empty cells. It is used to capture the current command line before sending Enter to the PTY.
func (*Screen) NextLine ¶
func (s *Screen) NextLine()
NextLine moves to column zero on the next line.
func (*Screen) Put ¶
Put writes a rune at the cursor position and advances the cursor by its terminal cell width. Wide runes occupy a base cell plus a continuation cell; combining runes extend the previous grapheme without moving the cursor.
func (*Screen) PutBytes ¶
PutBytes bulk-writes printable ASCII bytes to the screen with a single markDirty and without allocating a temporary slice. It mirrors Put's per-byte semantics (wrap at end of row, cursor advance, wrapPending) but does it in one tight pass instead of N function calls.
The caller must guarantee data is all printable ASCII (0x20..0x7e). Returns the number of bytes consumed. Callers that discover a non-printable byte must fall back to Put for that byte.
func (*Screen) Render ¶
Render returns the screen as a string. If the view is scrolled back, lines are taken from the scrollback buffer; otherwise the live screen is rendered.
func (*Screen) RepeatPrevious ¶
RepeatPrevious repeats the preceding grapheme cluster n times (REP).
func (*Screen) Reset ¶
func (s *Screen) Reset()
Reset restores power-on screen state at the current dimensions.
func (*Screen) ResetView ¶
func (s *Screen) ResetView()
ResetView resets the view offset so the live screen is shown.
func (*Screen) Resize ¶
Resize resizes the screen when dimensions are valid. Invalid dimensions leave the screen unchanged; use ResizeChecked to retrieve the validation error.
func (*Screen) ResizeChecked ¶
ResizeChecked resizes the screen or returns an error before changing it.
func (*Screen) RestoreCursor ¶
func (s *Screen) RestoreCursor()
RestoreCursor restores the saved cursor position.
func (*Screen) ReverseIndex ¶
func (s *Screen) ReverseIndex()
ReverseIndex moves the cursor up, scrolling the active region down at its top.
func (*Screen) SaveCursor ¶
func (s *Screen) SaveCursor()
SaveCursor saves the current cursor position.
func (*Screen) ScrollBottom ¶
ScrollBottom returns the bottom of the scroll region (0-indexed).
func (*Screen) ScrollRegionDown ¶
ScrollRegionDown scrolls the active region down by n lines.
func (*Screen) ScrollRegionUp ¶
ScrollRegionUp scrolls the active region up by n lines.
func (*Screen) ScrollUp ¶
func (s *Screen) ScrollUp()
ScrollUp scrolls the active region up by one line.
func (*Screen) ScrollViewDown ¶
ScrollViewDown moves the view down towards the live screen by n lines.
func (*Screen) ScrollViewUp ¶
ScrollViewUp moves the view up into the scrollback by n lines.
func (*Screen) SelectionText ¶
SelectionText returns the selected text. It returns nil when the selection exceeds clipboard resource limits; trailing whitespace is trimmed.
func (*Screen) SetAutoWrap ¶
func (*Screen) SetCursorAddress ¶
SetCursorAddress applies CUP/HVP/VPA coordinates. In DECOM origin mode the row is relative to the active scrolling region.
func (*Screen) SetCursorBlinkVisible ¶
SetCursorBlinkVisible updates the host-controlled cursor blink phase.
func (*Screen) SetInsertMode ¶
SetInsertMode controls whether printable writes shift existing cells.
func (*Screen) SetOriginMode ¶
func (*Screen) SetScrollRegion ¶
SetScrollRegion sets the scrolling region (DECSTBM). top and bottom are 1-indexed (as sent by ANSI).
func (*Screen) SetScrollbackLimit ¶
SetScrollbackLimit sets the maximum number of retained lines. A value of zero or less disables this line-count limit; the cell-count safety cap still applies.
func (*Screen) SetSync ¶
SetSync enables or disables synchronized output (ESC[?2026h/l). While synchronized output is active, Render() returns the last committed frame so intermediate redraw states are not visible.
func (*Screen) SetTabStop ¶
func (s *Screen) SetTabStop()
SetTabStop adds a tab stop at the current cursor column.
func (*Screen) SoftReset ¶
func (s *Screen) SoftReset()
SoftReset restores terminal modes and cursor rendition without clearing text.
func (*Screen) StartSelection ¶
StartSelection begins a selection at the given cell.
func (*Screen) TabBackward ¶
TabBackward moves to the previous configured tab stop, or the first column.
func (*Screen) TabForward ¶
TabForward moves to the next configured tab stop, or the last column.
func (*Screen) ViewOffset ¶
ViewOffset returns how many lines the view is scrolled back.
type WorkingDirectory ¶
WorkingDirectory is a validated OSC 7 location. Host is preserved for remote file URLs; Local reports whether Path belongs to this machine.