* mouse: the wheel's four directions and the side buttons parseSGRMouse read a report's low two bits alone, so a wheel tilted left or right (66, 67) reported as WheelDown, and a mouse's back and forward buttons (128, 129) as a left or middle press. It now decodes by bank: bits 0-1 number a button within the main three and none, the wheel's four directions (bit 6), or buttons 8 to 11 (bit 7). WheelLeft and WheelRight join MouseButton after Forward, so every existing value keeps its number; Back and Forward are reported for buttons 8 and 9; buttons 10 and 11, and a report with both bank bits set, are dropped as KeyNone. A wheel step is a press with no release in every direction. * tui: ScrollThumb and ScrollDrag ScrollThumb is the thumb ScrollBarStyled draws, its first row and height, exported so an application hit-tests the bar it drew. ScrollDrag drives a bar by the pointer, rows counted from the track's top: a press on the thumb takes hold where it lands, a press on the track moves the thumb's middle there and takes hold, and each drag keeps the held row under the pointer, clamped at the track's ends, at the nearest offset when there are fewer offsets than rows. Each call returns the offset to show. A table of SGR reports covers each bank and drops the buttons past 9; a property test over every track of 3 to 10 rows and content up to 30 checks each press and drag against the thumb ScrollThumb draws.
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package terminal
|
|
|
|
// MouseButton represents mouse button identity
|
|
type MouseButton uint8
|
|
|
|
const (
|
|
MouseBtnNone MouseButton = iota
|
|
MouseBtnLeft
|
|
MouseBtnMiddle
|
|
MouseBtnRight
|
|
MouseBtnWheelUp
|
|
MouseBtnWheelDown
|
|
MouseBtnBack // Button 8, a mouse's back side button
|
|
MouseBtnForward // Button 9, its forward side button
|
|
MouseBtnWheelLeft // A wheel tilted left, or a touchpad swiped so
|
|
MouseBtnWheelRight // A wheel tilted right, or a touchpad swiped so
|
|
)
|
|
|
|
// MouseAction represents the type of mouse event
|
|
type MouseAction uint8
|
|
|
|
const (
|
|
MouseActionNone MouseAction = iota
|
|
MouseActionPress
|
|
MouseActionRelease
|
|
MouseActionMove
|
|
MouseActionDrag
|
|
)
|
|
|
|
// MouseMode controls which mouse events are reported (bitmask)
|
|
type MouseMode uint8
|
|
|
|
const (
|
|
MouseModeNone MouseMode = 0
|
|
MouseModeClick MouseMode = 1 << 0 // Press/release events
|
|
MouseModeDrag MouseMode = 1 << 1 // Drag events (button held + motion)
|
|
MouseModeMotion MouseMode = 1 << 2 // All motion events
|
|
)
|
|
|
|
// String returns human-readable button name
|
|
func (b MouseButton) String() string {
|
|
switch b {
|
|
case MouseBtnLeft:
|
|
return "Left"
|
|
case MouseBtnMiddle:
|
|
return "Middle"
|
|
case MouseBtnRight:
|
|
return "Right"
|
|
case MouseBtnWheelUp:
|
|
return "WheelUp"
|
|
case MouseBtnWheelDown:
|
|
return "WheelDown"
|
|
case MouseBtnBack:
|
|
return "Back"
|
|
case MouseBtnForward:
|
|
return "Forward"
|
|
case MouseBtnWheelLeft:
|
|
return "WheelLeft"
|
|
case MouseBtnWheelRight:
|
|
return "WheelRight"
|
|
default:
|
|
return "None"
|
|
}
|
|
}
|
|
|
|
// String returns human-readable action name
|
|
func (a MouseAction) String() string {
|
|
switch a {
|
|
case MouseActionPress:
|
|
return "Press"
|
|
case MouseActionRelease:
|
|
return "Release"
|
|
case MouseActionMove:
|
|
return "Move"
|
|
case MouseActionDrag:
|
|
return "Drag"
|
|
default:
|
|
return "None"
|
|
}
|
|
}
|