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

Default all G-sets to ASCII unless ISO-2022 is requested #11658

Merged
1 commit merged into from Nov 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/terminal/adapter/terminalOutput.cpp
Expand Up @@ -10,10 +10,16 @@ using namespace Microsoft::Console::VirtualTerminal;

TerminalOutput::TerminalOutput() noexcept
{
// By default we set all of the G-sets to ASCII, so if someone accidentally
// triggers a locking shift, they won't end up with Latin1 in the GL table,
// making their system unreadable. If ISO-2022 encoding is selected, though,
// we'll reset the G2 and G3 tables to Latin1, so that 8-bit apps will get a
// more meaningful character mapping by default. This is triggered by a DOCS
// sequence, which will call the EnableGrTranslation method below.
_gsetTranslationTables.at(0) = Ascii;
_gsetTranslationTables.at(1) = Ascii;
_gsetTranslationTables.at(2) = Latin1;
_gsetTranslationTables.at(3) = Latin1;
_gsetTranslationTables.at(2) = Ascii;
_gsetTranslationTables.at(3) = Ascii;
}

bool TerminalOutput::Designate94Charset(size_t gsetNumber, const VTID charset)
Expand Down Expand Up @@ -91,7 +97,13 @@ bool TerminalOutput::NeedToTranslate() const noexcept
void TerminalOutput::EnableGrTranslation(boolean enabled)
{
_grTranslationEnabled = enabled;
// We need to reapply the right locking shift to (de)activate the translation table.
// The default table for G2 and G3 is Latin1 when GR translation is enabled,
// and ASCII when disabled. The reason for this is explained in the constructor.
const auto defaultTranslationTable = enabled ? std::wstring_view{ Latin1 } : std::wstring_view{ Ascii };
_gsetTranslationTables.at(2) = defaultTranslationTable;
_gsetTranslationTables.at(3) = defaultTranslationTable;
// We need to reapply the locking shifts in case the underlying G-sets have changed.
LockingShift(_glSetNumber);
LockingShiftRight(_grSetNumber);
}

Expand Down