Documentation
¶
Index ¶
- func DefaultShell() (string, []string)
- func SendBytes(p *Pty, data []byte) tea.Cmd
- type Cell
- type Cursor
- type CursorBlinkMsg
- type Emulator
- func (e *Emulator) Blur()
- func (e *Emulator) CWD() string
- func (e *Emulator) Close()
- func (e *Emulator) Focus()
- func (e *Emulator) Listen() tea.Cmd
- func (e *Emulator) Pty() *Pty
- func (e *Emulator) SetCommandHistory(history []string)
- func (e *Emulator) SetInitialCWD(dir 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()
- func (e *Emulator) Update(msg tea.Msg) tea.Cmd
- func (e *Emulator) View(width, height int) string
- type Parser
- type Pty
- type PtyExitMsg
- type PtyOutputMsg
- type PtyReadyMsg
- type RenderTickMsg
- type ResizeMsg
- type Screen
- func (s *Screen) Clear()
- func (s *Screen) ClearLine()
- func (s *Screen) ClearLineAll()
- func (s *Screen) ClearLineLeft()
- func (s *Screen) ClearSelection()
- func (s *Screen) ClearWrapPending()
- func (s *Screen) CursorBackward(n int)
- 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) CursorUp(n int)
- 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) ResetView()
- func (s *Screen) Resize(rows, cols int)
- func (s *Screen) RestoreCursor()
- func (s *Screen) ReverseIndex()
- 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) SetCursor(row, col int)
- func (s *Screen) SetScrollRegion(top, bottom int)
- func (s *Screen) SetScrollbackLimit(limit int)
- func (s *Screen) SetSync(active bool)
- func (s *Screen) StartSelection(row, col int)
- func (s *Screen) ViewOffset() int
- type StyleBits
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 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 {
SessionID string
ChatName string
// Callbacks invoked when cwd or command history changes.
OnCWDChange func(string)
OnCommandHistoryChanged func([]string)
// 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) CWD ¶
CWD returns the current working directory of the PTY process. Falls back to InitialCWD if the PTY hasn't reported OSC 7 yet.
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) SetCommandHistory ¶
SetCommandHistory restores a previously saved command history.
func (*Emulator) SetInitialCWD ¶
SetInitialCWD sets the directory in which the PTY process starts.
func (*Emulator) SetScrollbackLimit ¶
SetScrollbackLimit sets the maximum number of scrollback lines. Non-positive values disable the limit. Call before Start to take effect; calling after Start updates the existing screen immediately.
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. Returns an error if spawning fails.
func (*Emulator) StartWithEnv ¶
StartWithEnv begins spawning the PTY process with extra environment variables.
func (*Emulator) Stop ¶
func (e *Emulator) Stop()
Stop terminates the session and switches the panel to the idle ASCII art view.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses ANSI escape sequences and updates a Screen.
func (*Parser) SetCWDCallback ¶
SetCWDCallback sets the callback invoked when the working directory changes.
type Pty ¶
Pty wraps a pseudoterminal and forwards output to a channel.
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.
type PtyExitMsg ¶
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.
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 {
Rows int
Cols int
Cells [][]Cell
Cursor Cursor
CursorVisible bool
CursorBlinkVisible bool // toggled by emulator for blinking cursor
// contains filtered or unexported fields
}
Screen is a 2D grid of cells.
func NewScreen ¶
NewScreen creates a new screen with the given dimensions. Scrollback is capped to defaultScrollbackLimit lines by default.
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) ClearSelection ¶
func (s *Screen) ClearSelection()
ClearSelection clears any active selection.
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) 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) 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) ResetView ¶
func (s *Screen) ResetView()
ResetView resets the view offset so the live screen is shown.
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 text currently highlighted by the selection, with each line as one string in the slice. Trailing whitespace trimmed. When dragging left on a single row, the column under the mouse (the lower col index) is excluded.
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 scrollback lines. A value of zero or less disables the limit (not recommended for long-running sessions).
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) StartSelection ¶
StartSelection begins a selection at the given cell.
func (*Screen) ViewOffset ¶
ViewOffset returns how many lines the view is scrolled back.