Repository: microsoft/terminal
File: src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (C++)

Code before:

    _flushFirstFrame();

    _checkConptyOutput = false;
    _logConpty = true;

    const auto width = static_cast<size_t>(TerminalViewWidth);

    const auto charsInFirstLine = width;
    const auto numCharsFirstColor = 30;
    const auto numCharsSecondColor = charsInFirstLine - numCharsFirstColor;
    const auto charsInSecondLine = width / 2;

    const auto defaultAttrs = TextAttribute();
    const auto conhostDefaultAttrs = si.GetAttributes();

    // Helper to abstract calls into either StateMachine::ProcessString or
    // WriteCharsLegacy
    auto print = [&](const std::wstring_view str) {
        if (writingMethod == PrintWithPrintString)
        {
            sm.ProcessString(str);
        }
        else if (writingMethod == PrintWithWriteCharsLegacy)
        {
            WriteCharsLegacy(si, str, true, nullptr);
        }
    };

    // Each of the lines of text in the buffer will look like the following:
    //
    // Line 1 chars: ~~~~~~~~~~~~~~~~~~ <wrap>
    // Line 1 attrs: YYYYYYYDDDDDDDDDDD (First 30 are yellow FG, then default attrs)
    // Line 2 chars: ~~~~~~~~~~________ <break> (there are width/2 '~'s here)
    // Line 2 attrs: DDDDDDDDDDDDDDDDDD (all are default attrs)
    //
    // The last line of the buffer will be used as a "prompt" line, with a
    // single ':' in it. This is similar to the way `less` typically displays
    // its prompt at the bottom of the buffer.

    // First, print a whole viewport full of text.
    for (auto i = 0; i < (TerminalViewHeight) / 2; i++)
    {
        Log::Comment(NoThrowString().Format(L"writing pair of lines %d", i));

        sm.ProcessString(L"\x1b[33m");
        print(std::wstring(numCharsFirstColor, L'~'));
        sm.ProcessString(L"\x1b[m");

        if (paintEachNewline == PaintEveryLine)
        {

Review comment (suggestion):
This makes the tests pass. I don't think they ever relied on the interactive behavior of `WriteCharsLegacy`.

Code after:

    _flushFirstFrame();

    _checkConptyOutput = false;
    _logConpty = true;

    const auto width = static_cast<size_t>(TerminalViewWidth);

    const auto charsInFirstLine = width;
    const auto numCharsFirstColor = 30;
    const auto numCharsSecondColor = charsInFirstLine - numCharsFirstColor;
    const auto charsInSecondLine = width / 2;

    const auto defaultAttrs = TextAttribute();
    const auto conhostDefaultAttrs = si.GetAttributes();

    // Helper to abstract calls into either StateMachine::ProcessString or
    // WriteCharsLegacy
    auto print = [&](const std::wstring_view str) {
        if (writingMethod == PrintWithPrintString)
        {
            sm.ProcessString(str);
        }
        else if (writingMethod == PrintWithWriteCharsLegacy)
        {
            WriteCharsLegacy(si, str, false, nullptr);
        }
    };

    // Each of the lines of text in the buffer will look like the following:
    //
    // Line 1 chars: ~~~~~~~~~~~~~~~~~~ <wrap>
    // Line 1 attrs: YYYYYYYDDDDDDDDDDD (First 30 are yellow FG, then default attrs)
    // Line 2 chars: ~~~~~~~~~~________ <break> (there are width/2 '~'s here)
    // Line 2 attrs: DDDDDDDDDDDDDDDDDD (all are default attrs)
    //
    // The last line of the buffer will be used as a "prompt" line, with a
    // single ':' in it. This is similar to the way `less` typically displays
    // its prompt at the bottom of the buffer.

    // First, print a whole viewport full of text.
    for (auto i = 0; i < (TerminalViewHeight) / 2; i++)
    {
        Log::Comment(NoThrowString().Format(L"writing pair of lines %d", i));

        sm.ProcessString(L"\x1b[33m");
        print(std::wstring(numCharsFirstColor, L'~'));
        sm.ProcessString(L"\x1b[m");

        if (paintEachNewline == PaintEveryLine)
        {