peterbrittain / asciimatics

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getting a KEY_ESC event when resizing pycharm terminal

eyaler opened this issue · comments

widnows 10, asciimatics 1.13.0, python 3.9.5

I am running Screen.wrapper in pycharm (either by using Emulate terminal option OR by using the terminal tab and running python.exe). After resizeing the terminal window a few times, i get a KEY_ESC keyboard event. that is a KeyboardEvent event with key_code=-1. I am not sure if this is a pycharm or asciimatics issue, however i was not able to get such an escape key event on resize when not using asciimatics.

debugging further i added in screen.py:

event = self._stdin.ReadConsoleInput(1)[0]
                if event.EventType == win32console.KEY_EVENT:
                    print(ord(event.Char)) ### added for dubug

add i am seeing 13 followed by 27 on these resizes. however if i just run input() in the terminal i do not seem to get such key events.

Hmmm... Kinda struggling with this one... All asciimatics does is read the input queue and convert it. The fact that it is actually returned by ReadConsoleInput means something is injecting that input - either pycharm or the user (e.g. partial keypress that pycharm routes to its terminal).

Can you reproduce in a normal console window? If not, I think this is a pycharm bug...

i could not reproduce on a normal console. maybe its a pycharm windows api issue. also if we are on the subject of pycharm terminal... automatic scroll to start on screen.refresh does not work when the terminal is docked and also the height is sometimes wrong when the terminal is docked (so line y=0 may not be in view). undocking the terminal fixes this. i am not sure if you want to deal with these things... if so i can open new issues

Sorry, but the pycharm terminal is not a pure Windows command window/terminal, and shouldn't be used for production, so I don't have any plans to work around their emulation bugs.

Was intrigued to know why this happened, so dug a little more... PyCharm uses pty4j, which uses winpty tocreate the console window (i.e. terminal in PyCharm). That last package does various things to manipulate the console.

In particular, it has this code to freeze/unfreeze the console output (https://github.com/rprichard/winpty/blob/7e59fe2d09adf0fa2aa606492e7ca98efbc5184e/src/agent/Win32Console.cc#L91). Call me suspicious, but that is injecting an escape key into the Window... which asciimatics then detects.

Definitely an interop issue with that package, so I'm going to close this now.

thanks! injecting ENTER + ESC it seems... maybe this should be mentioned in the pycharm terminal documentation. i was hitting this when i mapped ESC to quit program, so it was quite an issue having my program exit on window resize...

Good point. That belongs in the troubleshooting docs.