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

Add an option to temporarily disable mouse input #3898

Closed
jose1711 opened this issue Dec 18, 2023 · 13 comments
Closed

Add an option to temporarily disable mouse input #3898

jose1711 opened this issue Dec 18, 2023 · 13 comments

Comments

@jose1711
Copy link
Contributor

I would like to have an option to temporarily stop handling of mouse events by Textual. Use case would be a user which is used to paste input into terminal using right-click (PuTTY) and an application with a single Input widget.

The application would disable handling of mouse events (application mode) temporarily while Input is in focus.

I tried commenting self._enable_mouse_support() in linux_driver.py during experimenting but that did not work.

@TomJGooding
Copy link
Contributor

I think something like the below should work, although probably not recommended as it uses Textual internals. This is untested though as my terminal doesn't paste on mouse click.

from textual.app import App, ComposeResult
from textual.widgets import Button, Input


class CustomInput(Input):
    def on_focus(self) -> None:
        self.app._driver._disable_mouse_support()  # type: ignore
        self.notify("Mouse support disabled")

    def on_blur(self) -> None:
        self.app._driver._enable_mouse_support()  # type: ignore
        self.notify("Mouse support enabled")


class ExampleApp(App):
    def compose(self) -> ComposeResult:
        yield CustomInput()
        yield Button("Reset Focus")


if __name__ == "__main__":
    app = ExampleApp()
    app.run()

@jose1711
Copy link
Contributor Author

@TomJGooding Thank you, your solution works - tested with Windows 10 and PuTTY/MobaXterm. I would still like to see a public method that would allow to achieve the same.

@Textualize Textualize deleted a comment from github-actions bot Dec 19, 2023
@rodrigogiraoserrao
Copy link
Contributor

Hey @jose1711, just to see if I understand correctly, you want Textual to stop handling events and to let the terminal handle them instead, right?

@jose1711
Copy link
Contributor Author

Hey @jose1711, just to see if I understand correctly, you want Textual to stop handling events and to let the terminal handle them instead, right?

If that means that Textual ignores mouse clicks but still receives key presses, then the answer is yes.

@willmcgugan
Copy link
Collaborator

What are you pasting that is causing a problem? Help us to understand the issue you are solving here. You may want to read https://label.dev/articles/xy-problem/

Most terminals support "bracketed paste mode", which means you can paste without having the terminal interpret escape sequences.

@TomJGooding
Copy link
Contributor

@willmcgugan I think you might want to read the original issue post again. The use case is stated quite plainly and I don't understand how "bracketed paste mode" is relevant here?

@willmcgugan
Copy link
Collaborator

The OP was asking about pasting in to an input, which AFAIK works fine, and uses bracketed paste mode.

Reading between the lines, if the context menu is not appearing, it might be because you need to press a modifier in application mode. Like ctrl or alt.

I can't recommend mouse support as it will break user expectations.

@TomJGooding
Copy link
Contributor

Good point about perhaps just needing a modifier!

@jose1711 - could you confirm if shift+right-click works in application mode to paste?

@rodrigogiraoserrao
Copy link
Contributor

@jose1711
Copy link
Contributor Author

@willmcgugan thanks for the link on the XY problem. I'll strive to enhance my descriptions accordingly.

Let me share a complete story. I utilized Textual to develop a small application for the support team within our company. Thanks to Textual, the development process was incredibly enjoyable, resulting in an application that surpasses the visual appeal of a standard shell script.

Upon launching the program, users are prompted to enter a hostname. These hostnames can vary, with differences sometimes as subtle as a single letter (e.g., 'b' instead of 'd'). As users aim to avoid typos and expedite the process, they often prefer to paste hostnames from the clipboard.

The majority of our users come from a Windows environment, where PuTTY serves as their primary tool for interacting with the Linux/Unix world. They've learned that right-clicking facilitates pasting, and instinctively try it in our application, only to encounter no response. This leads to the assumption that something is malfunctioning. Although the application mentions the use of Shift+Ins for pasting, altering user habits can be challenging, especially in time-sensitive scenarios where documentation is not thoroughly read.

To address the need for pasting a single line of input and pressing Return, I'm considering suspending the output, as suggested by @TomJGooding . If you feel this use case is too specialized to deserve an implementation in a form of public method, I completely understand and will continue using the internal (private) method calls.

@jose1711
Copy link
Contributor Author

shift+right-click work

@TomJGooding Indeed, it does. However, as mentioned in my more detailed description, it may 'feel' broken to less experienced users - especially those who find reading the manual a bit challenging.

@willmcgugan
Copy link
Collaborator

Closing as there doesn't seem to be much demand, and I'm not convinced it is a good idea.

@willmcgugan willmcgugan closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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

No branches or pull requests

4 participants