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

Code before:
                len = std::min(8 - (column & 7), remaining);
                std::fill_n(&buf[0], len, L' ');
            }
            else
            {
                buf[0] = L'^';
                buf[1] = wch + L'@';
                len = 2;
            }

            if (column + len > columnLimit)
            {
                goto outerLoopExit;
            }

            output.append(buf, len);
            column += len;
        }
    }

outerLoopExit:
    if (it != end && column < columnLimit)
    {
        output.append(columnLimit - column, L' ');
        column = columnLimit;
    }

    return {
        .offset = static_cast<size_t>(it - beg),
        .column = column,
    };
}

void COOKED_READ_DATA::_appendCUP(std::wstring& output, til::point pos)
{
    fmt::format_to(std::back_inserter(output), FMT_COMPILE(L"\x1b[{};{}H"), pos.y + 1, pos.x + 1);
}

void COOKED_READ_DATA::_appendPopupAttr(std::wstring& output) const
{
    VtIo::FormatAttributes(output, _screenInfo.GetPopupAttributes());
}

void COOKED_READ_DATA::_popupPush(const PopupKind kind)
try
{
    auto& popup = _popups.emplace_back(kind);
    _dirty = true;

    switch (kind)
    {

Review comment (suggestion):
Removing this stops us from inserting padding spaces manually (that's the job of the terminal). But with the `if` condition gone, we need to move the `column = columnLimit;` elsewhere of course, because otherwise the caller doesn't know that we line-wrapped.

Code after:
    _originInViewport = originInViewportFinal;
    _pagerPromptEnd = pagerPromptEnd;
    _pagerContentTop = pagerContentTop;
    _pagerHeight = pagerHeight;
    _bufferDirtyBeg = _buffer.size();
    _dirty = false;
}

COOKED_READ_DATA::LayoutResult COOKED_READ_DATA::_layoutLine(std::wstring& output, const std::wstring_view& input, const size_t inputOffset, const til::CoordType columnBegin, const til::CoordType columnLimit) const
{
    const auto& textBuffer = _screenInfo.GetTextBuffer();
    const auto beg = input.data();
    const auto end = beg + input.size();
    auto it = beg + std::min(inputOffset, input.size());
    auto column = std::min(columnBegin, columnLimit);

    output.reserve(output.size() + columnLimit - column);

    while (it != end && column < columnLimit)
    {
        const auto nextControlChar = std::find_if(it, end, [](const auto& wch) { return wch < L' '; });
        if (it != nextControlChar)
        {
            std::wstring_view text{ it, nextControlChar };
            til::CoordType cols = 0;
            const auto len = textBuffer.FitTextIntoColumns(text, columnLimit - column, cols);

            output.append(text, 0, len);
            column += cols;
            it += len;
        }

        const auto nextPlainChar = std::find_if(it, end, [](const auto& wch) { return wch >= L' '; });
        for (; it != nextPlainChar; ++it)
        {
            if (column >= columnLimit)
            {
                column = columnLimit;
                goto outerLoopExit;
            }

            const auto wch = *it;
            wchar_t buf[8];
            til::CoordType len = 0;

            if (wch == UNICODE_TAB)
            {
                const auto remaining = columnLimit - column;
                len = std::min(8 - (column & 7), remaining);
                std::fill_n(&buf[0], len, L' ');
            }