-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Writing to Terminal with \n inconsistent on Windows vs Linux and vs other libraries #156
Comments
I also noticed that if I change the System.Console test to include a bit of Cathode, it starts doing the wrong thing.
I know the analyzer blocks this because they don't play well together, but simply causing the |
Ok it looks like the issue is that DISABLE_NEWLINE_AUTO_RETURN is being set in the native driver. Since this is deliberate, I'm wondering why? I can work around the issue for myself by flipping the bit back off after ensuring the native console has been initialized, but what might I break when I do this? (Guess I'll find out!) |
Can you confirm whether clearing the |
I was actually aware of this issue since the beginning of the project. I recall that I concluded that it was an unfixable platform difference. How or why I concluded that, though, I don't exactly remember. But let me try...
An easy workaround is to just use |
This code indeed works around the problem for me:
I can go find everywhere I'm using the Terminal specific streams, or one of the Terminal 'out' functions, and run them through helper functions instead that do the newline replacement. But I'd rather just set the mode once, as I did above. It's much less error prone. Indeed this is a strange situation. I've written loads of little cli tools over the years for Windows Mac and Linux, and have always (*) used plain old \n. All my tooling, the company VCS's, etc. have been set to unix EOL. I normally strip \r's and avoid direct/indirect use of Environment.NewLine, because those \r's cause portability annoyances in practice. But here, I need to add them back in to work right! Philosophy aside, the main argument I have is that it's different from System.Console and Spectre, and therefore surprising. Also only shows up with embedded newlines, which may be a less common case than people hitting OutLine (this is how I came across the issue today). I'm imagining the Mac user who is now trying out their cool little cli tool on Windows, only to find the most surprising behavior.. (* Ok maybe only in the last 15 years, when Windows dev tooling became more unix friendly.) |
One clarification:
I don't mean to say that it shouldn't have the ability to be different. Just that the default behavior is different. If it's cooked because that is what people expect (I think I saw that in a comment in your code, and agree), then I'd say that people also generally expect that \n will end up on with an implicit \r as well. |
OK, the fact that I wonder if this is a bug in the console host. 🤔 I'll need to do some more investigation and see what can be done. I do agree that it isn't ideal; consistency between platforms is preferable. |
OK. Yeah. The docs for that flag are just completely super wildly wrong. And the funny part is that I filed a bug for it! I just completely forgot, apparently. The TL;DR of that bug tail seems to be that we should set this flag for raw mode and clear it for cooked mode, similar to how we set |
@scottbilas v0.13.25 has the fix and should appear on NuGet soon™. |
Amazing, at multiple levels. :D |
Got the latest version, I can confirm it fixes the issue for me and I have removed my local workaround. Thank you! |
On Windows, Terminal.Out/OutLine will not do a carriage return when receiving a string with embedded
\n
in it. Given this code:Vezel.Cathode.Terminal.OutLine("Line 1\nLine 2");
On Windows the output is:
If I make that
\n
into a\r\n
, then it does the right thing.If I run the
\n
version on Linux, then it also is correct. Only on Windows is it wrong.Other libraries also do the right thing. I tested with both Spectre and .NET BCL. On Windows and Linux, with just
\n
, either of these is also correct:Spectre.Console.AnsiConsole.WriteLine("Line 1\nLine 2");
System.Console.WriteLine("Line 1\nLine 2");
The text was updated successfully, but these errors were encountered: