Documentation
¶
Overview ¶
Package sel holds the value types for component-owned mouse text selection. A selectable region (the transcript window, the composer input) owns its screen rect, its anchor/focus cells, and the plain text between them; the app router only drives the arm/drag/commit state machine across those regions. Coordinates are absolute screen cells (zero-based, matching tea.MouseMsg) at the boundary and region-local cells inside a component.
This package imports only stdlib, bubbletea, and x/ansi. It sits below internal/ui/component/* and internal/ui/screen/* in the layering so both may use it without an import cycle through app.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HighlightLines ¶
HighlightLines wraps the cells of lines between from..to (inclusive, reading order normalized) in reverse video (SGR 7 / SGR 27), the same live-drag feedback a terminal's own selection gives. It operates on already-rendered styled rows: Cut and StringWidth are display- width aware, so wide/CJK cells and ANSI runs stay aligned. Rows outside [from.Row, to.Row] are returned untouched; out-of-range rows clamp so a caller may pass a selection taller than its line slice.
func StreamSelect ¶
StreamSelect extracts the plain-text stream selection between two region-local cells from rows, normalizing so the earlier point in reading order comes first. This is a stream selection (terminal click-drag semantics), not a block selection: the anchor row runs from its column to the row's end, inner rows are taken whole, and the end row runs from its start to the focus column inclusive. Out-of-range rows clamp; styles are stripped from the result.
Types ¶
type Cell ¶
type Cell struct {
Row, Col int
}
Cell is a (row, col) position inside a region's own grid.
func FromScreen ¶
FromScreen converts an absolute screen cell to a region-local cell, clamping into the region so a press or release at the grid edge (and the spurious out-of-grid coordinates some terminals report past it) still lands on a real cell.
type CopyTextMsg ¶
type CopyTextMsg struct {
Text string
}
CopyTextMsg announces a completed copy-to-clipboard of Text so the visible screens can toast it on their status lines. OSC 52 gives no delivery confirmation, so the notice says what was attempted.
type Rect ¶
type Rect struct {
MinX, MinY, MaxX, MaxY int
}
Rect is an absolute screen rectangle, zero-based, half-open on Max: [MinX, MaxX) columns and [MinY, MaxY) rows - the same grid tea.MouseMsg reports against.
type RegionEntry ¶
type RegionEntry struct {
ID RegionID
Handle *Selectable
}
RegionEntry pairs a region id with the component that owns it. The handle is a pointer to the screen's own field (or to the stack slot's Selectable value): SetSelection and ClearSelection must mutate live state, and a value copy of a value-receiver component would mutate a copy instead.
type RegionsScreen ¶
type RegionsScreen interface {
SelectionRegions() []RegionEntry
}
RegionsScreen is implemented by any app.Screen that offers selectable regions for the current frame. The router hit-tests presses against these and routes drag updates to the owning handle.
type Selectable ¶
type Selectable interface {
// SelectionRect returns the region's current absolute screen rect.
SelectionRect() Rect
// SetSelection records the live selection (region-local cells).
SetSelection(s Selection)
// Selection reports the current selection, including the anchor the
// last SetSelection armed. The router reads it back instead of
// keeping its own copy: a value-copy of the router between press
// and motion must not lose the armed state.
Selection() Selection
// ClearSelection drops any selection and its highlight.
ClearSelection()
// SelectedText returns the plain (style-stripped) stream text
// between anchor and focus, derived from the component's model -
// not from a re-rendered string. Empty when no selection is active.
SelectedText() string
}
Selectable is what a component with a selectable text region implements. The component owns its rect (injected by the owning screen during layout), its selection state, and the plain-text extraction; it also paints the highlight itself during View, so the router never re-renders a frame to read it back.