Repository: microsoft/terminal
File: src/host/_stream.cpp (C++)

Code before:
        size_t offset = 0;

        // DISABLE_NEWLINE_AUTO_RETURN not being set is equivalent to a LF -> CRLF translation.
        const auto write = [&](size_t beg, size_t end) {
            const auto chunk = til::safe_slice_abs(str, beg, end);
            if (WI_IsFlagSet(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN))
            {
                writer.WriteUTF16(chunk);
            }
            else
            {
                writer.WriteUTF16TranslateCRLF(chunk);
            }
        };

        // When we encounter something like a RIS (hard reset), we must re-enable
        // modes that we rely on (like the Win32 Input Mode). To do this, the VT
        // parser tells us the positions of any such relevant VT sequences.
        for (const auto& injection : injections)
        {
            write(offset, injection.offset);
            offset = injection.offset;

            static constexpr std::array<std::string_view, 2> mapping{ {
                { "\x1b[?1004h\x1b[?9001h" }, // RIS: Focus Event Mode + Win32 Input Mode
                { "\033[?1004h" } // DECSET_FOCUS: Focus Event Mode
            } };
            static_assert(static_cast<size_t>(InjectionType::Count) == mapping.size(), "you need to update the mapping array");

            writer.WriteUTF8(mapping[static_cast<size_t>(injection.type)]);
        }

        write(offset, std::wstring_view::npos);
        writer.Submit();
    }
}

// Erases all contents of the given screenInfo, including the current screen and scrollback.
void WriteClearScreen(SCREEN_INFORMATION& screenInfo)
{
    WriteCharsVT(
        screenInfo,
        L"\x1b[H" // CUP to home
        L"\x1b[2J" // Erase in Display: clear the screen
        L"\x1b[3J" // Erase in Display: clear the scrollback buffer
    );
}

// Routine Description:
// - Takes the given text and inserts it into the given screen buffer.
// Note:

Review comment (suggestion):
while you're here

```suggestion
                { "\x1b[?1004h" } // DECSET_FOCUS: Focus Event Mode
```

Code after:
        size_t offset = 0;

        // DISABLE_NEWLINE_AUTO_RETURN not being set is equivalent to a LF -> CRLF translation.
        const auto write = [&](size_t beg, size_t end) {
            const auto chunk = til::safe_slice_abs(str, beg, end);
            if (WI_IsFlagSet(screenInfo.OutputMode, DISABLE_NEWLINE_AUTO_RETURN))
            {
                writer.WriteUTF16(chunk);
            }
            else
            {
                writer.WriteUTF16TranslateCRLF(chunk);
            }
        };

        // When we encounter something like a RIS (hard reset), we must re-enable
        // modes that we rely on (like the Win32 Input Mode). To do this, the VT
        // parser tells us the positions of any such relevant VT sequences.
        for (const auto& injection : injections)
        {
            write(offset, injection.offset);
            offset = injection.offset;

            static constexpr std::array<std::string_view, 2> mapping{ {
                { "\x1b[?1004h\x1b[?9001h" }, // RIS: Focus Event Mode + Win32 Input Mode
                { "\x1b[?1004h" } // DECSET_FOCUS: Focus Event Mode
            } };
            static_assert(static_cast<size_t>(InjectionType::Count) == mapping.size(), "you need to update the mapping array");

            writer.WriteUTF8(mapping[static_cast<size_t>(injection.type)]);
        }

        write(offset, std::wstring_view::npos);
        writer.Submit();
    }
}

// Erases all contents of the given screenInfo, including the current screen and scrollback.
void WriteClearScreen(SCREEN_INFORMATION& screenInfo)
{
    WriteCharsVT(
        screenInfo,
        L"\x1b[H" // CUP to home
        L"\x1b[2J" // Erase in Display: clear the screen
        L"\x1b[3J" // Erase in Display: clear the scrollback buffer
    );
}

// Routine Description:
// - Takes the given text and inserts it into the given screen buffer.
// Note: