The ColrC repo includes the ColrC Tool, which is a program that colorizes text from the command line. It offers all of the important features from the original colr tool, but operates much faster because it was written in a compiled language. You can have both of these installed at the same time. The ColrC version is known as colrc
, where the original is known as colr
.
If you would like to use the ColrC tool, you will have to build it or download it, and then install it.
The ColrC tool can be used in shell scripts or as a standalone application in a variety of ways. Long options are used in the examples, but they all have a single-letter short form as well:
The most basic use of colrc
is to colorize text (from arguments or stdin
). The FORE
, BACK
, and STYLE
arguments are optional, and order only matters when you're not using the explicit --fore
, --back
, and --style
flags.
For instance, creating some red text is as simple as:
If you want to colorize output from another program, use -
as the text:
If you only want to set the back color or style you would need to be explicit:
The Colr tool can make "rainbowized" text, much like lolcat
except faster (only because of the language choice).
The options for ColrC do not match lolcat
exactly, but if you would like to "rainbowize" some text, all you have to do is set the fore or back color to rainbow
:
One of the most common uses is to pipe some output to ColrC to make it prettier:
You can also "rainbowize" the background, and optionally set the fore color and style at the same time:
If you have a program that doesn't have a --color=never
or --nocolor
option, and you'd like to remove all escape-codes from it's output, use colrc
to strip them.
Using the section above as an example, I'll run fortune
through lolcat
and then "undo" all of those fancy colors:
The result is like running fortune
by itself. No colors.
The ColrC tool can parse output from another program and list all colors/styles that are found with an example, a name, and the string that produced them:
If that was too much information (too many codes), you can trim the output by listing only unique codes:
ColrC will translate any valid color name (BasicValue), 256-color value (ExtendedValue), RGB value, or Hex color. A "closest match" will be used for basic names and 256-color values when converting to/from RGB and Hex colors.
To get the closest matching color from an RGB value (for terminals that don't support them):
Same thing with hex values:
You'll notice that when you reverse the translation, you get a different RGB/Hex value: