Skip to content

Commit

Permalink
feat(mouse): add extended mouse sequences
Browse files Browse the repository at this point in the history
1006: SGR mouse mode
1016: SGR Pixel mouse mode
  • Loading branch information
aymanbagabas committed Nov 10, 2022
1 parent 6fd0ee9 commit 73701ae
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions screen.go
Expand Up @@ -32,16 +32,20 @@ const (
EraseEntireLineSeq = "2K"

// Mouse.
EnableMousePressSeq = "?9h" // press only (X10)
DisableMousePressSeq = "?9l"
EnableMouseSeq = "?1000h" // press, release, wheel
DisableMouseSeq = "?1000l"
EnableMouseHiliteSeq = "?1001h" // highlight
DisableMouseHiliteSeq = "?1001l"
EnableMouseCellMotionSeq = "?1002h" // press, release, move on pressed, wheel
DisableMouseCellMotionSeq = "?1002l"
EnableMouseAllMotionSeq = "?1003h" // press, release, move, wheel
DisableMouseAllMotionSeq = "?1003l"
EnableMousePressSeq = "?9h" // press only (X10)
DisableMousePressSeq = "?9l"
EnableMouseSeq = "?1000h" // press, release, wheel
DisableMouseSeq = "?1000l"
EnableMouseHiliteSeq = "?1001h" // highlight
DisableMouseHiliteSeq = "?1001l"
EnableMouseCellMotionSeq = "?1002h" // press, release, move on pressed, wheel
DisableMouseCellMotionSeq = "?1002l"
EnableMouseAllMotionSeq = "?1003h" // press, release, move, wheel
DisableMouseAllMotionSeq = "?1003l"
EnableMouseExtendedModeSeq = "?1006h" // press, release, move, wheel, extended coordinates
DisableMouseExtendedModeSeq = "?1006l"
EnableMousePixelsModeSeq = "?1016h" // press, release, move, wheel, extended pixel coordinates
DisableMousePixelsModeSeq = "?1016l"

// Screen.
RestoreScreenSeq = "?47l"
Expand Down Expand Up @@ -259,6 +263,29 @@ func (o Output) DisableMouseAllMotion() {
fmt.Fprint(o.tty, CSI+DisableMouseAllMotionSeq)
}

// EnableMouseExtendedMotion enables Extended Mouse mode (SGR). This should be
// enabled in conjunction with EnableMouseCellMotion, and EnableMouseAllMotion.
func (o Output) EnableMouseExtendedMode() {
fmt.Fprint(o.tty, CSI+EnableMouseExtendedModeSeq)
}

// DisableMouseExtendedMotion disables Extended Mouse mode (SGR).
func (o Output) DisableMouseExtendedMode() {
fmt.Fprint(o.tty, CSI+DisableMouseExtendedModeSeq)
}

// EnableMousePixelsMotion enables Pixel Motion Mouse mode (SGR-Pixels). This
// should be enabled in conjunction with EnableMouseCellMotion, and
// EnableMouseAllMotion.
func (o Output) EnableMousePixelsMode() {
fmt.Fprint(o.tty, CSI+EnableMousePixelsModeSeq)
}

// DisableMousePixelsMotion disables Pixel Motion Mouse mode (SGR-Pixels).
func (o Output) DisableMousePixelsMode() {
fmt.Fprint(o.tty, CSI+DisableMousePixelsModeSeq)
}

// SetWindowTitle sets the terminal window title.
func (o Output) SetWindowTitle(title string) {
fmt.Fprintf(o.tty, OSC+SetWindowTitleSeq, title)
Expand Down

0 comments on commit 73701ae

Please sign in to comment.