Documentation
¶
Overview ¶
Package selection provides character-level text selection for terminal UIs.
It handles converting mouse coordinates (in terminal cells) to character positions within rendered ANSI-styled text, supporting multi-byte characters, wide characters (CJK, emoji), and word/line selection via double/triple click.
The approach is modeled after Charm's crush: all coordinate calculations use display columns (terminal cells), not byte offsets or rune counts. The ultraviolet ScreenBuffer provides the bridge between rendered ANSI strings and individual character cells.
Index ¶
Constants ¶
const ClickTolerance = 2
ClickTolerance is the pixel/cell tolerance for multi-click detection.
const DoubleClickThreshold = 400 * time.Millisecond
DoubleClickThreshold is the maximum time between clicks for multi-click.
Variables ¶
This section is empty.
Functions ¶
func ExtractText ¶
ExtractText extracts plain text from a rendered ANSI string within the given column range on a single line. Uses ultraviolet to parse ANSI and extract character content.
func FindWordBoundaries ¶
FindWordBoundaries finds the start and end column of the word at the given column position in a plain-text line (ANSI codes already stripped). Returns (startCol, endCol) where endCol is exclusive. Uses UAX#29 word segmentation and display-width-aware column tracking.
func HighlightLine ¶
HighlightLine applies reverse-video highlighting to a portion of a rendered line (which may contain ANSI escape codes). startCol/endCol are in display columns. If startCol == -1, the entire line is highlighted. If startCol == endCol, returns the line unchanged.
Uses ultraviolet ScreenBuffer for cell-level ANSI manipulation.
func IsLineInRange ¶
IsLineInRange checks if a specific line within an item falls inside the selection range. Returns (inRange, startCol, endCol) where startCol == -1 means the entire line is selected. startCol == endCol means no selection on this line.
Types ¶
type Range ¶
type Range struct {
StartItemIdx int
StartLine int
StartCol int
EndItemIdx int
EndLine int
EndCol int
}
Range represents a normalized (start <= end) selection range.
type State ¶
type State struct {
// Whether a mouse button is currently held down.
MouseDown bool
// Position where mouse was first pressed (viewport-relative).
MouseDownItemIdx int
MouseDownLineIdx int
MouseDownCol int
// Current drag position (viewport-relative).
DragItemIdx int
DragLineIdx int
DragCol int
// Multi-click detection.
LastClickTime time.Time
LastClickX int
LastClickY int
ClickCount int
}
State tracks the full state of a mouse text selection.
func (*State) HasSelection ¶
HasSelection returns true if there is a non-empty active selection.