zephyrproject-rtos / windows-curses

Windows Curses Python module
https://pypi.org/project/windows-curses/
Other
164 stars 26 forks source link

Arrow keys not read by python in integrated terminal of vscode. #23

Closed ChrisIdema closed 11 months ago

ChrisIdema commented 3 years ago

windows-curses doesn't work properly in the integrated terminal of vscode since at least December 2020. Arrowkeys are not detected. For more details: https://github.com/microsoft/vscode/issues/112405

I think it is an issue with vscode, but they blame it on an extension (even with all extensions disabled). The only thing other than vscode would be the curses library itself. So it would be great if we can get to the bottom of this.

ChrisIdema commented 3 years ago

Update. Problem still persists. Versions:

I think the integrated terminal changes key codes and wgetch doesn't capture them correctly. I don't know who is at fault.

boardkeystown commented 2 years ago

@ChrisIdema are you able to get windows-curses to lint at all in vscode?

Spent hours trying different things. Have no clue why it vscode does not think curses there there. Even though curses code will run. It just does not lint.

ChrisIdema commented 2 years ago

@boardkeystown It's been a while since I visited this issue (although it is still on my mind). I have no idea how to debug this. I don't know what you mean by lint. Can you explain?

boardkeystown commented 2 years ago

@ChrisIdema of crouse. I mean the auto complete in vscode. When I import curses the linter does not work. Meaning after

import curses

You do get any dot function drop downs or comments. So you can't figure out what methods you have available to you while you use curse. Meaning I have to keep looking up the documentation... But the script seems to run fine. It's rather annoying

ChrisIdema commented 1 year ago

Update. Problem still persists. Versions:

Python 3.9.13
Vscode 1.71.2
windows_curses 2.3.0
kconfiglib 14.1.0
Windows 10

How to test? Run python3 snake.py or menuconfig in VSCode integrated terminal. Arrow keys are not processed by windows-curses in VSCode's integrated terminal, but curses under Ubuntu does process it in VSCode's integrated terminal.

I tried building windows-curses so I could debug it, but I get compile errors:

LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
_cursesmodule.obj : error LNK2001: unresolved external symbol __imp__PyUnicode_AsEncodedString
AntonBogun commented 1 year ago

I'm trying to use curses and I'm having the same problem. I've noticed that shift+arrow keys actually end up printing numbers, which leads me to believe something is broken with how curses+vscode console is reading the state of numlock, and thus falsely thinks that it is on, therefore returning the key values for numpad rather than actual arrows.

ChrisIdema commented 11 months ago

Update. Problem is fixed! Versions:

Python  3.11.4 
Vscode 1.82.3
windows_curses 2.3.1
kconfiglib 14.1.0
Windows 11

Both python3 snake.py and idf.py menuconfig work in integrated terminal (cmd or powershell) in Vscode. I wonder in which version it was fixed and why it took 2.5 years. But I'm happy I finally have full terminal functionality with arrow keys in Vscode in Windows.

lokzz commented 6 months ago

according to this issue on the vscode github, the issue was caused by vscode's terminal's backend, which is conpty.

apparently, this issue was fixed somewhere inbetween windows 10 and 11. (conpty is shipped with windows)

ChrisIdema commented 6 months ago

@lokzz Thank you for explaining! I was glad the issue was fixed, but it always bugged me that I didn't know what the cause was. I never even heard of conpty.