Using the command prompt on Windows can be useful for many tasks, but the default black and white color scheme can get boring. Luckily, there are ways to customize and save color settings in cmd to make it more visually appealing or easier to read. In this comprehensive guide, we’ll cover everything you need to know about saving color in cmd.
An Introduction to Using Color in Cmd
The cmd shell on Windows doesn’t support true color by default. However, you can enable color output with the color command. This sets the foreground and background colors for text output in the cmd window.
Here is the basic syntax for the color command:
color [attribute]
[attribute] can be one of the following values:
0 | Reset to default colors (white on black) |
1 | Blue on black |
2 | Green on black |
3 | Cyan on black |
4 | Red on black |
5 | Purple on black |
6 | Yellow on black |
7 | White on black |
8 | Gray on black |
9 | Light blue on black |
For example, to set the text color to red, you would run:
color 4
This will set the default foreground color to red. The background color will remain black unless changed.
You can also combine two attributes to set both foreground and background. The first is the background, second is the foreground. For example:
color 1F
This will set the background to blue and the foreground to white text.
Saving Color Settings in Cmd
The color settings in cmd will reset each time you open a new command prompt window. To make the colors persistent, you need to save them to a profile.
Here are the steps to save color settings in cmd:
- Open the command prompt window
- Set your desired color with the color command, like
color 4F
- Type
prompt $G
to save the colors - Close the command prompt window
The $G
sequence in the prompt command tells cmd to persist the current colors. Now whenever you open a new cmd window, the colors will automatically be set.
Creating Reusable Cmd Color Schemes
Typing the prompt and color commands each time is tedious. For more reusable color settings, you can create color schemes in a batch file.
Here is an example color scheme batch file called scheme.bat:
@echo off color 1F prompt $G
This sets the color to blue on white and saves it. To use the scheme, simply run:
scheme.bat
You can create multiple batch files for different color schemes and run the one you want to load those colors.
Customizing Colors Further
The basic color command gives you 16 foreground and background color options. To customize colors further, you need to enable ANSI escape sequences in cmd.
Run this command to enable ANSI:
reg add HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1
Now you can use ANSI escape codes to set colors and formatting like bold, underline, and text background.
Here are some common ANSI codes:
\033[0m | Reset to default colors and style |
\033[1m | Bold text |
\033[4m | Underlined text |
\033[30m | Black foreground |
\033[31m | Red foreground |
\033[32m | Green foreground |
\033[33m | Yellow foreground |
\033[34m | Blue foreground |
\033[35m | Purple foreground |
\033[36m | Cyan foreground |
\033[37m | White foreground |
\033[40m | Black background |
\033[41m | Red background |
\033[42m | Green background |
\033[43m | Yellow background |
\033[44m | Blue background |
\033[45m | Purple background |
\033[46m | Cyan background |
\033[47m | White background |
For example, to set bright green text on a blue background, you would run:
echo \033[1;32;44mBright green on blue \033[0m Reset to default
The formatting will apply from where it’s set until you reset with \033[0m. This allows coloring specific text in your output.
Custom Color Profiles with ANSI Codes
You can define reusable color profiles using ANSI escape codes in batches files too. Here is an example with a purple color scheme:
@echo off echo \033[1;35;47m prompt $G
This sets bright purple text on a white background. Run the batch to load the colors into your cmd session.
Converting RGB to ANSI Escape Codes
To select custom RGB color values, you need to convert them to ANSI codes.
Here is the basic formula:
\033[38;2;; ;m
Where
\033[38;2;255;165;0m
You can use online converters to easily get the escape codes from RGB values. There are also converters for converting HEX color codes.
Saving ANSI Color Settings
To save ANSI colors to use permanently, you need to set the defaults in the registry:
reg add HKCU\Console /v DefaultColor /t REG_DWORD /d 1
This will enable ANSI colors by default. Then set your custom colors in a .reg file like:
default_colors.reg
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Console] "ScreenColors"="0;255;165;0" "PopupColors"="255;255;255;160"
Run or import this .reg file to set orange prompt text and pale yellow popups.
You can also edit the Windows registry manually if you prefer.
Potential Issues
Here are some troubleshooting tips for color issues:
- Make sure ANSI is enabled as shown above
- Some apps and utilities don’t support ANSI codes
- Background color might not work in Windows Terminal
- Reset properly with \033[0m instead of color 0
- Check colors on a dark mode cmd for visibility
Conclusion
Customizing cmd colors takes some work but can make your workflow more efficient and pleasing. The color and prompt commands provide basic options, while ANSI escape sequences allow full RGB color control. With the steps outlined here, you can create and save color schemes to spice up the command line.
Let us know if you have any other questions!