Skip to content

Commit

Permalink
feat(mouse): add extended coordinates and additional buttons support
Browse files Browse the repository at this point in the history
The X10 mouse protocol limits the X and Y coordinates to 223 cells only.
SGR (1006) fixes that.

* Support additional buttons like wheel left/right and backward/forward
* SGR (1006) mode extended coordinates.

feat(mouse): deprecated MouseEventType and support additional button

This includes wheel left/right, and buttons 8 through 11

chore(mouse): add extended sgr mode tests

chore(mouse): update mouse example

feat(mouse): enable extended mode by default

ref(mouse): rename backward button to back button

fix(mouse): set mouse type to release on SGR

ref(mouse): remove extended pixels mode

fix(mouse): mouse tests
  • Loading branch information
aymanbagabas committed Jan 25, 2023
1 parent 93bec55 commit bbc1082
Show file tree
Hide file tree
Showing 11 changed files with 1,142 additions and 232 deletions.
14 changes: 3 additions & 11 deletions examples/mouse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ package main
// coordinates and events.

import (
"fmt"
"log"

tea "github.com/charmbracelet/bubbletea"
)

func main() {
p := tea.NewProgram(model{}, tea.WithAltScreen(), tea.WithMouseAllMotion())
p := tea.NewProgram(model{}, tea.WithMouseAllMotion())
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
}

type model struct {
init bool
mouseEvent tea.MouseEvent
}

Expand All @@ -34,20 +32,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

case tea.MouseMsg:
m.init = true
m.mouseEvent = tea.MouseEvent(msg)
return m, tea.Printf("(X: %d, Y: %d) %s", msg.X, msg.Y, tea.MouseEvent(msg))
}

return m, nil
}

func (m model) View() string {
s := "Do mouse stuff. When you're done press q to quit.\n\n"

if m.init {
e := m.mouseEvent
s += fmt.Sprintf("(X: %d, Y: %d) %s", e.X, e.Y, e)
}
s := "Do mouse stuff. When you're done press q to quit.\n"

return s
}
2 changes: 1 addition & 1 deletion key.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func readInputs(input io.Reader) ([]Msg, error) {

// Check if it's a mouse event. For now we're parsing X10-type mouse events
// only.
mouseEvent, err := parseX10MouseEvents(b)
mouseEvent, err := parseMouseEvents(b)
if err == nil {
var m []Msg
for _, v := range mouseEvent {
Expand Down
Loading

0 comments on commit bbc1082

Please sign in to comment.