Console.WriteLine occasionally doesn't break the line #19987

Closed
opened 2026-01-31 06:59:35 +00:00 by claunia · 7 comments
Owner

Originally created by @Rand-Random on GitHub (May 26, 2023).

Windows Terminal version

1.16.10262.0

Windows build number

10.0.22621.1702

Other Software

No response

Steps to reproduce

I did explain the issue in detail on Stackoverflow
https://stackoverflow.com/questions/76341712

if linking to Stackoverflow isn't sufficient, please let me know.

Expected Behavior

Console.Writeline() should always produce a new line

Actual Behavior

see the stackoverflow post

Originally created by @Rand-Random on GitHub (May 26, 2023). ### Windows Terminal version 1.16.10262.0 ### Windows build number 10.0.22621.1702 ### Other Software _No response_ ### Steps to reproduce I did explain the issue in detail on Stackoverflow https://stackoverflow.com/questions/76341712 if linking to Stackoverflow isn't sufficient, please let me know. ### Expected Behavior `Console.Writeline()` should always produce a new line ### Actual Behavior see the stackoverflow post
claunia added the Issue-BugResolution-Duplicate labels 2026-01-31 06:59:36 +00:00
Author
Owner

@zadjii-msft commented on GitHub (May 26, 2023):

I've got a crazy hunch. I think this is probably the same thing as #14512.

Can you try installing Terminal Preview, v1.18, setting that as the "Default Terminal Application" in the Settings App, and try again?

@zadjii-msft commented on GitHub (May 26, 2023): I've got a crazy hunch. I think this is probably the same thing as #14512. Can you try installing [Terminal Preview, v1.18](https://github.com/microsoft/terminal/releases/tag/v1.18.1421.0), setting that as the "Default Terminal Application" in the Settings App, and try again?
Author
Owner

@Rand-Random commented on GitHub (May 26, 2023):

@zadjii-msft
thanks for the fast response

#14512 did partially help, in stackoverflow comment I mentioned this:

@bdcoder - without thread sleep the output disappears completly (only the last view lines remain) but everything above the scrollviewer threshhold is gone: i.stack.imgur.com/U9reA.png

this issue got resolved, but my original problem the line breaks (apparently after resizing the window) is still there
image

image

@Rand-Random commented on GitHub (May 26, 2023): @zadjii-msft thanks for the fast response #14512 did partially help, in stackoverflow comment I mentioned this: > @bdcoder - without thread sleep the output disappears completly (only the last view lines remain) but everything above the scrollviewer threshhold is gone: [i.stack.imgur.com/U9reA.png](https://i.stack.imgur.com/U9reA.png) this issue got resolved, but my original problem the line breaks (apparently after resizing the window) is still there ![image](https://github.com/microsoft/terminal/assets/9868626/cfc7a0cb-c857-4ff3-a8e8-9184330574ad) ![image](https://github.com/microsoft/terminal/assets/9868626/89e72942-441d-432e-8280-a04c9710a59c)
Author
Owner

@elsaco commented on GitHub (May 27, 2023):

@Rand-Random this issue is triggered when resizing horizontally only, and you have output past BufferWidth. Starting with default terminal size:

bw120

and horizontal resize by one column:

bw121

It's easy to see what happen when using hex:

Before buffer resize:

00000000: 3061 6161 6161 6161 6161 6161 6161 6161  0aaaaaaaaaaaaaaa
00000010: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000020: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000030: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000040: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000050: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000060: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000070: 6161 6161 6161 610a 3161 6161 6161 6161  aaaaaaa.1aaaaaaa
00000080: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000090: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000a0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000b0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000c0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000d0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000e0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000f0: 0a32 6161 6161 6161 6161 6161 6161 6161  .2aaaaaaaaaaaaaa
00000100: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000110: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000120: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000130: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000140: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000150: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000160: 6161 6161 6161 6161 6161 0a              aaaaaaaaaa.

and after:

00000000: 3061 6161 6161 6161 6161 6161 6161 6161  0aaaaaaaaaaaaaaa
00000010: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000020: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000030: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000040: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000050: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000060: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000070: 6161 6161 6161 610a 3161 6161 6161 6161  aaaaaaa.1aaaaaaa
00000080: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000090: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000a0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000b0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000c0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000d0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000e0: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
000000f0: 3261 6161 6161 6161 6161 6161 6161 6161  2aaaaaaaaaaaaaaa
00000100: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000110: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000120: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000130: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000140: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000150: 6161 6161 6161 6161 6161 6161 6161 6161  aaaaaaaaaaaaaaaa
00000160: 6161 6161 6161 6161 610a                 aaaaaaaaa.


Notice how 0x0A (line feed) is gone between line 1 and 2.

@elsaco commented on GitHub (May 27, 2023): @Rand-Random this issue is triggered when resizing horizontally only, and you have output past `BufferWidth`. Starting with default terminal size: ![bw120](https://github.com/microsoft/terminal/assets/3933920/62c2a280-4ad9-4e79-b197-54b061f90d89) and horizontal resize by one column: ![bw121](https://github.com/microsoft/terminal/assets/3933920/6ab0426d-f5c1-45c9-b4f6-5fe90db2bbb7) It's easy to see what happen when using hex: Before buffer resize: ``` 00000000: 3061 6161 6161 6161 6161 6161 6161 6161 0aaaaaaaaaaaaaaa 00000010: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000020: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000030: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000040: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000050: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000060: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000070: 6161 6161 6161 610a 3161 6161 6161 6161 aaaaaaa.1aaaaaaa 00000080: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000090: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000a0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000b0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000c0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000d0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000e0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000f0: 0a32 6161 6161 6161 6161 6161 6161 6161 .2aaaaaaaaaaaaaa 00000100: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000110: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000120: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000130: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000140: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000150: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000160: 6161 6161 6161 6161 6161 0a aaaaaaaaaa. ``` and after: ``` 00000000: 3061 6161 6161 6161 6161 6161 6161 6161 0aaaaaaaaaaaaaaa 00000010: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000020: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000030: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000040: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000050: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000060: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000070: 6161 6161 6161 610a 3161 6161 6161 6161 aaaaaaa.1aaaaaaa 00000080: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000090: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000a0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000b0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000c0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000d0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000e0: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 000000f0: 3261 6161 6161 6161 6161 6161 6161 6161 2aaaaaaaaaaaaaaa 00000100: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000110: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000120: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000130: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000140: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000150: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa 00000160: 6161 6161 6161 6161 610a aaaaaaaaa. ``` Notice how `0x0A` (line feed) is gone between line 1 and 2.
Author
Owner

@carlos-zamora commented on GitHub (May 31, 2023):

Thanks for filing this! Gonna mark this as a duplicate of https://github.com/microsoft/terminal/issues/6901#issuecomment-1307781312

/dup #6901

@carlos-zamora commented on GitHub (May 31, 2023): Thanks for filing this! Gonna mark this as a duplicate of https://github.com/microsoft/terminal/issues/6901#issuecomment-1307781312 /dup #6901
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (May 31, 2023):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@microsoft-github-policy-service[bot] commented on GitHub (May 31, 2023): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (May 31, 2023):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@microsoft-github-policy-service[bot] commented on GitHub (May 31, 2023): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Author
Owner

@Rand-Random commented on GitHub (Jun 9, 2023):

@zadjii-msft - not sure if you would look at a closed issue without a ping


IMHO closing the issue makes the duplicate comment look like this is a completed task, as some issues in the comment aren't closed - so to me that would be confusing, I would believe looking at
image

that #8976 and #9933 are open tasks while #15455 is completed

BUT if thats how you want to do things, its totally up to you, so you do you


Had some time to look at this issue again, and wanted to do a "simple" fix based on the observed behaviour, I borrowed @elsaco code and did the following

internal class Program
{
    static void Main(string[] args)
    {
        for (var i = 0; i < 3; i++) 
            ConsoleEx.WriteLine(i.ToString().PadRight(119 + i, 'a'));

        Console.ReadKey();
    }
}

internal static class ConsoleEx
{
    #region Static Public Methods

    public static void WriteLine(string str)
    {
        //try to fix 
        if (str.Length is >= 119 and <= 121)
            str = str.PadRight(125);

        Console.WriteLine(str);
    }

    #endregion
}

the idea is if the length 120 is something special, I just add more whitespace characters (PadRight) to the string and hopefully this solve the issue.

Sadly, this didn't help and instead of the broken state of newlines "concatenated together" I am getting the different issue described in the comment https://github.com/microsoft/terminal/issues/6901#issuecomment-1307781312 "line breaks are introduced"
image

@Rand-Random commented on GitHub (Jun 9, 2023): @zadjii-msft - not sure if you would look at a closed issue without a ping --------------- IMHO closing the issue makes the [duplicate comment](https://github.com/microsoft/terminal/issues/6901#issuecomment-1307781312) look like this is a completed task, as some issues in the comment aren't closed - so to **me** that would be confusing, I would believe looking at ![image](https://github.com/microsoft/terminal/assets/9868626/dce7c578-707b-4301-8546-df64f7edbbcd) that #8976 and #9933 are open tasks while #15455 is completed BUT if thats how you want to do things, its totally up to you, so you do you --------------- Had some time to look at this issue again, and wanted to do a "simple" fix based on the observed behaviour, I borrowed @elsaco code and did the following ```c# internal class Program { static void Main(string[] args) { for (var i = 0; i < 3; i++) ConsoleEx.WriteLine(i.ToString().PadRight(119 + i, 'a')); Console.ReadKey(); } } internal static class ConsoleEx { #region Static Public Methods public static void WriteLine(string str) { //try to fix if (str.Length is >= 119 and <= 121) str = str.PadRight(125); Console.WriteLine(str); } #endregion } ``` the idea is if the length `120` is something special, I just add more whitespace characters (PadRight) to the string and hopefully this solve the issue. Sadly, this didn't help and instead of the broken state of newlines "concatenated together" I am getting the different issue described in the comment https://github.com/microsoft/terminal/issues/6901#issuecomment-1307781312 "line breaks are introduced" ![image](https://github.com/microsoft/terminal/assets/9868626/0203cf77-dc4b-43a2-8b3b-410ec4eef65a)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19987