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

Regression: mouse support broken in Visual Studio Code terminal #5547

Closed
davidfokkema opened this issue Feb 17, 2025 · 15 comments · Fixed by #5549 or #5551
Closed

Regression: mouse support broken in Visual Studio Code terminal #5547

davidfokkema opened this issue Feb 17, 2025 · 15 comments · Fixed by #5549 or #5551

Comments

@davidfokkema
Copy link

Mouse support is broken in the VS Code terminal. When you click on a widget, that widget is not focused. Worse, if it was focused using keyboard shortcuts, it will be blurred. It turns out that the mouse coordinates are incorrectly calculated and that if you move your mouse over the top-left corner of the terminal, the reported mouse coordinates cover the entire area. So the exact top-left is reported as (0.0, 0.0, but if you move a bit to the right and a bit down it already reports (17.0, 12.0) and so on.

I ran a git bisect and the offending commit is (unsurprisingly) 9f18dfe (smooth scrolling). I tested using this code:

from textual import on
from textual.app import App, ComposeResult
from textual.events import MouseMove
from textual.widgets import RichLog


class MouseMoveApp(App[None]):
    def compose(self) -> ComposeResult:
        yield RichLog(markup=True)

    @on(MouseMove)
    def record_mouse_position(self, event: MouseMove) -> None:
        self.query_one(RichLog).write(event)


MouseMoveApp().run()

I ran textual diagnose in that same terminal:

<!-- This is valid Markdown, please paste the following directly in to a GitHub issue -->
# Textual Diagnostics

## Versions

| Name    | Value  |
|---------|--------|
| Textual | 2.0.1  |
| Rich    | 13.9.4 |

## Python

| Name           | Value                                                           |
|----------------|-----------------------------------------------------------------|
| Version        | 3.13.2                                                          |
| Implementation | CPython                                                         |
| Compiler       | Clang 16.0.0 (clang-1600.0.26.6)                                |
| Executable     | /Users/david/work/software/playground-textual/.venv/bin/python3 |

## Operating System

| Name    | Value                                                                                                 |
|---------|-------------------------------------------------------------------------------------------------------|
| System  | Darwin                                                                                                |
| Release | 24.3.0                                                                                                |
| Version | Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020 |

## Terminal

| Name                 | Value           |
|----------------------|-----------------|
| Terminal Application | vscode (1.97.2) |
| TERM                 | xterm-256color  |
| COLORTERM            | truecolor       |
| FORCE_COLOR          | *Not set*       |
| NO_COLOR             | *Not set*       |

## Rich Console options

| Name           | Value                |
|----------------|----------------------|
| size           | width=123, height=27 |
| legacy_windows | False                |
| min_width      | 1                    |
| max_width      | 123                  |
| is_terminal    | False                |
| encoding       | utf-8                |
| max_height     | 27                   |
| justify        | None                 |
| overflow       | None                 |
| no_wrap        | False                |
| highlight      | None                 |
| markup         | None                 |
| height         | None                 |
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@davidfokkema
Copy link
Author

I tested on macOS with 1.97.2 (broken) and Windows with 1.96.2 (working fine!) and 1.97.2 (also fine). So the problem seems limited to macOS.

@willmcgugan
Copy link
Collaborator

I see the issue. It is a bug in Textual. Fix incoming.

@davidfokkema
Copy link
Author

That is very nice, thanks!

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@davidfokkema
Copy link
Author

Works as a charm, thank you very much!

@dmakhno
Copy link

dmakhno commented Feb 17, 2025

2.0.4 did not helped me for iterm + ssh tunnel.
Mac + ITerm2 (v3.5.11)
python -m textual - controls are not clickable

pip install textual==1.0.0
same tutorial works fine.

Without ssh tunnel - everything is fine. Not sure how to troubleshoot the ssh.

iterm
ssh somewhere
pip install -U textual  # 2.0.4
python -m textual

Note: ssh somewhere 'python -m textual' never worked for me. No idea what is difference.

@willmcgugan , is it the same issue or should I report new one?

@davidfokkema
Copy link
Author

I can confirm on my Raspberry Pi. VS Code + ssh works fine, Ghostty + ssh works fine, iTerm2 + ssh is broken in a very similar fashion to the original issue with the VS Code terminal.

@willmcgugan
Copy link
Collaborator

When you SSH, what does the env var TERM_PROGRAM contain?

@dmakhno
Copy link

dmakhno commented Feb 17, 2025

@willmcgugan

root@somewhere:~# env | grep TERM
LC_TERMINAL=iTerm2
TERM=xterm-256color
LC_TERMINAL_VERSION=3.5.11

this value - does not exist for me, under ssh.

vs localhost

dmakhnom@my-MacBook-Pro % env | grep TERM
TERM_SESSION_ID=w0t1p0:F65E6C11-xxxx-xxx-8F23-9B422FAF16FA
LC_TERMINAL_VERSION=3.5.11
ITERM_PROFILE=Default
TERM_FEATURES=T3LrMSc7UUw9Ts3BFGsSyHNoSxF
TERM_PROGRAM_VERSION=3.5.11
TERM_PROGRAM=iTerm.app
LC_TERMINAL=iTerm2
COLORTERM=truecolor
TERM=xterm-256color
TERMINFO_DIRS=/Applications/iTerm.app/Contents/Resources/terminfo:/usr/share/terminfo
ITERM_SESSION_ID=w0t1p0:F65E6C11-xxxx-xxxx-8F23-9B422FAF16FA

@davidfokkema
Copy link
Author

davidfokkema commented Feb 17, 2025

I'm afraid export | grep TERM only shows the TERM variable.

@davidfokkema
Copy link
Author

But the LC_TERMINAL variable is indeed available in my SSH environment.

@willmcgugan
Copy link
Collaborator

Looks like an easy fix. Just need to detect iTerm via LC_TERMINAL

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@davidfokkema
Copy link
Author

Can confirm that mouse support on SSH over iTerm2 works again! 🎉

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.

3 participants