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 support for DECBKM (Backarrow Key Mode) #13894

Merged
5 commits merged into from
Sep 6, 2022
Merged

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Aug 31, 2022

This PR adds support for the DECBKM sequence, which provides a way for
applications to specify whether the Backspace key should generate a
BS character or a DEL character.

On the original VT100 terminals, the Backarrow key generated a BS,
and there was a separate Delete key that generated DEL. However, on
the VT220 and later, there was only the Backarrow key. By default it
generated DEL, but from the VT320 onwards there was an option to make
it generate BS, and the DECBKM sequence provided a way to control
that behavior programmatically.

On modern terminals, the Backspace key serves as the equivalent of the
VT Backarrow, and typically generates DEL, while Ctrl+Backspace
generates BS. When DECBKM is enabled (for those that support it),
that behavior is reversed, i.e. Backspace generates BS and
Ctrl+Backspace generates DEL.

This PR also gets the other Backspace modifiers more closely aligned
with the expected behavior for modern terminals. The Shift modifier
typically has no effect, and the Alt modifier typically prefixes the
generated sequence with an ESC character.

While not strictly related to DECBKM, I noticed while testing that the
_SetInputMode method was doing unnecessary work that was specific to
the FocusEvent mode. I've now moved that additional processing into
the EnableFocusEventMode method, which I think makes things somewhat
simpler.

Validation Steps Performed

I've tested the basic DECBKM functionality in Vttest, and I've
manually tested all the modifier key combinations to make sure they
match what most modern terminals generate.

I've also added a unit test that confirms that the expected sequences
are generated correctly when the DECBKM mode is toggled.

Closes #13884

@ghost ghost added Issue-Task It's a feature request, but it doesn't really need a major design. Product-Conhost For issues in the Console codebase labels Aug 31, 2022
// GH#12799 - If the app requested that we disable focus events, DON'T pass
// that through. ConPTY would _always_ like to know about focus events.

return !_api.IsConsolePty() ||
!_api.IsVtInputEnabled() ||
(!enable && mode == TerminalInput::Mode::FocusEvent);

// Another way of writing the above statement is:
//
// const bool inConpty = _api.IsConsolePty();
// const bool shouldPassthrough = inConpty && _api.IsVtInputEnabled();
// const bool disabledFocusEvents = inConpty && (!enable && mode == TerminalInput::Mode::FocusEvent);
// return !shouldPassthrough || disabledFocusEvents;
//
// It's like a "filter" left to right. Due to the early return via
// !IsConsolePty, once you're at the !enable part, IsConsolePty can only be
// true anymore.
return !_api.IsConsolePty() || !_api.IsVtInputEnabled();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note to reviewers, if you didn't read the PR description, the additional check here that was specific to the FocusEvent mode has now been moved down into the EnableFocusEventMode method. I think this reduces some of the confusion that was introduced here, and also avoids unnecessary overhead in the other input mode operations.

This is isn't strictly related to DECBKM mode, though (other than as a minor optimisation), so if you'd prefer not to include this change in the PR, it wouldn't be a problem to revert it.

Copy link
Member

Choose a reason for hiding this comment

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

This makes way more sense. Thanks!

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

Not a single complaint. Thank you!

// GH#12799 - If the app requested that we disable focus events, DON'T pass
// that through. ConPTY would _always_ like to know about focus events.

return !_api.IsConsolePty() ||
!_api.IsVtInputEnabled() ||
(!enable && mode == TerminalInput::Mode::FocusEvent);

// Another way of writing the above statement is:
//
// const bool inConpty = _api.IsConsolePty();
// const bool shouldPassthrough = inConpty && _api.IsVtInputEnabled();
// const bool disabledFocusEvents = inConpty && (!enable && mode == TerminalInput::Mode::FocusEvent);
// return !shouldPassthrough || disabledFocusEvents;
//
// It's like a "filter" left to right. Due to the early return via
// !IsConsolePty, once you're at the !enable part, IsConsolePty can only be
// true anymore.
return !_api.IsConsolePty() || !_api.IsVtInputEnabled();
Copy link
Member

Choose a reason for hiding this comment

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

This makes way more sense. Thanks!

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Sep 6, 2022
@ghost
Copy link

ghost commented Sep 6, 2022

Hello @DHowett!

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 276405a into microsoft:main Sep 6, 2022
@ghost
Copy link

ghost commented Sep 13, 2022

🎉Windows Terminal Preview v1.16.252 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
AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for DECBKM (Backarrow Key Mode)
3 participants