3 ms·
Just discovered today standard ANSI escape sequences work on Windows 10 command prompt. Even 24-bit color works fine! Try (not possible to copy paste, see [1])
by vardump 3y ago
Just discovered today standard ANSI escape sequences work on Windows 10 command prompt. Even 24-bit color works fine!
Try (not possible to copy paste, see [1]):
echo ^[[48;2;255;0;0mHello^[[0m
Hello is printed with a red (RGB(255,0,0)) background. "^[[0m" resets back to normal colors.
[1]: You can type ^[ (escape) by pressing CTRL-'['. Don't type ^ and [ as separate chars, that won't work.
- teddyh 3y agoJust don’t forget to add DEVICE=C:\DOS\ANSI.SYS to your C:\CONFIG.SYS file.
- zadjii 3y agoYou haven't needed to do that for like, 7 years now. RGB color support was added to the windows console in 2016: https://devblogs.microsoft.com/commandline/24-bit-color-in-the-windows-console/ https://devblogs.microsoft.com/commandline/24-bit-color-in-t...
- account42 3y ago> [1]: You can type ^[ (escape) by pressing CTRL-'['. Don't type ^ and [ as separate chars, that won't work. You can also use the \x1b escape code(or the \e alias) together with a command that accepts escape code in order to avoid nonprintable characters on the command-line: echo -e '\e[48;2;255;0;0mHello\e[0m' For scripts, always use printf though since echo -e is nonstandard and even plain echo differs in edge cases: printf '\e[48;2;255;0;0mHello\e[0m\n'
- vardump 3y agoPlease note I was talking about Windows 10/11 command prompt. Your tip works on Linux.