gum
gum copied to clipboard
On Windows, ENABLE_VIRTUAL_TERMINAL_INPUT flag remains set in console
Describe the bug
After running any gum command, input (stdin) in Windows terminal is left in odd state, whether running in the CMD terminal or the new Windows Terminal (wt.exe). For example, the arrow keys no longer work. Instead they return their corresponding ANSI escape sequences (eg ^[[A
). Running the clear
command will reset the terminal back to normal.
The problem appears to be related to the way the SetConsoleMode
(https://docs.microsoft.com/en-us/windows/console/setconsolemode) is being set for stdin. It appears that ENABLE_VIRTUAL_TERMINAL_INPUT
flag is being set for stdin but not being reset/removed.
Running the following piece of code in python, to access the Windows API resets the terminal:
def _reset_stdin(self):
"""
Remove ENABLE_VIRTUAL_TERMINAL_INPUT flag in stdin set by gum
(via Win32 SetConsoleMode() call)
"""
if __import__("platform").system() == "Windows":
kernel32 = __import__("ctypes").windll.kernel32
consoleFlagsInput = 64 + 32 + 4 + 2 + 1
kernel32.SetConsoleMode(kernel32.GetStdHandle(-10), consoleFlagsInput)
del kernel32
Here -10
is the STD_INPUT_HANDLE
according to https://docs.microsoft.com/en-us/windows/console/getstdhandle
To Reproduce Steps to reproduce the behavior:
- run any gum command in the standard dos terminal. eg
gum choose one two three
- after command has completed, press the arrow keys. ansi escape sequence appears in stdout instead
- pressing backspace removes the entire word instead of single character
Expected behavior The terminal, in particular the stdin, under windows should remain the same as prior to running gum command.
Desktop (please complete the following information):
- OS: Windows 10
- Browser n/a
- Version gum version v0.3.0 (c049d1a)
Additional context Add any other context about the problem here.
Similar issues with 0.4.0.
This should be fixed by https://github.com/charmbracelet/bubbletea/pull/565 as soon as we merge & bump the bubbletea dependency in gum.
When do you think an update would be available?
Hey do you think this is the same issue as in this video? Once returned from gum, arrow keys print what you see and ctrl+c
etc don't work anymore
https://user-images.githubusercontent.com/7041726/205449396-8cf7182a-b3af-40fa-a226-7770c7daaf47.mp4
Edit: I just tried on gum version v0.8.1-0.20221118011134-eb3c5c1037a5
(main) and it still occurs
Yes, it appears to be the same issue. It appears to be a bug in one of the dependencies gum.exe
relies on.