-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Add support for application keypad mode (DECKPAM) #16506
Copy link
Copy link
Closed
Labels
Area-VTVirtual Terminal sequence supportVirtual Terminal sequence supportHelp WantedWe encourage anyone to jump in on these.We encourage anyone to jump in on these.In-PRThis issue has a related PRThis issue has a related PRIssue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.Complex enough to require an in depth planning process and actual budgeted, scheduled work.Needs-Tag-FixDoesn't match tag requirementsDoesn't match tag requirementsProduct-ConhostFor issues in the Console codebaseFor issues in the Console codebase
Metadata
Metadata
Assignees
Labels
Area-VTVirtual Terminal sequence supportVirtual Terminal sequence supportHelp WantedWe encourage anyone to jump in on these.We encourage anyone to jump in on these.In-PRThis issue has a related PRThis issue has a related PRIssue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.Complex enough to require an in depth planning process and actual budgeted, scheduled work.Needs-Tag-FixDoesn't match tag requirementsDoesn't match tag requirementsProduct-ConhostFor issues in the Console codebaseFor issues in the Console codebase
Description of the new feature/enhancement
Looking through the old issues, I see I already noted back in #159 that
DECKPAMdidn't appear to be working. I assumed at the time that it was a configuration issue, or possibly a minor bug in the implementation, but I've only realised now that this mode doesn't do anything at all.We do already parse the
DECKPAMandDECKPNMescape sequences, and I even recently added support forDECNKM, which is an alias of that functionality, but the mode doesn't actually have any effect. It switches between two key mapping tables in theTerminalInputclass, but they're essentially identical.This mode is useful because it provides a way for applications to distinguish the keypad keys from the top row numeric keys and arithmetic keys, as well as distinguishing the two Return keys.
Proposed technical implementation details (optional)
If we just want a simple solution, we can probably just update the existing mapping table, although it might be a little more complicated than that to handle the modifiers.
My preferred approach, though, is essentially a rewrite of the
TerminalInputclass, which is something I've been working on for a while. In addition to the application keypad support, it also prepares the way for future VT enhancements, and fixes a bunch of other keyboard issue.The way it works is there's a single keyboard map, that takes a virtual key code combined with Ctrl, Alt, and Shift modifier bits as the key, and the appropiate VT sequence as the value. This map is initially built at startup, and then regenerated whenever a keyboard mode is changed.
That takes care of the "functional" keys (cursor keys, editing keys, function keys, and things like BkSp, Tab, and Return). But if the key-modifier combination is not in that map, I do the following:
If the active keyboard layout has given us a
UnicodeCharvalue, that takes priority. Although that can often still need to be "extended" with a Ctrl modifier that converts the value into a C0 control, and/or an Alt modifier that add anESCprefix.If there isn't a
UnicodeCharvalue, we need to calculate what value the would have been without any Ctrl or Alt modifiers applied (you can do this with theToUnicodeExAPI). And once we have that value, we can then manually apply the Ctrl and Alt modifiers as described above.There are a whole lot of edge cases that also need to be dealt with, but that's the main gist of my proposal.