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

How should applications behave when running under Windows Terminal if they want to maximize functionality? #18127

Open
marchelzo opened this issue Oct 30, 2024 · 1 comment
Labels
Issue-Question For questions or discussion Needs-Discussion Something that requires a team discussion before we can proceed Needs-Tag-Fix Doesn't match tag requirements

Comments

@marchelzo
Copy link

Hi, I'm working on a cross-platform readline-esque library and one of the goals is to take full advantage of the capabilities of whatever terminal emulator is being used.

From what I understood reading the Console API docs on MSDN, Windows Terminal seems to be trying to move away from the Win32 Console API and behave more like terminals on other platforms, supporting various CSI and DCS escape sequences etc., but I have some questions:

  • Since termios and ioctl don't exist in Windows, do we still use the Console API for things like getting Windows Terminal out of line-input mode, or requesting the window size?

  • I made a small test program which sets the console mode to ENABLE_VIRTUAL_TERMINAL_INPUT | ENABLE_PROCESSED_INPUT and then reads KEY_EVENT_RECORDs using ReadConsoleInputA(). Under conhost.exe, the KeyEvent.dwControlKeyState field seems to be populated correctly, but under Windows Terminal it's always zero. Is there a way for applications to handle arbitrary keyboard input in Windows Terminal? If not, what approach should we be using to handle a many different key events as possible?

Sorry if this is all documented somewhere and I missed it. Any links to further reading would be appreciated!

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Oct 30, 2024
@carlos-zamora carlos-zamora added Needs-Discussion Something that requires a team discussion before we can proceed Issue-Question For questions or discussion and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Oct 30, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Tag-Fix Doesn't match tag requirements label Oct 30, 2024
@lhecker
Copy link
Member

lhecker commented Nov 4, 2024

Since termios and ioctl don't exist in Windows, do we still use the Console API for things like getting Windows Terminal out of line-input mode, or requesting the window size?

Yes. For anything where there's a VT equivalent, I'd try to use VT, but otherwise the console APIs are just fine.

Under conhost.exe, the KeyEvent.dwControlKeyState field seems to be populated correctly, but under Windows Terminal it's always zero.

If there's a behavior difference between conhost and Windows Terminal, I'd consider that a bug. But not necessarily a bug in Windows Terminal: When you request ENABLE_VIRTUAL_TERMINAL_INPUT we'll give you an UNIX-style stdin that cannot for instance represent pressing a modifier key (Ctrl/Shift/Alt) on its own without pressing another key. As such the dwControlKeyState should always be 0. If your goal is to be cross-platform I'd personally recommend not trying to make these Windows-specific features available.

I'm not sure how familiar you are with ENABLE_PROCESSED_INPUT but if you need some documentation about how modifier-key combinations are represented there you can read this, for instance: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Special-Keyboard-Keys
(There's a ton of other sources out there as well.)

FYI: If you'd like to be performant, please try to avoid emitting small stdout writes as much as possible. The overhead of small writes on Windows is a lot higher than on Linux/macOS (large writes are unaffected).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question For questions or discussion Needs-Discussion Something that requires a team discussion before we can proceed Needs-Tag-Fix Doesn't match tag requirements
Projects
None yet
Development

No branches or pull requests

3 participants