ANSI Escape code are counted as characters hwne #3873

Open
opened 2026-01-30 23:32:16 +00:00 by claunia · 0 comments
Owner

Originally created by @floppyman on GitHub (Sep 14, 2019).

Environment

Microsoft Windows NT 10.0.18362.0

Version of Terminal
2019-09-14 17_08_16-Window

Steps to reproduce

When the following C# code it executed it will produce all the 255 color palette colors, in rows of 20 colors.
When running it it Windows Console (Developer Debug Conosle), it works just fine.
But when running it in Windows Terminal the lines are cut much earlier, and the output is not uniform.

using System;
namespace App
{
	internal class Program
	{
		internal static void Main(string[] args) {
			var rowSplitCount = 20;
			var count = 1;
			for (var i = 0; i < 256; i++) {
				if (count < rowSplitCount) {
					Console.Write($"\x1b[38;5;{i}m\x1b[48;5;0m {i.ToString().PadLeft(3, '0')} \x1b[0m");
					count++;
				} else {
					Console.WriteLine($"\x1b[38;5;{i}m\x1b[48;5;0m {i.ToString().PadLeft(3, '0')} \x1b[0m");
					count = 1;
				}
			}

			Console.WriteLine("");
		}
	}
}

Expected behavior

As seen in the attached picture on the Right side we have the normal Windows Console (developer debug console)
And on the Left side we have the Windows Terminal

The expected output is what is shown in the Windows Console.

2019-09-14 16_41_58-Window

Actual behavior

My suspicion is that the Windows Terminal is counting the ANSI characters when drawing the text, but at the same time correctly interpreting the escape sequences and changing the text.

Originally created by @floppyman on GitHub (Sep 14, 2019). # Environment Microsoft Windows NT 10.0.18362.0 Version of Terminal ![2019-09-14 17_08_16-Window](https://user-images.githubusercontent.com/932288/64909967-4e075f80-d712-11e9-9915-00602ff40eed.png) # Steps to reproduce When the following C# code it executed it will produce all the 255 color palette colors, in rows of 20 colors. When running it it Windows Console (Developer Debug Conosle), it works just fine. But when running it in Windows Terminal the lines are cut much earlier, and the output is not uniform. ``` using System; namespace App { internal class Program { internal static void Main(string[] args) { var rowSplitCount = 20; var count = 1; for (var i = 0; i < 256; i++) { if (count < rowSplitCount) { Console.Write($"\x1b[38;5;{i}m\x1b[48;5;0m {i.ToString().PadLeft(3, '0')} \x1b[0m"); count++; } else { Console.WriteLine($"\x1b[38;5;{i}m\x1b[48;5;0m {i.ToString().PadLeft(3, '0')} \x1b[0m"); count = 1; } } Console.WriteLine(""); } } } ``` # Expected behavior As seen in the attached picture on the Right side we have the normal Windows Console (developer debug console) And on the Left side we have the Windows Terminal The expected output is what is shown in the Windows Console. ![2019-09-14 16_41_58-Window](https://user-images.githubusercontent.com/932288/64909881-ab4ee100-d711-11e9-8e5e-827b93fab792.png) # Actual behavior My suspicion is that the Windows Terminal is counting the ANSI characters when drawing the text, but at the same time correctly interpreting the escape sequences and changing the text.
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-30 23:32:16 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#3873