-
Notifications
You must be signed in to change notification settings - Fork 165
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-based selection stops working after using the mouse in an app. #493
Comments
@chhackett - could it be that mouse mode state is not being restored / deactivated? |
I did some testing using vty-mode-demo. I reproduced the problem in WT. Noticed there is no problem in a bare cmd window. In both cases, the mouse mode enabled/disabled sequences are emitted as expected when the app starts/ends. But there is a slight difference in the escape sequences sent to the output. Not sure what that has to do with mucking up the mouse select. And I'm not sure why that happens. But apparently, in WT, mouse mode is not disabled when the vty app shuts down. If I run vty-mode-demo a second time, mouse mode is enabled without me toggling it on. Somehow WT is ignoring the mouse disable sequences that are emitted on shutdown. I'll look at it more later this week. |
Thanks, @chhackett! |
Another instance of the same problem - I spend all day trying to understand why we lose mouse events upon the app exit, to no avail for now. |
Yeah, I've spent at least 5 or 6 hours on it so far, and I'm no closer to understanding it. But like you said, we can put in a workaround. I might just do that as a temporary solution and just open another issue on vty-windows to fix it the right way. |
What’s confusing to me about this Is that the image shows that mouse mode is getting left enabled on exit. The mouse selection behavior shows that mouse mode is disabled before the program runs, and left enabled when it exits, thus interfering with the normal selection behavior. I mention this because my interpretation doesn’t line up with some of the discussion above - and it leaves me really confused about why explicitly enabling mouse mode on exit would have the desired effect, since I would expect the opposite to be true. |
@jtdaugherty I think that's a issue of definitions. One might say that "mouse is enabled" in a (regular) terminal if mouse scrolling and mouse selection works. Or one might say that "mouse is enabled" if terminal passes mouse events to the currently running program. @chhackett I have an idea - IIRC, you implemented a hack for FocusEvents regarding "Focus events are still sent even if there were told to disappear" in chhackett/vty-windows#1 I think that we are facing the same problem here, but for MouseEvents.
|
@ShrykeWindgrace in general I agree, but there is already a definition in use here: the Vty API uses In other terminal emulators, the behavior is the same: when mouse mode is disabled, that means it is disabled from the perspective of the application, meaning the emulator will do what it wants with mouse events (e.g. perform text selection). But when it is enabled, mouse events are passed to the running terminal application and the emulator does not handle the events. That behavior is consistent with how the Vty API works. |
So I tried @ShrykeWindgrace solution to emit the 'reset terminal' sequence on shutdown. But like you said, it resets everything, including the screen. So it replaces one bug with another. What is so annoying about this is that mouse behaves correctly in the terminal emulator if I manually toggle mouse mode to disabled (ie. setMode .. Mouse False), and then exit the application. In both cases (manually change mouse mode to False or the application changing the mouse mode as part of the 'releaseTerminal' IO action) the mouse mode disable sequence is emitted to the output. I'm guessing the difference in behavior might have something to do with the order or timing of sequences being sent to the output on shutdown. But I could be wrong. Anyway, I have a few more ideas to test... |
OK, I finally figured it out. It is an order of events issue. On shutdown, vty does:
Unfortunately, calling shutdownInput first in the windows version calls the Windows API to reset the 'virtual terminal input' mode to False. So Windows was then ignoring the subsequent calls to reset mouse mode (which are obviously VT sequences). So I just re-ordered the shutdown sequence to:
and mouse mode successfully resets now. Sorry for the long wait... |
That's great news, congrats on tracking this down! |
Version 0.2.0.1 of vty-windows is released. |
@madsbangh can you upgrade and confirm? Then we'll close this. |
@chhackett that's quite a find! Thanks a lot! |
@jtdaugherty This is awesome news! Well done @chhackett and all! I will verify it on my end later today <3 |
@jtdaugherty ✅ I ran After quitting the demo app, I now regain the ability to select with my mouse etc in the Windows terminal as expected :) |
Great, thanks! |
(Reproduced on Microsoft Windows Terminal)
When I run
cabal -fdemos run brick-viewport-scrollbars-demo
any subsequent mouse-based selection of text in the terminal window stops working.Below you can see a gif of the reproduction.
![brick-vty-mouse-bug](https://private-user-images.githubusercontent.com/2969321/282296832-81f074f7-0810-4cdb-9d3c-1b28f12b97d0.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk1MzI4MTksIm5iZiI6MTcxOTUzMjUxOSwicGF0aCI6Ii8yOTY5MzIxLzI4MjI5NjgzMi04MWYwNzRmNy0wODEwLTRjZGItOWQzYy0xYjI4ZjEyYjk3ZDAuZ2lmP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjdUMjM1NTE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTAxZTA5YmZkZmJiNjE1ZDIyZjk0YTdjMWUyYWQxYzAxYTg3MmRiODI1MzczOTFjNjI4YzMzYmIwODliNGI5ZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.GRuciq6wvk2DJvR_Hhn9hvxI3lenZqeU-HNGAvIW3DI)
I am unsure if this is an issue in Vty or Brick, but I am not sure I am experienced enough to verify it myself.
Thanks, and I hope this helps :)
The text was updated successfully, but these errors were encountered: