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

Add enhanced key support for ConPty #5021

Merged
5 commits merged into from
Mar 24, 2020
Merged

Conversation

carlos-zamora
Copy link
Member

@carlos-zamora carlos-zamora commented Mar 19, 2020

Summary of the Pull Request

ConPty did not set the ENHANCED_KEY flag when generating new input. This change helps detect when it's supposed to do so, and sends it.

References

Enhanced Key Documentation

PR Checklist

Detailed Description of the Pull Request / Additional comments

KEY_EVENT_RECORD modifiers VT encodable? Detectable on the way out?
CAPSLOCK_ON No No
ENHANCED_KEY No Yes**
LEFT_ALT_PRESSED Yes* Yes*
LEFT_CTRL_PRESSED Yes* Yes*
NUMLOCK_ON No No
RIGHT_ALT_PRESSED Yes* Yes*
RIGHT_CTRL_PRESSED Yes* Yes*
SCROLLLOCK_ON No No
SHIFT_PRESSED Yes Yes
* We can detect Alt and Ctrl, but not necessarily which one
** Enhanced Keys are limited to the following:
    - off keypad: INS, DEL, HOME, END, PAGE UP, PAGE DOWN, direction keys
    - on keypad: / and ENTER
   Since we can't detect the keypad keys, those will _not_ send the ENHANCED_KEY modifier.
   For the following CSI action codes, we can assume that they are Enhanced Keys:
     case CsiActionCodes::ArrowUp:
     case CsiActionCodes::ArrowDown:
     case CsiActionCodes::ArrowRight:
     case CsiActionCodes::ArrowLeft:
     case CsiActionCodes::Home:
     case CsiActionCodes::End:
     case CsiActionCodes::CSI_F1:
     case CsiActionCodes::CSI_F3:
     case CsiActionCodes::CSI_F2:
     case CsiActionCodes::CSI_F4:
   These cases are handled in ActionCsiDispatch

Validation Steps Performed

Followed bug repro steps. It now matches!

@carlos-zamora
Copy link
Member Author

Can someone verify that the table above is correct? Specifically, the "No?" cells. Because if there is a way to know that, I could go ahead and maybe add them in in this PR.

@DHowett-MSFT
Copy link
Contributor

There's no way for us to pass lock state over VT.

@DHowett-MSFT
Copy link
Contributor

nit: please edit your markdown table to be fully spaced. commit messages don't actually use markdown, and are presented in standard monospace type

Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever and looks like it works well.

@DHowett-MSFT
Copy link
Contributor

Make sure @zadjii-msft signs off.

Please do not automerge this pull request -- the bot will take the single commit message as the merge message and not take into account the PR title or description

@DHowett-MSFT
Copy link
Contributor

Is this testable?

@carlos-zamora
Copy link
Member Author

Is this testable?

I just followed the repro steps from the attached but. Recreated the python script and everything. The output now matches. :)

@DHowett-MSFT
Copy link
Contributor

I meant is this unit-testable 😉

@carlos-zamora
Copy link
Member Author

I meant is this unit-testable 😉

Looks like this would be best tested as a part of #4405, so I'm gonna try and fix that here too.

@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Mar 20, 2020
@j4james
Copy link
Collaborator

j4james commented Mar 21, 2020

There's no way for us to pass lock state over VT.

I'm not sure if you were just referring to our current implementation, but technically it should be possible for us to control the NumLock and CapsLock states via VT sequences if we really wanted to. See DECNUMLK and DECCAPSLK.

@DHowett-MSFT
Copy link
Contributor

Ah! I wasn’t aware of those. Are they intended to be generated by a terminal? I wouldn’t want to contravene best practice.

It’ll be really useful to look at these when we are planning robust key event serialization for Win32 compatibility :)

@j4james
Copy link
Collaborator

j4james commented Mar 21, 2020

Ah! I wasn’t aware of those. Are they intended to be generated by a terminal?

Ah no. These are for the host to report the state to the client. Going in the other direction would probably require DECPCTERM mode I think, and then you're basically just registering the key being pressed rather than reporting the state. Another alternative would be the extended keyboard reports from DECKPM mode, which can give you the CapsLock state (and also the left/right Shift and Alt states), with every keypress.

@zadjii-msft zadjii-msft added Product-Conpty For console issues specifically related to conpty Area-Input Related to input processing (key presses, mouse, etc.) labels Mar 23, 2020
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea these are pretty much all nits

src/terminal/parser/ut_parser/InputEngineTest.cpp Outdated Show resolved Hide resolved
src/terminal/parser/ut_parser/InputEngineTest.cpp Outdated Show resolved Hide resolved
src/terminal/parser/InputStateMachineEngine.cpp Outdated Show resolved Hide resolved
@carlos-zamora carlos-zamora added the AutoMerge Marked for automatic merge by the bot when requirements are met label Mar 24, 2020
@ghost
Copy link

ghost commented Mar 24, 2020

Hello @carlos-zamora!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 403069c into master Mar 24, 2020
@ghost ghost deleted the dev/cazamor/conpty/enhanced-key branch March 24, 2020 19:46
@nwillems94
Copy link

nwillems94 commented Mar 24, 2020

Thanks for the good work! When should users expect to see these changes? Are ConPty updates pushed through Windows Update?

@zadjii-msft
Copy link
Member

@nwillems94 If you're using the Windows Terminal, you'll get this update on the next release of the Windows Terminal ☺️

If you're still using the vintage console, then yea, you'll need to wait for a Windows Update. Conpty is actually just conhost.exe. If you're on Insiders, these updates usually take about a month after when they're checked in here. If you're not, then I honestly have no idea how long it is till the update that will come after 2004(the Windows build, not the year).

DHowett-MSFT pushed a commit that referenced this pull request Apr 21, 2020
Improve wide glyph support in UIA (GH-4946)
Add enhanced key support for ConPty (GH-5021)
Set DxRenderer non-text alias mode (GH-5149)
Reduce CursorChanged Events for Accessibility (GH-5196)
Add more object ID tracing for Accessibility (GH-5215)
Add SS3 cursor key encoding to ConPty (GH-5383)
UIA: Prevent crash from invalid UTR endpoint comparison (GH-5399)
Make CodepointWidthDetector::GetWidth faster (CC-3727)
add til::math, use it for float conversions to point, size (GH-5150)
Add support for renderer backoff, don't FAIL_FAST on 3x failures, add UI (GH-5353)
Fix a deadlock and a bounding rects issue in UIA (GH-5385)
Don't duplicate spaces from potentially-wrapped EOL-deferred lines (GH-5398)
Reimplement the VT tab stop functionality (CC-5173)
Clamp parameter values to a maximum of 32767. (CC-5200)
Prevent the cursor type being reset when changing the visibility (CC-5251)
Make RIS switch back to the main buffer (CC-5248)
Add support for the DSR-OS operating status report (CC-5300)
Update the virtual bottom location if the cursor moves below it (CC-5317)
ci: run spell check in CI, fix remaining issues (CC-4799) (CC-5352)
Set Cascadia Code as default font (GH-5121)
Show a double width cursor for double width characters (GH-5319)
Delegate all character input to the character event handler (CC-4192)
Update til::bitmap to use dynamic_bitset<> + libpopcnt (GH-5092)
Merged PR 4465022: [Git2Git] Merged PR 4464559: Console: Ingest OSS changes up to e055079
Correct scrolling invalidation region for tmux in pty w/ bitmap (GH-5122)
Render row-by-row instead of invalidating entire screen (GH-5185)
Make conechokey use ReadConsoleInputW by default (GH-5148)
Manually pass mouse wheel messages to TermControls (GH-5131)
This fixes C-M-space for WSL but not for Win32, but I'm not sure there's a problem in Win32 quite yet. (GH-5208)
Fix copying wrapped lines by implementing better scrolling (GH-5181)
Emit lines wrapped due to spaces at the end correctly (GH-5294)
Remove unneeded whitespace (CC-5162)
@ghost
Copy link

ghost commented Apr 22, 2020

🎉Windows Terminal Preview v0.11.1121.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) AutoMerge Marked for automatic merge by the bot when requirements are met Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConPTY does not translate arrow keys with +ENHANCED_KEY in their modifiers
5 participants