Repository: microsoft/terminal (language: cpp)

Issue:
Add an additional debug option to show a `\n` when `\r` is received
<!-- 
🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨

I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING:
1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement.
2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement.
3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number).
4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement.
5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement.

All good? Then proceed!
-->

# Description of the new feature/enhancement

The debug tool is great, but could certainly be improved if you could add an option to actually do a `\n` when the `\r` (CR) character is received. This would significantly increase the readability of the infinite debug strings coming out, without affecting the actual output and understanding.

So that it would look like:

```
blah blahblah   blah
[C/R] blah blah
``` 
(Where [C/R] is the special unicode (\x2400 range) character for `\r`.) 


# Proposed technical implementation details (optional)

Add an optional 2nd debug option after the `"debugFeatures": true,` option.
Name the option: `"debugFeature_Show_NL": true`.



Discussion / hints:
I'm tempted to just outright reject this - I actually quite like that every character that's emitted to the debug tap is turned into a printable character. It gets rid of any guesswork as to whatever the line discipline is supposed to be. You can just look at the output and know "yep, there was the CR, there's the NL, the BS SPC BS", etc.

@DHowett is the father of the debug tap so I'll give him the final say. If anything, the setting should probably be `debugFeature.showNewlines`, since we're sorta using the dot notation for things like that
The problem is only of readability, because when you are doing something on CLI/prompt, the debug output is always misaligned, so it's very hard to read where was the last place something was output/input. So being able to add a *real* newline where there are, either an `\n` or a `\r`, in addition to the unicode block symbol for that, would really help the readablity and alignment. Everything else is great and remain the same. The symbols are all there, only occasionally separated by a visible newline. 

An additional advantage is that of copy pasting the debug output. If you don't have a visible `\n` (or `\r`) you will get the entire copied part, in one very long string. Not very practical for reporting and including in bug reports. 
I don't feel strongly about this one way or the other, but if we were going to have this feature, I'd expect it to be trigger by a `\n` rather than a `\r`, and I'd also expect the line break in the log to come *after* the output of the control character. For example, something like this:

```
C:\>␛[13;28;13;1;0;1_␛[13;28;13;0;0;1_␍␊
C:\>
```

This is similar to what you'd see if you've enabled visible whitespace in a text editor.
> This is similar to what you'd see if you've enabled visible whitespace in a text editor.

Even better! 👍 

Honestly, I think we should probably just do this all the time and without a setting. Right now, the debug tap is incapable of producing a physical CR/LF, so adding one would be adding valuable clarifying whitespace without adding confusion as to where that whitespace came from.

Thanks for the request, and I'm sorry I missed this thread the first time!

Fix patch:
diff --git a/src/cascadia/TerminalApp/DebugTapConnection.cpp b/src/cascadia/TerminalApp/DebugTapConnection.cpp
index ab2aa0b9644..bd1192b225e 100644
--- a/src/cascadia/TerminalApp/DebugTapConnection.cpp
+++ b/src/cascadia/TerminalApp/DebugTapConnection.cpp
@@ -111,7 +111,15 @@ namespace winrt::Microsoft::TerminalApp::implementation
 
     void DebugTapConnection::_OutputHandler(const hstring str)
     {
-        _TerminalOutputHandlers(til::visualize_control_codes(str));
+        auto output = til::visualize_control_codes(str);
+        // To make the output easier to read, we introduce a line break whenever
+        // an LF control is encountered. But at this point, the LF would have
+        // been converted to U+240A (␊), so that's what we need to search for.
+        for (size_t lfPos = 0; (lfPos = output.find(L'\u240A', lfPos)) != std::wstring::npos;)
+        {
+            output.insert(++lfPos, L"\r\n");
+        }
+        _TerminalOutputHandlers(output);
     }
 
     // Called by the DebugInputTapConnection to print user input


Test patch: