Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line breaks in the debug tap output #13475

Merged
1 commit merged into from
Jul 11, 2022
Merged

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented Jul 10, 2022

Summary of the Pull Request

When the debug tap converts control characters into visible glyphs, it
ends up losing the structure of the output, and that can sometimes make
things difficult to read. This PR attempts to alleviate that problem by
reinjecting an actual line break in the debug stream whenever an LF
control is received.

PR Checklist

Validation Steps Performed

I've tested the updated debug tab with a number of different shells, and
also a couple of different apps. When there aren't many linefeeds in the
output, it's obviously not going to make much of a difference, but when
there are, I think it definitely improves the readability.

@ghost ghost added Area-TerminalConnection Issues pertaining to the terminal<->backend connection interface Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Jul 10, 2022
@j4james
Copy link
Collaborator Author

j4james commented Jul 10, 2022

Some sample output so you can see the kind of difference it makes...

image

@j4james j4james marked this pull request as ready for review July 10, 2022 01:20
Comment on lines +118 to +121
for (size_t lfPos = 0; (lfPos = output.find(L'\u240A', lfPos)) != std::wstring::npos;)
{
output.insert(++lfPos, L"\r\n");
}
Copy link
Member

@lhecker lhecker Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this.

Although I'd generally prefer it if til::visualize_control_codes was decomposed, so that we can "recompose" it back into the two behaviors we need (namely newline preserving and not). Something like that:

namespace til
{
    constexpr wchar_t visualize_control_code(wchar_t ch) noexcept
    {
        if (ch < 0x20)
        {
            ch += 0x2400;
        }
        else if (ch == 0x20)
        {
            ch = 0x2423; // replace space with ␣
        }
        else if (ch == 0x7f)
        {
            ch = 0x2421; // replace del with ␡
        }
        return ch;
    }

    _TIL_INLINEPREFIX std::wstring visualize_control_codes(std::wstring str) noexcept
    {
        for (auto& ch : str)
        {
            ch = visualize_control_code(ch);
        }
        return str;
    }

    _TIL_INLINEPREFIX std::wstring visualize_control_codes_with_newlines(std::wstring_view str) noexcept
    {
        std::wstring out;
        out.reserve(str.size());

        wchar_t buffer[3]{ L'\0', L'\r', L'\n' };

        for (const auto& ch : str)
        {
            buffer[0] = visualize_control_code(ch);
            const auto length = buffer[0] != 0x240A ? 1 : 3;
            out.append(&buffer[0], length);
        }

        return out;
    }
}

(I haven't tested, nor commented it, but I think it should work. The main benefit is that it doesn't need to reshuffle the string so that it's only a single O(n) loop.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but also... this is an "under duress" debugging feature. It's going to impact performance, even if negligibly, but it is on a low-use surface. I'm cool with it.

I know you probably approved instead of blocking because you're aware of that already. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you probably approved instead of blocking because you're aware of that already. :)

^ This. 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I guess this was a bit lazy of me, but I didn't want to mess with the existing code, and I figured the performance wasn't that important here.

Comment on lines +118 to +121
for (size_t lfPos = 0; (lfPos = output.find(L'\u240A', lfPos)) != std::wstring::npos;)
{
output.insert(++lfPos, L"\r\n");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but also... this is an "under duress" debugging feature. It's going to impact performance, even if negligibly, but it is on a low-use surface. I'm cool with it.

I know you probably approved instead of blocking because you're aware of that already. :)

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jul 11, 2022
@ghost
Copy link

ghost commented Jul 11, 2022

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 04478d1 into microsoft:main Jul 11, 2022
DHowett pushed a commit that referenced this pull request Jul 15, 2022
## Summary of the Pull Request

When the debug tap converts control characters into visible glyphs, it
ends up losing the structure of the output, and that can sometimes make
things difficult to read. This PR attempts to alleviate that problem by
reinjecting an actual line break in the debug stream whenever an `LF`
control is received.

## PR Checklist
* [x] Closes #12312
* [x] CLA signed.
* [ ] Tests added/passed
* [ ] Documentation updated.
* [ ] Schema updated.
* [x] I've discussed this with core contributors already. Issue number
where discussion took place: #12312

## Validation Steps Performed

I've tested the updated debug tab with a number of different shells, and
also a couple of different apps. When there aren't many linefeeds in the
output, it's obviously not going to make much of a difference, but when
there are, I think it definitely improves the readability.

(cherry picked from commit 04478d1)
Service-Card-Id: 84116394
Service-Version: 1.14
DHowett pushed a commit that referenced this pull request Jul 19, 2022
## Summary of the Pull Request

When the debug tap converts control characters into visible glyphs, it
ends up losing the structure of the output, and that can sometimes make
things difficult to read. This PR attempts to alleviate that problem by
reinjecting an actual line break in the debug stream whenever an `LF`
control is received.

## PR Checklist
* [x] Closes #12312
* [x] CLA signed.
* [ ] Tests added/passed
* [ ] Documentation updated.
* [ ] Schema updated.
* [x] I've discussed this with core contributors already. Issue number
where discussion took place: #12312

## Validation Steps Performed

I've tested the updated debug tab with a number of different shells, and
also a couple of different apps. When there aren't many linefeeds in the
output, it's obviously not going to make much of a difference, but when
there are, I think it definitely improves the readability.

(cherry picked from commit 04478d1)
Service-Card-Id: 84116395
Service-Version: 1.15
@ghost
Copy link

ghost commented Aug 5, 2022

🎉Windows Terminal v1.14.196 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Aug 5, 2022

🎉Windows Terminal Preview v1.15.200 has been released which incorporates this pull request.:tada:

Handy links:

@j4james j4james deleted the debugtap-linebreaks branch August 31, 2022 00:23
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalConnection Issues pertaining to the terminal<->backend connection interface AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an additional debug option to show a \n when \r is received
4 participants