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 the S8C1T/S7C1T escape sequences #17945

Merged

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Sep 21, 2024

This PR adds support for the S8C1T and S7C1T commands, which enable
an application to choose whether the terminal should use C1 controls
when sending key sequences and query responses.

This also updates the DOCS command to set both the input and output
code pages. So when switched to ISO2022 mode, the C1 controls will be
transmitted as 8-bit, which is what legacy systems would be expecting.

Detailed Description of the Pull Request / Additional comments

While adding the input code page support, I also reworked the way we
handle the code page reset in RIS. In the original implementation we
saved the active code page when the DOCS sequence was first used, and
that would become the default value for a reset.

With this PR I'm now saving the code pages whenever SetConsoleCP or
SetConsoleOutputCP is called, so those APIs now control what the
default values will be. This feels more consistent than the previous
approach. And this is how WSL sets its initial code page to UTF-8.

Validation Steps Performed

I've added a couple of unit tests that check one of each applicable C1
control in the key sequences and query reports.

I also built myself a code page aware telnet client so I could log into
WSL in 8-bit mode, and confirmed that the C1 transmissions are working
as expected in vttest.

Closes #17931
Tests added/passed

@microsoft-github-policy-service microsoft-github-policy-service bot added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Sep 21, 2024
@j4james j4james marked this pull request as ready for review September 26, 2024 13:15
@microsoft-github-policy-service microsoft-github-policy-service bot added Area-VT Virtual Terminal sequence support Product-Terminal The new Windows Terminal. labels Sep 26, 2024
Comment on lines 231 to 232
if (IsValidCodePage(codepage))
{
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why we should check this outside the two set functions? I think it may be safer if it was inside them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It just seemed a little more efficient, but that's not really important here. I've moved the checks back into the DoSrvSet* functions now.

src/terminal/parser/stateMachine.cpp Show resolved Hide resolved
Comment on lines -65 to 66
const auto codepage = _api.GetConsoleOutputCP();
const auto codepage = _api.GetOutputCodePage();
InputEventQueue keyEvents;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to mention that I noticed we're using the output code page here to generate input events, which seemed wrong to me. Was that intentional?

That codepage is only used if the UseNumpadEventsForClipboardInput feature is enabled (which doesn't appear to be the case), so I don't think it's breaking anything at the moment, but it's still worth fixing if it's incorrect.

Copy link
Member

Choose a reason for hiding this comment

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

That's an excellent question. Personally I'm not sure, though I suspect that it was an oversight.

UseNumpadEvents... was a last minute "don't break Windows conhost users right before a big release" feature flag, which we should almost certainly just remove now... :)

_api.ReturnResponse(fmt::format(FMT_COMPILE(L"{}{}{}"), dcs, response, st));
}

void AdaptDispatch::_ReturnOscResponse(const std::wstring_view response) const
Copy link
Member

Choose a reason for hiding this comment

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

Thought: Xterm specifies that OSC responses are returned with the same terminator (ST or BEL) as the request that generated them. I suppose having this function affords us a much easier way to find/fix all occurrences of us being out of spec :)

    XTerm accepts either BEL  or ST  for terminating OSC
    sequences, and when returning information, uses the same
    terminator used in a query.  While the latter is preferred,
    the former is supported for legacy applications:
    o   Although documented in the changes for X.V10R4 (December
        1986), BEL  as a string terminator dates from X11R4
        (December 1989).
    o   Since XFree86-3.1.2Ee (August 1996), xterm has accepted ST
        (the documented string terminator in ECMA-48).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I really hate that BEL terminator, but you're right, we should be responding with BEL if the query was terminated with BEL.

@lhecker lhecker added the AutoMerge Marked for automatic merge by the bot when requirements are met label Oct 7, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit aa256ad into microsoft:main Oct 7, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for the S8C1T/S7C1T escape sequences
3 participants