Documentation
¶
Overview ¶
Package scrollback provides a scrollback browser that parses terminal history into structured command-output blocks.
Index ¶
- Variables
- type Browser
- func (b *Browser) CycleMode()
- func (b *Browser) EnterOutputMode()
- func (b *Browser) ExitOutputMode()
- func (b *Browser) Next()
- func (b *Browser) PageDown(pageSize int)
- func (b *Browser) PageUp(pageSize int)
- func (b *Browser) Prev()
- func (b *Browser) ScrollPreviewDown()
- func (b *Browser) ScrollPreviewUp()
- func (b *Browser) SelectedCommand() *CommandBlock
- func (b *Browser) SelectedCommandText() string
- func (b *Browser) SelectedJSON() *JSONBlock
- func (b *Browser) SelectedPath() *PathBlock
- func (b *Browser) SelectedStyledText() string
- func (b *Browser) SelectedText() string
- func (b *Browser) SetMode(mode BrowserMode)
- func (b *Browser) SetSearch(query string)
- func (b *Browser) ToggleSelect()
- type BrowserMode
- type CommandBlock
- type JSONBlock
- type PathBlock
- type VimMode
- type VimSearchMatch
- type VimState
- func (v *VimState) CenterView()
- func (v *VimState) ConsumeCount() int
- func (v *VimState) EnsureVisible()
- func (v *VimState) EnterVisualChar()
- func (v *VimState) EnterVisualLine()
- func (v *VimState) ExitVisual()
- func (v *VimState) FindChar(ch rune, dir int, till bool) bool
- func (v *VimState) HalfPageDown()
- func (v *VimState) HalfPageUp()
- func (v *VimState) MatchBracket()
- func (v *VimState) MoveDown()
- func (v *VimState) MoveLeft()
- func (v *VimState) MoveRight()
- func (v *VimState) MoveToBottom()
- func (v *VimState) MoveToFirstNonBlank()
- func (v *VimState) MoveToLine(n int)
- func (v *VimState) MoveToLineEnd()
- func (v *VimState) MoveToLineStart()
- func (v *VimState) MoveToScreenBottom()
- func (v *VimState) MoveToScreenMiddle()
- func (v *VimState) MoveToScreenTop()
- func (v *VimState) MoveToTop()
- func (v *VimState) MoveUp()
- func (v *VimState) PageDown()
- func (v *VimState) PageUp()
- func (v *VimState) ParagraphDown()
- func (v *VimState) ParagraphUp()
- func (v *VimState) RepeatCharSearch(reverse bool) bool
- func (v *VimState) SearchExecute()
- func (v *VimState) SearchMatchesOnLine(y int) []VimSearchMatch
- func (v *VimState) SearchNext()
- func (v *VimState) SearchPrev()
- func (v *VimState) SelectedText() string
- func (v *VimState) VisualBounds() (int, int, int, int)
- func (v *VimState) WORDBackward()
- func (v *VimState) WORDEnd()
- func (v *VimState) WORDForward()
- func (v *VimState) WordBackward()
- func (v *VimState) WordEnd()
- func (v *VimState) WordForward()
Constants ¶
This section is empty.
Variables ¶
var DebugLogFunc func(format string, args ...any)
DebugLogFunc can be set to capture parser diagnostic output.
Functions ¶
This section is empty.
Types ¶
type Browser ¶
type Browser struct {
Blocks []CommandBlock
FilteredIdx []int // indices into Blocks matching search
SelectedIdx int // cursor in filtered list
ScrollOffset int // left pane scroll
PreviewScroll int // right pane scroll
Mode BrowserMode
SearchQuery string
SearchActive bool
MultiSelect map[int]bool // selected block indices (for multi-yank)
// Diagnostic info (displayed in header)
ParseMethod string // "osc133" or "regex"
MarkerCount int // number of OSC 133 markers found
// Extracted content for JSON/Paths modes
JSONBlocks []JSONBlock
PathBlocks []PathBlock
FilteredJSON []int
FilteredPaths []int
// Output pane navigation (vim mode)
OutputMode bool // focus in output pane
Vim *VimState // vim navigation state (non-nil when OutputMode is true)
LastPaneHeight int // set by renderer, used for page movement
// Help overlay
ShowHelp bool // show keybinding help modal
// Layout geometry populated each render for mouse input mapping.
LayoutLeftW int // left pane width
LayoutRightW int // right pane width
LayoutPaneH int // pane height (rows)
// Mouse drag state for visual selection.
DragActive bool // mouse button held in right pane
DragOriginY int // line index at drag start
DragOriginX int // column at drag start
}
Browser holds the state for the scrollback browser overlay.
func NewBrowser ¶
func NewBrowser(blocks []CommandBlock) *Browser
NewBrowser creates a browser from parsed command blocks.
func (*Browser) EnterOutputMode ¶
func (b *Browser) EnterOutputMode()
EnterOutputMode enters the output pane with vim-style navigation.
func (*Browser) ExitOutputMode ¶
func (b *Browser) ExitOutputMode()
ExitOutputMode returns focus to the command list.
func (*Browser) ScrollPreviewDown ¶
func (b *Browser) ScrollPreviewDown()
ScrollPreviewDown scrolls the preview pane down.
func (*Browser) ScrollPreviewUp ¶
func (b *Browser) ScrollPreviewUp()
ScrollPreviewUp scrolls the preview pane up.
func (*Browser) SelectedCommand ¶
func (b *Browser) SelectedCommand() *CommandBlock
SelectedCommand returns the currently selected command block, or nil.
func (*Browser) SelectedCommandText ¶
SelectedCommandText returns the command string for paste-back.
func (*Browser) SelectedJSON ¶
SelectedJSON returns the currently selected JSON block, or nil.
func (*Browser) SelectedPath ¶
SelectedPath returns the currently selected path block, or nil.
func (*Browser) SelectedStyledText ¶
SelectedStyledText returns the ANSI-styled output for the current selection.
func (*Browser) SelectedText ¶
SelectedText returns the copyable text for the current selection.
func (*Browser) SetMode ¶
func (b *Browser) SetMode(mode BrowserMode)
SetMode switches to a specific mode.
func (*Browser) ToggleSelect ¶
func (b *Browser) ToggleSelect()
ToggleSelect toggles multi-selection on the current item.
type BrowserMode ¶
type BrowserMode int
BrowserMode selects what the browser displays.
const ( // ModeCommands shows command/output blocks. ModeCommands BrowserMode = iota // ModeJSON shows extracted JSON fragments. ModeJSON // ModePaths shows extracted file paths and URLs. ModePaths )
type CommandBlock ¶
type CommandBlock struct {
Command string // command text (what the user typed)
Output string // plain text output
StyledOutput string // ANSI-colored output (preserves terminal styling)
ExitCode int // -1 if unknown
StartLine int // absolute line index
EndLine int // absolute line index (inclusive)
Method string // "osc133" or "regex" — how this block was parsed
}
CommandBlock represents a single command and its output extracted from scrollback.
func ParseBlocks ¶
func ParseBlocks(term *vt.Emulator) []CommandBlock
ParseBlocks extracts command blocks from the terminal's scrollback and screen. It uses OSC 133 markers when available, falling back to regex prompt detection.
type JSONBlock ¶
type JSONBlock struct {
Name string // description (e.g., "object" or "array")
Pretty string // pretty-printed JSON
Raw string // raw JSON string
}
JSONBlock represents a JSON object or array found in command output.
func ExtractJSON ¶
ExtractJSON finds valid JSON objects and arrays in the output text using bracket matching.
type PathBlock ¶
type PathBlock struct {
Raw string
Path string
Line int // extracted line number, 0 if none
Col int // extracted column number, 0 if none
IsURL bool
}
PathBlock represents a file path or URL found in command output.
func ExtractPaths ¶
ExtractPaths finds file paths and URLs in the output text.
type VimSearchMatch ¶
type VimSearchMatch struct {
Line int
StartX int // rune index (inclusive)
EndX int // rune index (exclusive)
}
VimSearchMatch represents a search match position within a line.
type VimState ¶
type VimState struct {
// Cursor position (rune indices)
CursorX int
CursorY int
// Viewport
ScrollY int // first visible line index
ViewHeight int // visible rows (set by renderer)
// Mode
Mode VimMode
// Visual selection anchor
VisualStartX int
VisualStartY int
// Search
SearchQuery string
SearchMatches []VimSearchMatch
SearchCurrent int
// Count prefix
PendingCount int
// Character search (f/F/t/T)
PendingCharSearch bool
LastCharSearch rune
LastCharSearchDir int // 1=forward, -1=backward
LastCharSearchTill bool // true for t/T
// gg detection
PendingG bool
LastGTime time.Time
// Text data
Lines []string // plain text (used for cursor/search logic)
StyledLines []string // ANSI-styled text (used for rendering with colors)
}
VimState holds cursor, selection, and search state for vim-style navigation over plain text lines. Used by the scrollback browser output mode.
func NewVimState ¶
NewVimState creates a VimState for the given text lines, with cursor at startY. styledLines may be nil — if provided, they are used for colored rendering.
func (*VimState) CenterView ¶
func (v *VimState) CenterView()
CenterView centers the viewport on the cursor.
func (*VimState) ConsumeCount ¶
ConsumeCount returns the pending count (minimum 1) and resets it.
func (*VimState) EnsureVisible ¶
func (v *VimState) EnsureVisible()
EnsureVisible adjusts ScrollY to keep cursor in viewport.
func (*VimState) EnterVisualChar ¶
func (v *VimState) EnterVisualChar()
EnterVisualChar enters character-wise visual mode.
func (*VimState) EnterVisualLine ¶
func (v *VimState) EnterVisualLine()
EnterVisualLine enters line-wise visual mode.
func (*VimState) FindChar ¶
FindChar searches for a character, crossing line boundaries. dir: 1=forward, -1=backward. till: true=stop before char.
func (*VimState) HalfPageDown ¶
func (v *VimState) HalfPageDown()
func (*VimState) HalfPageUp ¶
func (v *VimState) HalfPageUp()
func (*VimState) MatchBracket ¶
func (v *VimState) MatchBracket()
func (*VimState) MoveToBottom ¶
func (v *VimState) MoveToBottom()
func (*VimState) MoveToFirstNonBlank ¶
func (v *VimState) MoveToFirstNonBlank()
func (*VimState) MoveToLine ¶
func (*VimState) MoveToLineEnd ¶
func (v *VimState) MoveToLineEnd()
func (*VimState) MoveToLineStart ¶
func (v *VimState) MoveToLineStart()
func (*VimState) MoveToScreenBottom ¶
func (v *VimState) MoveToScreenBottom()
func (*VimState) MoveToScreenMiddle ¶
func (v *VimState) MoveToScreenMiddle()
func (*VimState) MoveToScreenTop ¶
func (v *VimState) MoveToScreenTop()
func (*VimState) ParagraphDown ¶
func (v *VimState) ParagraphDown()
func (*VimState) ParagraphUp ¶
func (v *VimState) ParagraphUp()
func (*VimState) RepeatCharSearch ¶
RepeatCharSearch repeats the last f/F/t/T search. reverse flips direction.
func (*VimState) SearchExecute ¶
func (v *VimState) SearchExecute()
SearchExecute runs the search query and jumps to the first match at or after cursor.
func (*VimState) SearchMatchesOnLine ¶
func (v *VimState) SearchMatchesOnLine(y int) []VimSearchMatch
SearchMatchesOnLine returns all search matches on the given line.
func (*VimState) SearchNext ¶
func (v *VimState) SearchNext()
SearchNext jumps to the next search match.
func (*VimState) SearchPrev ¶
func (v *VimState) SearchPrev()
SearchPrev jumps to the previous search match.
func (*VimState) SelectedText ¶
SelectedText returns the text of the current selection (visual) or current line (normal).
func (*VimState) VisualBounds ¶
VisualBounds returns the normalized selection bounds for rendering. Returns (startX, startY, endX, endY) where start <= end.
func (*VimState) WORDBackward ¶
func (v *VimState) WORDBackward()
func (*VimState) WORDForward ¶
func (v *VimState) WORDForward()
func (*VimState) WordBackward ¶
func (v *VimState) WordBackward()
func (*VimState) WordForward ¶
func (v *VimState) WordForward()