Documentation
¶
Index ¶
- Constants
- func StyleToANSI(s Style) string
- func StyleToDeltaANSI(prev, next Style) string
- type Cell
- type Color
- type ColorType
- type Parser
- type ResponseWriter
- type Style
- type VTerm
- func (v *VTerm) AbsoluteLineToScreenY(absLine int) int
- func (v *VTerm) ClearDirty()
- func (v *VTerm) ClearDirtyWithCursor(showCursor bool)
- func (v *VTerm) ClearSelection()
- func (v *VTerm) DirtyLines() ([]bool, bool)
- func (v *VTerm) GetAllLines() []string
- func (v *VTerm) GetScrollInfo() (int, int)
- func (v *VTerm) GetSelectedText(startX, startLine, endX, endLine int) string
- func (v *VTerm) GetTextRange(startX, startLine, endX, endLine int) string
- func (v *VTerm) HasSelection() bool
- func (v *VTerm) IsInSelection(x, screenY int) bool
- func (v *VTerm) IsScrolled() bool
- func (v *VTerm) LastCursorHidden() bool
- func (v *VTerm) LastCursorX() int
- func (v *VTerm) LastCursorY() int
- func (v *VTerm) LastShowCursor() bool
- func (v *VTerm) LineCells(line int) []Cell
- func (v *VTerm) MaxViewOffset() int
- func (v *VTerm) PrependScrollback(data []byte)
- func (v *VTerm) Render() string
- func (v *VTerm) RenderBuffers() ([][]Cell, int)
- func (v *VTerm) Resize(width, height int)
- func (v *VTerm) ScreenYToAbsoluteLine(screenY int) int
- func (v *VTerm) ScrollToLine(lineIdx int)
- func (v *VTerm) ScrollView(delta int)
- func (v *VTerm) ScrollViewTo(offset int)
- func (v *VTerm) ScrollViewToBottom()
- func (v *VTerm) ScrollViewToTop()
- func (v *VTerm) Search(query string) []int
- func (v *VTerm) SelActive() bool
- func (v *VTerm) SelEndLine() int
- func (v *VTerm) SelEndX() int
- func (v *VTerm) SelEndY() int
- func (v *VTerm) SelStartLine() int
- func (v *VTerm) SelStartX() int
- func (v *VTerm) SelStartY() int
- func (v *VTerm) SetResponseWriter(w ResponseWriter)
- func (v *VTerm) SetSelection(startX, startLine, endX, endLine int, active, rect bool)
- func (v *VTerm) SyncActive() bool
- func (v *VTerm) TotalLines() int
- func (v *VTerm) Version() uint64
- func (v *VTerm) VisibleLineRange() (start, end, total int)
- func (v *VTerm) VisibleScreen() [][]Cell
- func (v *VTerm) VisibleScreenInto(dst [][]Cell) [][]Cell
- func (v *VTerm) VisibleScreenWithSelection() [][]Cell
- func (v *VTerm) Write(data []byte)
Constants ¶
const MaxScrollback = 10000
Variables ¶
This section is empty.
Functions ¶
func StyleToANSI ¶
StyleToANSI converts a Style to ANSI escape codes. Optimized to avoid allocations using strings.Builder.
func StyleToDeltaANSI ¶
StyleToDeltaANSI returns the minimal SGR escape sequence to transition from prev to next style. This avoids the overhead of always emitting a full reset. Optimized to avoid allocations using strings.Builder.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles ANSI escape sequence parsing
type ResponseWriter ¶
type ResponseWriter func([]byte)
ResponseWriter is called when the terminal needs to send a response back to the PTY
type Style ¶
type Style struct {
Fg Color
Bg Color
Bold bool
Dim bool
Italic bool
Underline bool
Blink bool
Reverse bool
Hidden bool
Strike bool
}
Style holds text styling attributes
type VTerm ¶
type VTerm struct {
// Screen buffer (visible area)
Screen [][]Cell
// Scrollback buffer (oldest at index 0)
Scrollback [][]Cell
// Cursor position (0-indexed)
CursorX, CursorY int
// Dimensions
Width, Height int
// Scroll viewing position (0 = live, >0 = lines scrolled up)
ViewOffset int
// Alt screen mode (full-screen TUI applications).
AltScreen bool
// AllowAltScreenScrollback keeps scrollback active even in alt screen.
// Useful for tmux-backed sessions where scrollback should remain available.
AllowAltScreenScrollback bool
// Scrolling region (for DECSTBM)
ScrollTop int
ScrollBottom int
// Origin mode (DECOM) - cursor positions are relative to scroll region.
OriginMode bool
// Current style for new characters
CurrentStyle Style
// Saved cursor state (for DECSC/DECRC)
SavedCursorX int
SavedCursorY int
SavedStyle Style
// Cursor visibility (controlled externally when pane is focused)
ShowCursor bool
// CursorHidden tracks if terminal app hid cursor via DECTCEM (mode 25)
CursorHidden bool
// contains filtered or unexported fields
}
VTerm is a virtual terminal emulator with scrollback support.
Synchronization contract: VTerm has no internal mutex. All callers must provide external synchronization. In practice, every call site (WriteToTerminal, SidebarPTYFlush, and TerminalLayer snapshot creation) holds TerminalState.mu for the duration of the operation. Snapshot-based rendering (TerminalLayer) copies data under the lock and then renders the immutable snapshot without locks.
func (*VTerm) AbsoluteLineToScreenY ¶ added in v0.0.4
AbsoluteLineToScreenY converts an absolute line number to a screen Y coordinate. Returns -1 if the line is not currently visible.
func (*VTerm) ClearDirty ¶
func (v *VTerm) ClearDirty()
ClearDirty resets dirty tracking state after a render.
func (*VTerm) ClearDirtyWithCursor ¶
ClearDirtyWithCursor resets dirty tracking state and updates cursor tracking. This should be called after snapshotting to track cursor position changes.
func (*VTerm) ClearSelection ¶
func (v *VTerm) ClearSelection()
ClearSelection clears the current selection
func (*VTerm) DirtyLines ¶
DirtyLines returns the dirty line flags and whether all lines are dirty. This is used by VTermLayer for optimized rendering.
func (*VTerm) GetAllLines ¶
GetAllLines returns all content (scrollback + screen) as lines for search
func (*VTerm) GetScrollInfo ¶
GetScrollInfo returns (current offset, max offset)
func (*VTerm) GetSelectedText ¶
GetSelectedText extracts text from the current selection. Returns empty string if no selection is active.
func (*VTerm) GetTextRange ¶
GetTextRange extracts text from a range in the combined scrollback+screen buffer. Coordinates are absolute line indices (0-based) and columns.
func (*VTerm) HasSelection ¶ added in v0.0.4
HasSelection returns true if there is an active selection.
func (*VTerm) IsInSelection ¶
IsInSelection checks if coordinate (x, screenY) is within the selection. screenY is a screen-relative coordinate (0 to Height-1).
func (*VTerm) IsScrolled ¶
IsScrolled returns true if viewing scrollback
func (*VTerm) LastCursorHidden ¶
LastCursorHidden returns the DECTCEM cursor hidden state from the previous render frame.
func (*VTerm) LastCursorX ¶
LastCursorX returns the cursor X position from the previous render frame. Used to detect cursor movement and mark dirty lines.
func (*VTerm) LastCursorY ¶
LastCursorY returns the cursor Y position from the previous render frame. Used to detect cursor movement and mark old cursor line dirty.
func (*VTerm) LastShowCursor ¶
LastShowCursor returns the cursor visibility from the previous render frame.
func (*VTerm) LineCells ¶
LineCells returns the cell slice for an absolute line index in scrollback+screen.
func (*VTerm) MaxViewOffset ¶
MaxViewOffset returns the maximum scrollback offset for the current buffers.
func (*VTerm) PrependScrollback ¶ added in v0.0.9
PrependScrollback parses captured scrollback content (with ANSI escapes) and prepends the resulting lines to the scrollback buffer. This is used to populate scrollback history when attaching to an existing tmux session. It is a no-op if data is empty.
func (*VTerm) RenderBuffers ¶
RenderBuffers returns the current screen buffer and scrollback length. During synchronized output, it returns the frozen snapshot.
func (*VTerm) ScreenYToAbsoluteLine ¶ added in v0.0.4
ScreenYToAbsoluteLine converts a screen Y coordinate (0 to Height-1) to an absolute line number. Absolute line 0 is the first line in scrollback.
func (*VTerm) ScrollToLine ¶
ScrollToLine scrolls view to show the given line index (in combined buffer)
func (*VTerm) ScrollView ¶
ScrollView scrolls the view by delta lines (positive = up into history)
func (*VTerm) ScrollViewTo ¶
ScrollViewTo sets absolute scroll position
func (*VTerm) ScrollViewToBottom ¶
func (v *VTerm) ScrollViewToBottom()
ScrollViewToBottom returns to live view
func (*VTerm) ScrollViewToTop ¶
func (v *VTerm) ScrollViewToTop()
ScrollViewToTop scrolls to oldest content
func (*VTerm) SelEndLine ¶ added in v0.0.4
SelEndLine returns the selection end line (absolute line number).
func (*VTerm) SelEndY ¶
SelEndY returns the selection end Y in screen coordinates. Returns -1 if the end line is not visible.
func (*VTerm) SelStartLine ¶ added in v0.0.4
SelStartLine returns the selection start line (absolute line number).
func (*VTerm) SelStartY ¶
SelStartY returns the selection start Y in screen coordinates. Returns -1 if the start line is not visible.
func (*VTerm) SetResponseWriter ¶
func (v *VTerm) SetResponseWriter(w ResponseWriter)
SetResponseWriter sets the callback for terminal query responses
func (*VTerm) SetSelection ¶
SetSelection stores selection coordinates for rendering with highlight. startLine and endLine are absolute line numbers (0 = first scrollback line).
func (*VTerm) SyncActive ¶
SyncActive reports whether synchronized output is currently active.
func (*VTerm) TotalLines ¶
TotalLines returns the total number of lines in scrollback+screen.
func (*VTerm) Version ¶
Version returns the current version counter. This increments whenever visible content changes.
func (*VTerm) VisibleLineRange ¶
VisibleLineRange returns the [start, end) line indices in the combined scrollback+screen buffer that are currently visible, along with total lines.
func (*VTerm) VisibleScreen ¶
VisibleScreen returns the currently visible screen buffer as a copy.
func (*VTerm) VisibleScreenInto ¶ added in v0.0.12
VisibleScreenInto returns the currently visible screen buffer, reusing dst when possible. dst is resized as needed and its lines are reused to reduce allocations.
func (*VTerm) VisibleScreenWithSelection ¶
VisibleScreenWithSelection returns the visible screen with selection highlighting applied.