Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse events are recognized as key events when the terminal gains focus(may have been solved) #718

Closed
kylezb opened this issue Apr 11, 2023 · 1 comment · Fixed by #594
Closed

Comments

@kylezb
Copy link

kylezb commented Apr 11, 2023

Describe the bug
As the title says, however I think this has been solved by aymanbagabas in #594

Setup
Please complete the following information along with version numbers, if applicable.

  • OS Windows11
  • Shell Powershell
  • Terminal Emulator Windows Terminal
  • Terminal Multiplexer

To Reproduce
Steps to reproduce the behavior:

  1. Go to bubbletea/examples/mouse/main.go
  2. I changed the code to make it easier to see the problem(see below)
  3. run the code

Source Code

package main

// A simple program that opens the alternate screen buffer and displays mouse
// coordinates and events.

import (
	"fmt"
	"log"

	tea "github.com/charmbracelet/bubbletea"
)

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

type model struct {
	init       bool
	mouseEvent tea.MouseEvent
	key        tea.KeyMsg <---------------------------------------------------- (ADD)
}

func (m model) Init() tea.Cmd {
	return nil
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.KeyMsg:
		if s := msg.String(); s == "ctrl+c" || s == "q" || s == "esc" {
			return m, tea.Quit
		} else {
			m.key = msg <---------------------------------------------------- (ADD)
		}

	case tea.MouseMsg:
		m.init = true
		m.mouseEvent = 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 \n", e.X, e.Y, e)
		s += m.key.String() <---------------------------------------------------- (ADD)
	}

	return s
}

Expected behavior
see below

Screenshots
With master branch, seeing this. Mouse events are recognized as key events when the terminal gains focus and it can not capture event beyound column 95.
master
With #594, run the same code, everything works well
branch

Additional context
If there are no serious problems, perhaps we can merge this request, which would be significant for Windows Terminal users

@BigJk
Copy link
Contributor

BigJk commented Apr 11, 2023

This PR also fixes a consistent freeze I experience on macos with iterm2 and default macos terminal (#668 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants