Handling Missing Numbers in ANSI Escape Sequences #40

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

Originally created by @GaryDYelle on GitHub (Dec 29, 2017).

Originally assigned to: @zadjii-msft on GitHub.

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [Version 10.0.16299.125]

  • What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)
test@PC2:~$ printf "\033[31mtest\n"
test (red)
test@PC2:~$ printf "\033[31;mtest\n"
test (red)
test@PC2:~$ printf "\033[31;0mtest\n"
test (white)
test@PC2:~$
  • What's wrong
    The second output is printed in red:
wsl
  • What should be happening instead:

The second output should be printed in white like on Linux:

wsl2

According to Wikipedia (https://en.wikipedia.org/wiki/ANSI_escape_code):

All common sequences just use the parameters as a series of semicolon-separated numbers such as 1;2;3. Missing numbers are treated as 0 (1;;3 acts like the middle number is 0, and no parameters at all in ESC[m acts like a 0 reset code).

Further details are available from:
https://superuser.com/questions/1280903/how-to-enable-colors-with-win32-openssh-and-putty

Originally created by @GaryDYelle on GitHub (Dec 29, 2017). Originally assigned to: @zadjii-msft on GitHub. * Your Windows build number: (Type `ver` at a Windows Command Prompt) `Microsoft Windows [Version 10.0.16299.125]` * What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots) ``` test@PC2:~$ printf "\033[31mtest\n" test (red) test@PC2:~$ printf "\033[31;mtest\n" test (red) test@PC2:~$ printf "\033[31;0mtest\n" test (white) test@PC2:~$ ``` * What's wrong The second output is printed in **red**: <img width="252" alt="wsl" src="https://user-images.githubusercontent.com/34944881/34443027-8df46ada-ecc6-11e7-99f2-7c8b140bd431.png"> * What should be happening instead: The second output should be printed in **white** like on Linux: <img width="303" alt="wsl2" src="https://user-images.githubusercontent.com/34944881/34444331-b77252b2-eccd-11e7-85e6-996cd3c94779.png"> According to Wikipedia (https://en.wikipedia.org/wiki/ANSI_escape_code): > All common sequences just use the parameters as a series of semicolon-separated numbers such as `1;2;3`. Missing numbers are treated as `0` (`1;;3` acts like the middle number is `0`, and no parameters at all in `ESC[m` acts like a `0` reset code). Further details are available from: https://superuser.com/questions/1280903/how-to-enable-colors-with-win32-openssh-and-putty
claunia added the Product-Conhost label 2026-01-30 21:40:23 +00:00
Sign in to join this conversation.
No Label Product-Conhost
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#40