Palette plugin for TCC, TCC/LE, and Take Command v28+

beta version 0.87.4.1     2024-03-13

Charles Dye

Purpose:

This plugin provides an easy way to display, change, load, and save the console color palette.

Note that it changes the colors of the console window. If the console window is not visible, you will not see any effect. Tabbed console wrappers like Take Command, Console2, and ConEmu hide the console window, so this plugin is generally not useful in such environments.

The happy exception is the latest version of Take Command. Since version 28, Take Command includes an IPC call to reload the Take Command tab’s palette from the console window’s. If you are running Take Command v28 or later, you can use PALETTE and your changes will be reflected in Take Command.

Installation:

To use this plugin, copy Palette.dll to to some known location on your hard drive. (If you are still using the 32-bit version of Take Command, take Palette-x86.dll instead of Palette.dll.) Load the .DLL file with a PLUGIN /L command, for example:

plugin /l c:\bin\tcmd\test\palette.dll

If you copy the .DLL file to a subdirectory named PlugIns within your Take Command program directory, the plugin will be loaded automatically when TCC starts.

Plugin Features:

New commands: PALETTE, PALEDIT

New functions: @PALETTE, @PICKCOLOR

Syntax Note:

The syntax definitions in the following text use these conventions for clarity:

BOLD CODEindicates text which must be typed exactly as shown.
CODEindicates optional text, which may be typed as shown or omitted.
Bold italicnames a required argument; a value must be supplied.
Regular italicnames an optional argument.
ellipsis…after an argument means that more than one may be given.

New Command:

PALETTE — Display or change the console palette.

Syntax:
PALETTE /Cn:color[,color…] /D /E /F:n /I /Kn:r,g,b[;r,g,b…] /Q /R:filename /S:filename /T /V /W /X

/Cn:redefine a console color; n = 0 (black) to 15 (bright white)
/Dload a built-in set of default colors
/Esuppress many error messages
/F:specify the output format
/Iallow incomplete palette files; use with /R
/Kn:redefine a color using separate red, green, and blue values
/Qquietly; use with /R or /S to suppress the success message
/R:filenameread the palette from a file
/S:filenamesave the palette to a file
/Tdisplay a test pattern
/Vverbose
/Wno warning if the console window is not visible
/Xoverwrite an existing file; use with /S

Quote any parameter which contains spaces, forward slashes, or other troublesome characters.


/Cn: lets you redefine one or more console colors. n is the console color index, 0 (black) through 15 (bright white). Color values may be given as W3C color names, or three- or six-digit hexadecimal RGB values with a leading #. If n is less than 15, you can give multiple values separated by commas to redefine several consecutive colors at once:

palette /c0:#000,#009,#090,#099,#900

… would redefine black, blue, green, cyan, and red.


/Kn:r,g,b also lets you redefine colors, but you give the red, green, and blue components individually, separated by commas. n is the console color index, 0 (black) through 15 (bright white). r, g, and b are decimal values from 0 to 255, or hexadecimal from 0x00 to 0xFF.

palette /k7:255,192,0

… redefines ‘white’ as a bright orange.

As with /Cn:, if n is less than 15 you can redefine multiple colors; separate them with semicolons.


/D loads a built-in set of default color definitions. There is nothing particularly special or artistic about these colors; they’re just legible. If you somehow wind up with an unreadable combination of colors, PALETTE /D is a quick way to restore readability. You cannot combine /D with /R:filename.


/F: lets you specify the format used to display color values:

nFormat:Example:
0six-digit hex RGB (the default)#ffff00
1three- or six-digit hex RGB#ff0
2color name, or six-digit RGBYellow
3color name, or three- or six-digit RGBYellow
4decimal red, green, blue255,255,0
5hex COLORREF (with leading 0x)0x00FFFF

/R:filename reads color values saved to a file. You may only give one /R:filename. If you combine /R: with /Cn:, the /Cn: values win. PALETTE recognizes its own save files; ColorTool’s .INI file format; and iTerm’s XML format.

If the /R: file does not contain definitions for all sixteen console colors, the normal behavior is to abort with an error message. If you also specify /I, PALETTE will load the colors defined in the file, and leave the rest unchanged.

The filename may also be an internet URL starting with http://, https://, or ftp:// :

palette /r="https://raw.githubusercontent.com/mbadolato/iTerm2-Color-Schemes/master/schemes/Brogrammer.itermcolors"


/S:filename saves the current console palette to a file. You can only have one /S:filename. The save format is determined by the filename’s extension:

.INI.INI format, readable by Microsoft’s ColorTool
.XML or .itermcolorsXML format
anything elsenative format (text)

There are several options that you can use along with /S: to write additional information to the save file, if desired. All of these are optional. Remember to quote any parameter which contains spaces.

/A:authorauthor’s name
/L:licenselicense information
/N:namecolor scheme name
/U:urlURL

You can also save the palette by redirecting PALETTE’s output to a file:

palette > MyPalette.txt


/V tells PALETTE to list the current console color values to stdout. The default behavior is to show this list only if you’re not doing anything else — not changing colors, not loading or saving to a file, not displaying a test pattern, etc. /V tells PALETTE to list color values in addition to whatever else you’re doing.



PALEDIT — Edit the console palette interactively.

Syntax:
PALEDIT /D /I filename

/Dload a built-in set of default colors
/Iallow incomplete palette files

The keys you can use in this editor:

0 - 9, A - Fchoose a console color to modify
change the background color
change the foreground color
Lload colors from a file
Ssave colors to a file
Iopen the Save File Info dialog
Ctrl-Zundo the last change
Ctrl-Yredo the last undo
F5redraw the screen
F8undo all changes; return to the original palette
Escexit the editor


New Functions:

@PALETTE — Returns the current value of a console color.

Syntax:
%@PALETTE[n,fmt]

nthe console color index, 0 (black) to 15 (bright white)
fmtthe format in which to return the color value

The fmt parameter specifies the format of the returned value:

fmtFormat:Example:
0six-digit hex RGB (the default)#ffff00
1three- or six-digit hex RGB#ff0
2color name, or six-digit RGBYellow
3color name, or three- or six-digit RGBYellow
4decimal red, green, blue255,255,0
5hex COLORREF (with leading 0x)0x00FFFF

echo %@palette[7]
#cccccc

echo %@palette[7,1]
#ccc

echo %@palette[14,4]
249,241,165



@PICKCOLOR — Opens a color picker dialog and returns the user’s chosen color.

Syntax:
%@PICKCOLOR[color,fmt,title]

colorthe initial color
fmtthe format in which to return the user’s color
titlea title for the dialog

@PICKCOLOR opens that same dialog that TCC’s built-in @COLOR function does, but with several improvements. Input and output both use standard W3C color formats. You can specify the output format and set a title for the dialog box. The ‘Custom colors’ area is initialized with the sixteen console colors. And last but definitely not least, the dialog pops up on top of the Take Command window, not underneath it. These changes are mainly for the benefit of PALEDIT, but they seem useful enough that I’ve exposed them through this function.

The initial color may be entered as a W3C color name; a six- or three-digit hexadecimal RGB value with a leading #; a console color index 0 - 15 with a leading $; or as decimal red, green, and blue values, separated by commas:

Input Format:Example:
W3C color nameAqua
six-digit hex RGB#00ffff
three-digit hex RGB#0ff
console color index$11
red,green,blue0,255,255

The fmt parameter specifies the format of the returned value:

fmtFormat:Example:
0six-digit hex RGB (the default)#ffff00
1three- or six-digit hex RGB#ff0
2color name, or six-digit RGBYellow
3color name, or three- or six-digit RGBYellow
4decimal red, green, blue255,255,0
5hex COLORREF (with leading 0x)0x00FFFF

If the user cancels the dialog, @PICKCOLOR returns 0.



Automatic Palette Load:

When this plugin is loaded, it will look for a file named Palette.auto to load automatically. It looks first in TCC.EXE’s directory. If that fails, it will try the .DLL file’s directory next.

The autoload file must contain definitions for all sixteen colors. If any of the 16 console colors is not defined, the file will not be loaded.

Startup Message:

This plugin displays an informational line when it initializes. The message will be suppressed in transient or pipe shells. You can disable it for all shells by defining an environment variable named NOLOADMSG, for example:

set /e /u noloadmsg=1

Status and Licensing:

Consider this beta software. It may well have issues. Try it at your own risk. If you find a problem, you can report it in the JP Software support forum.

Palette is currently licensed only for testing purposes. I may make binaries and source code available under some free license once I consider it ready for use.

Download:

You can download the current version of the plugin from http://charlesdye.net/dl/palette.zip.