sel

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

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

func HighlightLines(lines []string, from, to Cell) []string

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

func StreamSelect(rows []string, from, to Cell) string

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

func FromScreen(r Rect, x, y int) Cell

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.

func (Rect) Contains

func (r Rect) Contains(x, y int) bool

Contains reports whether the screen cell (x, y) falls inside r.

func (Rect) Height

func (r Rect) Height() int

Height returns the row count of r.

func (Rect) Width

func (r Rect) Width() int

Width returns the column count of r.

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 RegionID

type RegionID string

RegionID names one selectable region within a screen.

const (
	RegionTranscript RegionID = "transcript"
	RegionComposer   RegionID = "composer"
	RegionPager      RegionID = "pager"
)

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.

type Selection

type Selection struct {
	Active bool
	Anchor Cell
	Focus  Cell
}

Selection is an anchor/focus pair in region-local cells. Anchor is where the press armed the selection; focus is where the drag (or release) last reached. Active distinguishes a live or pending selection from none.

func (Selection) Ordered

func (s Selection) Ordered() (from, to Cell)

Ordered returns the two cells normalized so the earlier one in reading order comes first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL