Documentation
¶
Overview ¶
Package mouse is a pure SGR mouse-report decoder plus the (mode, zone, button, action) → intent table. Terminal bytes in, intents out. Legacy X10 encoding is deliberately unsupported.
Go port of Ruby's lib/tui/mouse.rb and lib/tui/mouse_router.rb.
Under Bubble Tea the framework already decodes mouse reports and delivers them as messages, so Decode is not on the hot path there: build an Event with New from the framework's fields and hand it to Route. Decode remains for callers reading a terminal directly, and it is what pins the wire format in tests.
Index ¶
Constants ¶
const ( // Enable and Disable are the terminal sequences that turn SGR mouse // reporting on and off. Enable = "\x1b[?1000h\x1b[?1006h" Disable = "\x1b[?1006l\x1b[?1000l" // WheelDelta is how many rows one wheel notch moves. WheelDelta = 3 )
Variables ¶
var Sequence = regexp.MustCompile(`^\x1b\[<[0-9;]*[Mm]`)
Sequence matches the start of an SGR mouse report, for input demultiplexing.
Functions ¶
This section is empty.
Types ¶
type Button ¶
type Button string
Button names a mouse button or wheel axis.
const ( Left Button = "left" Middle Button = "middle" Right Button = "right" WheelUp Button = "wheel_up" WheelDown Button = "wheel_down" WheelLeft Button = "wheel_left" WheelRight Button = "wheel_right" Button8 Button = "button8" Button9 Button = "button9" Button10 Button = "button10" Button11 Button = "button11" )
type Event ¶
Event is one decoded report. Coordinates are 0-based screen cells.
func Decode ¶
Decode parses one complete SGR report. It reports ok=false for malformed input rather than failing — a garbled report is discarded, never fatal.
func New ¶
New builds an Event from already-decoded fields — the path for a framework (Bubble Tea, say) that has parsed the report itself. Coordinates are 0-based screen cells, as everywhere else in this package.
type Intent ¶
type Intent struct {
Kind IntentKind
Delta int
Index int
View string
}
Intent is a resolved mouse intent. Delta carries the scroll amount for the scroll intents; Index carries the row for the row intents; View carries the tab key for SwitchView.
type IntentKind ¶
type IntentKind string
Action names the intent a mouse event resolves to. Every intent maps to an existing keyboard handler.
const ( Ignored IntentKind = "ignored" ScrollList IntentKind = "scroll_list" ScrollPanel IntentKind = "scroll_panel" ScrollModal IntentKind = "scroll_modal" ScrollPopup IntentKind = "scroll_popup" ScrollResponse IntentKind = "scroll_response" SelectRow IntentKind = "select_row" ActivateRow IntentKind = "activate_row" ToggleCollapse IntentKind = "toggle_collapse" SwitchView IntentKind = "switch_view" FocusPrompt IntentKind = "focus_prompt" PickerHit IntentKind = "picker_hit" )
type RouteOptions ¶
type RouteOptions struct {
Mode Mode
// Panel reports whether a right panel is currently drawn.
Panel bool
// Selected is the currently selected absolute row index, or nil.
Selected *int
}
RouteOptions carries the application state the routing table consults.