mouse

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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 Action

type Action string

Action is what the button did.

const (
	Press   Action = "press"
	Release Action = "release"
	Motion  Action = "motion"
)

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

type Event struct {
	Button           Button
	Action           Action
	Col, Row         int
	Shift, Alt, Ctrl bool
}

Event is one decoded report. Coordinates are 0-based screen cells.

func Decode

func Decode(seq string) (Event, bool)

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

func New(button Button, action Action, col, row int) Event

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.

func (Event) IsExtra

func (e Event) IsExtra() bool

IsExtra reports one of the button8..11 side buttons.

func (Event) IsMotion

func (e Event) IsMotion() bool

func (Event) IsPress

func (e Event) IsPress() bool

func (Event) IsRelease

func (e Event) IsRelease() bool

func (Event) IsWheel

func (e Event) IsWheel() bool

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.

func Route

func Route(event Event, ok bool, hit hitmap.Hit, opts RouteOptions) Intent

Route maps a decoded event and the zone it landed in to an intent.

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 Mode

type Mode string

Mode is the input mode the application is in when the event arrives.

const (
	ModeList           Mode = "list"
	ModeModal          Mode = "modal"
	ModeModalFilter    Mode = "modal_filter"
	ModePalette        Mode = "palette"
	ModeContextPalette Mode = "context_palette"
	ModeLinkPicker     Mode = "link_picker"
	ModeForm           Mode = "form"
	ModeTaskEdit       Mode = "task_edit"
	ModePrompt         Mode = "prompt"
)

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.

Jump to

Keyboard shortcuts

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