Skip to content

Commit

Permalink
HAX: Try to fix the conpty first frame boog
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett authored and zadjii-msft committed Aug 3, 2022
1 parent ac9e9a3 commit aba6caf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
28 changes: 28 additions & 0 deletions src/host/ut_host/ConptyOutputTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ConptyOutputTests
TEST_METHOD(WriteAFewSimpleLines);
TEST_METHOD(InvalidateUntilOneBeforeEnd);
TEST_METHOD(SetConsoleTitleWithControlChars);
TEST_METHOD(IncludeBackgroundColorChangesInFirstFrame);

private:
bool _writeCallback(const char* const pch, const size_t cch);
Expand Down Expand Up @@ -371,6 +372,7 @@ void ConptyOutputTests::SetConsoleTitleWithControlChars()
{
BEGIN_TEST_METHOD_PROPERTIES()
TEST_METHOD_PROPERTY(L"Data:control", L"{0x00, 0x0A, 0x1B, 0x80, 0x9B, 0x9C}")
TEST_METHOD_PROPERTY(L"IsolationLevel", L"Method")
END_TEST_METHOD_PROPERTIES()

int control;
Expand Down Expand Up @@ -400,3 +402,29 @@ void ConptyOutputTests::SetConsoleTitleWithControlChars()

VERIFY_SUCCEEDED(renderer.PaintFrame());
}

void ConptyOutputTests::IncludeBackgroundColorChangesInFirstFrame()
{
auto& g = ServiceLocator::LocateGlobals();
auto& renderer = *g.pRender;
auto& gci = g.getConsoleInformation();
auto& si = gci.GetActiveOutputBuffer();
auto& sm = si.GetStateMachine();

sm.ProcessString(L"\x1b[41mRun 1 \x1b[42mRun 2 \x1b[43mRun 3 \x1b[m");

expectedOutput.push_back("\x1b[2J"); // standard init sequence for the first frame
expectedOutput.push_back("\x1b[m"); // standard init sequence for the first frame
expectedOutput.push_back("\x1b[41m");
expectedOutput.push_back("\x1b[H"); // standard init sequence for the first frame
expectedOutput.push_back("Run 1 ");
expectedOutput.push_back("\x1b[42m");
expectedOutput.push_back("Run 2 ");
expectedOutput.push_back("\x1b[43m");
expectedOutput.push_back("Run 3 ");

// This is also part of the standard init sequence.
expectedOutput.push_back("\x1b[?25h");

VERIFY_SUCCEEDED(renderer.PaintFrame());
}
11 changes: 7 additions & 4 deletions src/renderer/vt/paint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,13 @@ using namespace Microsoft::Console::Types;
// the lines _wrapped_. It doesn't care to manually break the lines, but if
// we trimmed the spaces off here, we'd print all the "~"s one after another
// on the same line.
const auto removeSpaces = !lineWrapped && (useEraseChar ||
_clearedAllThisFrame ||
(_newBottomLine && printingBottomLine && bgMatched));
const auto cchActual = removeSpaces ? nonSpaceLength : cchLine;

const bool removeSpaces = !lineWrapped && (useEraseChar // we determined earlier that ECH is optimal
|| (_clearedAllThisFrame && _lastTextAttributes == TextAttribute{}) // OR we cleared the last frame to the default attributes (specifically)
|| (_newBottomLine && printingBottomLine && bgMatched)); // OR we just scrolled a new line onto the bottom of the screen with the correct attributes
const size_t cchActual = removeSpaces ?
(cchLine - numSpaces) :
cchLine;

const auto columnsActual = removeSpaces ?
(totalWidth - numSpaces) :
Expand Down

0 comments on commit aba6caf

Please sign in to comment.