Windows 10 21H1 - ANSI Escape Codes Not Working #14743

Closed
opened 2026-01-31 04:18:15 +00:00 by claunia · 1 comment
Owner

Originally created by @ghost on GitHub (Jul 31, 2021).

Windows Terminal version (or Windows build number)

1.9.1942.0

Other Software

No response

Steps to reproduce

Make a new .NET console application.

Color.CS

public static class ColorManager
    {
        // Regular colors.
        public static string Black(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BLACK_FG : Colors.BLACK_BG; }
        public static string Red(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.RED_FG : Colors.RED_BG; }
        public static string Green(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.GREEN_FG : Colors.GREEN_BG; }
        public static string Yellow(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.YELLOW_FG : Colors.YELLOW_BG; }
        public static string Blue(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BLUE_FG : Colors.BLUE_BG; }
        public static string Magenta(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.MAGENTA_FG : Colors.MAGENTA_BG; }
        public static string Cyan(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.CYAN_FG : Colors.CYAN_BG; }
        public static string White(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.WHITE_FG : Colors.WHITE_BG; }

        // Bright colors.
        public static string BrightBlack(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_BLACK_FG : Colors.BRT_BLACK_BG; }
        public static string BrightRed(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_RED_FG : Colors.BRT_RED_BG; }
        public static string BrightGreen(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_GREEN_FG : Colors.BRT_GREEN_BG; }
        public static string BrightYellow(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_YELLOW_FG : Colors.BRT_YELLOW_BG; }
        public static string BrightBlue(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_BLUE_FG : Colors.BLUE_BG; }
        public static string BrightMagenta(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_MAGENTA_FG : Colors.BRT_MAGENTA_BG; }
        public static string BrightCyan(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_CYAN_FG : Colors.BRT_CYAN_BG; }
        public static string BrightWhite(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_WHITE_FG : Colors.BRT_WHITE_BG; }

        // Misc colors.
        public static string Reset() { return Colors.RESET; }
        public static string Bold(bool toggle) { return toggle ? Colors.BOLD : Colors.BOLD_OFF; }
        public static string Underline(bool toggle) { return toggle ? Colors.UNDERLINE : Colors.UNDERLINE_OFF; }
        public static string Inverse(bool toggle) { return toggle ? Colors.INVERSE : Colors.INVERSE_OFF; }
    }

    public static class Colors
    {
        public static string BLACK_FG = "\033[30m";
        public static string RED_FG = "\033[31m";
        public static string GREEN_FG = "\033[32m";
        public static string YELLOW_FG = "\033[33m";
        public static string BLUE_FG = "\033[34m";
        public static string MAGENTA_FG = "\033[35m";
        public static string CYAN_FG = "\033[36m";
        public static string WHITE_FG = "\033[37m";
        public static string BLACK_BG = "\033[40m";
        public static string RED_BG = "\033[41m";
        public static string GREEN_BG = "\033[42m";
        public static string YELLOW_BG = "\033[43m";
        public static string BLUE_BG = "\033[44m";
        public static string MAGENTA_BG = "\033[45m";
        public static string CYAN_BG = "\033[46sm";
        public static string WHITE_BG = "\033[47m";
        public static string BRT_BLACK_FG = "\033[90m";
        public static string BRT_RED_FG = "\033[91m";
        public static string BRT_GREEN_FG = "\033[92m";
        public static string BRT_YELLOW_FG = "\033[93m";
        public static string BRT_BLUE_FG = "\033[94m";
        public static string BRT_MAGENTA_FG = "\033[95m";
        public static string BRT_CYAN_FG = "\033[96m";
        public static string BRT_WHITE_FG = "\033[97m";
        public static string BRT_BLACK_BG = "\033[100m";
        public static string BRT_RED_BG = "\033[101m";
        public static string BRT_GREEN_BG = "\033[102m";
        public static string BRT_YELLOW_BG = "\033[103m";
        public static string BRT_BLUE_BG = "\033[104m";
        public static string BRT_MAGENTA_BG = "\033[105m";
        public static string BRT_CYAN_BG = "\033[106m";
        public static string BRT_WHITE_BG = "\033[107m";
        public static string RESET = "\033[0m";
        public static string BOLD = "\033[1m";
        public static string UNDERLINE = "\033[4m";
        public static string INVERSE = "\033[m";
        public static string BOLD_OFF = "\033[21m";
        public static string UNDERLINE_OFF = "\033[24m";
        public static string INVERSE_OFF = "\033[27m";
    }

    public enum COLOR_TYPE
    {
        FG,
        BG
    }

Program.cs

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($"{ColorManager.BrightGreen(COLOR_TYPE.FG)}Hello, World!{ColorManager.Reset()}");
        }
    }

Expected Behavior

Would print "Hello, World!" in bright green then reset the console's color.

Actual Behavior

HELP ME

Originally created by @ghost on GitHub (Jul 31, 2021). ### Windows Terminal version (or Windows build number) 1.9.1942.0 ### Other Software _No response_ ### Steps to reproduce Make a new .NET console application. ```Color.CS``` ```cs public static class ColorManager { // Regular colors. public static string Black(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BLACK_FG : Colors.BLACK_BG; } public static string Red(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.RED_FG : Colors.RED_BG; } public static string Green(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.GREEN_FG : Colors.GREEN_BG; } public static string Yellow(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.YELLOW_FG : Colors.YELLOW_BG; } public static string Blue(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BLUE_FG : Colors.BLUE_BG; } public static string Magenta(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.MAGENTA_FG : Colors.MAGENTA_BG; } public static string Cyan(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.CYAN_FG : Colors.CYAN_BG; } public static string White(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.WHITE_FG : Colors.WHITE_BG; } // Bright colors. public static string BrightBlack(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_BLACK_FG : Colors.BRT_BLACK_BG; } public static string BrightRed(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_RED_FG : Colors.BRT_RED_BG; } public static string BrightGreen(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_GREEN_FG : Colors.BRT_GREEN_BG; } public static string BrightYellow(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_YELLOW_FG : Colors.BRT_YELLOW_BG; } public static string BrightBlue(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_BLUE_FG : Colors.BLUE_BG; } public static string BrightMagenta(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_MAGENTA_FG : Colors.BRT_MAGENTA_BG; } public static string BrightCyan(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_CYAN_FG : Colors.BRT_CYAN_BG; } public static string BrightWhite(COLOR_TYPE type) { return type == COLOR_TYPE.FG ? Colors.BRT_WHITE_FG : Colors.BRT_WHITE_BG; } // Misc colors. public static string Reset() { return Colors.RESET; } public static string Bold(bool toggle) { return toggle ? Colors.BOLD : Colors.BOLD_OFF; } public static string Underline(bool toggle) { return toggle ? Colors.UNDERLINE : Colors.UNDERLINE_OFF; } public static string Inverse(bool toggle) { return toggle ? Colors.INVERSE : Colors.INVERSE_OFF; } } public static class Colors { public static string BLACK_FG = "\033[30m"; public static string RED_FG = "\033[31m"; public static string GREEN_FG = "\033[32m"; public static string YELLOW_FG = "\033[33m"; public static string BLUE_FG = "\033[34m"; public static string MAGENTA_FG = "\033[35m"; public static string CYAN_FG = "\033[36m"; public static string WHITE_FG = "\033[37m"; public static string BLACK_BG = "\033[40m"; public static string RED_BG = "\033[41m"; public static string GREEN_BG = "\033[42m"; public static string YELLOW_BG = "\033[43m"; public static string BLUE_BG = "\033[44m"; public static string MAGENTA_BG = "\033[45m"; public static string CYAN_BG = "\033[46sm"; public static string WHITE_BG = "\033[47m"; public static string BRT_BLACK_FG = "\033[90m"; public static string BRT_RED_FG = "\033[91m"; public static string BRT_GREEN_FG = "\033[92m"; public static string BRT_YELLOW_FG = "\033[93m"; public static string BRT_BLUE_FG = "\033[94m"; public static string BRT_MAGENTA_FG = "\033[95m"; public static string BRT_CYAN_FG = "\033[96m"; public static string BRT_WHITE_FG = "\033[97m"; public static string BRT_BLACK_BG = "\033[100m"; public static string BRT_RED_BG = "\033[101m"; public static string BRT_GREEN_BG = "\033[102m"; public static string BRT_YELLOW_BG = "\033[103m"; public static string BRT_BLUE_BG = "\033[104m"; public static string BRT_MAGENTA_BG = "\033[105m"; public static string BRT_CYAN_BG = "\033[106m"; public static string BRT_WHITE_BG = "\033[107m"; public static string RESET = "\033[0m"; public static string BOLD = "\033[1m"; public static string UNDERLINE = "\033[4m"; public static string INVERSE = "\033[m"; public static string BOLD_OFF = "\033[21m"; public static string UNDERLINE_OFF = "\033[24m"; public static string INVERSE_OFF = "\033[27m"; } public enum COLOR_TYPE { FG, BG } ``` ```Program.cs``` ```cs class Program { static void Main(string[] args) { Console.WriteLine($"{ColorManager.BrightGreen(COLOR_TYPE.FG)}Hello, World!{ColorManager.Reset()}"); } } ``` ### Expected Behavior Would print "Hello, World!" in bright green then reset the console's color. ### Actual Behavior ![HELP ME](https://i.ibb.co/4Rj0GQk/why.png)
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 04:18:15 +00:00
Author
Owner

@orcmid commented on GitHub (Jul 31, 2021):

The actual output should reveal that \0 in the C# string "\033" is the NUL character and on output the string appears as "33", since NULs are ignored.

Try substituting "\x1b" for all of those "\033" groups in class Colors and see what happens.

The C/C++ language treatment of \0 as introducing the octal value of a code doesn't work in C#.

@orcmid commented on GitHub (Jul 31, 2021): The actual output should reveal that \0 in the C# string "\033" is the NUL character and on output the string appears as "33", since NULs are ignored. Try substituting "\x1b" for all of those "\033" groups in class Colors and see what happens. The C/C++ language treatment of \0 as introducing the octal value of a code doesn't work in C#.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14743