Skip to content

Commit

Permalink
Replace controls in buffer with printable codepoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
j4james committed Mar 5, 2024
1 parent 338c504 commit 90397b9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/renderer/vt/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,25 @@ using namespace Microsoft::Console::Types;
_bufferLine.append(cluster.GetText());
totalWidth += cluster.GetColumns();
}

// If any of the values in the buffer are C0 or C1 controls, we need to
// convert them to printable codepoints, otherwise they'll end up being
// evaluated as control characters by the receiving terminal. We use the
// DOS 437 code page for the C0 controls and DEL, and just a `?` for the
// C1 controls, since that's what you would most likely have seen in the
// legacy v1 console with raster fonts.
const auto cchLine = _bufferLine.size();
std::for_each_n(_bufferLine.begin(), cchLine, [](auto& ch) {
static constexpr std::wstring_view C0Glyphs = L" ☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼";
if (ch < C0Glyphs.size())
{
ch = til::at(C0Glyphs, ch);
}
else if (ch >= L'\u007F' && ch < L'\u00A0')
{
ch = (ch == L'\u007F' ? L'' : L'?');
}
});

const auto spaceIndex = _bufferLine.find_last_not_of(L' ');
const auto foundNonspace = spaceIndex != decltype(_bufferLine)::npos;
Expand Down

0 comments on commit 90397b9

Please sign in to comment.