SaveConsole plugin for Take Command / TCC / TCC/LE

Version 1.4.7.2     2023-10-12

Charles Dye

Purpose:

This plugin implements a replacement for the internal SAVECONSOLE command.

Why would you want to replace the interal SAVECONSOLE? Well, SAVECONSOLE works fine in text mode, but in HTML mode it has some issues:

This plugin provides a SAVECONSOLE which addresses these issues. It’s much faster, and it produces smaller, syntactically valid HTML files which look decent in any modern browser. There are also a few new features, including support for directory aliases and saving to the clipboard.

Installation:

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

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

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

Plugin Features:

New command: SAVECONSOLE

New variables: _SAVECONFILE, _SAVECONMODE

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:

SAVECONSOLE — Save the console buffer to a text, HTML, or RTF file.

Syntax:
SAVECONSOLE /CP /CR /CRLF /BG:color /D /FS:size /H /L /LF /N:opts /O /Q /R /T /UTFx /V /W /X:cssfile /Y:css filename

/CPuse the console palette (HTML only)
/CRMacintosh line ends
/CRLFWindows line ends
/BG:colorspecify a background color (HTML only)
/Ddo not save colors (HTML and RTF only)
/FS:sizefont size (HTML and RTF only)
/Hsave as HTML
/Lline numbers
/LFUnix line ends (default)
/N:optsdisable features
/Oopen the output file when finished
/Qquietly
/Rsave as RTF
/Tinclude a header line
/UTF8save as UTF-8 (the default)
/UTF16save as UTF-16
/Vsave only the visible area of the console
/Wfull width (text only)
/X:cssfilelink to an external style sheet (HTML only)
/Y:cssadds internal CSS for the PRE tag (HTML only)
filenamethe file to create

Directory aliases are supported, and you can use CLIP: to save to the clipboard. If you do not specify a filename, you’ll get a ‘Save As’ dialog.

The default mode is to save as plain text, unless the filename ends in .HTML, .HTM, or .RTF.


/LF, /CR, and /CRLF let you select line-end characters; the default is /LF.

/BG:color allows you to choose a background color for the web page. Note that this option uses W3C color names, not the much smaller set of CGA colors supported by many TCC commands. This option only affects HTML mode; it is ignored in text mode.

/D prevents SAVECONSOLE from saving color information to an HTML or RTF file. This will produce a smaller file. /D has no effect when saving to a text file.

/FS:size lets you specify the font size. This option only affects HTML and RTF files. The allowed range is 6 to 48. /FS has no effect when saving to a text file.

/H saves the console buffer as HTML. The default is to save as plain text, unless the filename ends in .HTML, .HTM, or .RTF.


/N:opts lets you disable features:

Bdo not write a Byte Order Mark
Cdo not save colors (synonym for /D)
Ddisable the ‘Save As’ dialog (you must supply a filename)
Hdisable the custom hook procedure for the dialog
Ido not create an RTF info block (only affects RTF files)
Tdisable the ‘Save as type:’ control in the dialog

Suboptions may be combined, and the colon is optional.


/O automatically opens the output file in the default application after the save is complete. (/O is ignored when saving to CLIP:.)

/Q suppresses the final report.

/R saves the console buffer as RTF. Consider this mode experimental! It may be buggy as sin. Note that RTF files must use ASCII; /UTF8 and /UTF16 are ignored.

/T adds a header line with the console window’s title and the date and time to the top of the file.

/UTF8 and UTF16 let you specify the output character encoding. Note these limitations:

You can abbreviate these options to /U8 and /U16 if you wish.

/W saves trailing spaces at the ends of lines. I can’t imagine why you would want to do this; I only include this option for compatibility with TCC. /W has no effect in HTML or RTF mode.

/CP attempts to read the console palette, and use its color definitions instead of my default colors. /CP does not affect text files. This option requires Windows Vista or later. (It uses GetConsoleScreenBufferInfoEx, which does not exist in Windows XP.)


/X:cssfile includes a link in the HTML file’s header to an external style sheet. Note that SAVECONSOLE does not create this file or verify its existence. /X merely writes the appropriate reference to the output file; providing the cssfile is up to you. The filename is not canonicalized; it will be written to the output file as you entered it on the command line. Quote the cssfile if it contains spaces (bad idea!) or forward slashes. /X only affects HTML files.

You can use /X to override the HTML file’s internal styles. For example, your cssfile might contain a line:

PRE    { border: 16px ridge #6cf; border-radius: 48px; }

… to give your console dump a groovy 1970s border.


/Y:css lets you write CSS within the file’s header. Any CSS you specify will replace all of my default styles for the PRE tag, except for the colors.


If you do not specify a filename, or if it names a directory, SAVECONSOLE will display a ‘Save As’ dialog. Navigate to the desired directory and type a filename for your output file, or else click on an existing file to overwrite it. The file will be saved as plain text unless you specified either /H or /R. You can change the save mode within the dialog using the ‘Save as type:’ control.

You can disable the ‘Save As’ dialog with /ND. You can disable the ‘Save as type:’ control with /NT.



New Variables:

_SAVECONFILE — Returns the filename of the last SAVECONSOLE.

Syntax:
%_SAVECONFILE

If the last save was successful, this variable returns either a fully-qualified filename or CLIP:. If the last save failed, it returns *ERROR*. If SAVECONSOLE doesn’t even try to save — e.g. because of a syntax error or because the user canceled — the previous value of this variable will not be changed.



_SAVECONMODE — Returns the last SAVECONSOLE save mode.

Syntax:
%_SAVECONMODE

This function returns one of:

… or an empty string if SAVECONSOLE has not yet attempted to save the console. This variable is updated at the same time as _SAVECONFILE, after any attempted or successful save. It is not changed by syntax errors, syntax requests, or user cancellation.



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

Changes:


Version:Date:Changes:
1.4.7.22023-10-12Updated the plugin’s web address.
1.4.72023-09-07Added help text for SAVECONSOLE /N?.
1.4.6.22023-07-24Updated to the current version of w3ccolors.cpp.
1.4.6.12023-07-24Updated to the current version of ParseArgs.cpp.
1.4.62023-06-13Removed calls to QueryIsFile() to work around an issue in TCC v30.00.20.
1.4.5.32023-05-23Removed the trailing slash from the end of the charset tag.
1.4.5.22022-07-18Spelling correction. No changes to functionality.
1.4.5.12022-06-14Made RTF support a compile-time option (#define SAVECON_RTF_SUPPORT to enable).
1.4.52022-01-05Fix for trailing spaces with a different background color being lost. Also, I’m syncing the plugin version number with the version in the command’s source file — which is why this trivial change is marked by such a jump in the plugin version.
1.2.42021-11-24No longer entitizes non-breaking spaces.
1.2.32021-11-01Help text is now displayed via ShowCmdHelp(). Tweaked the default background color a bit.
1.2.22021-10-23Reduced the size of the UTF-8 translation buffer.
1.2.12021-10-16Added /NT. Now changing the file extension in the ‘Save As’ dialog’s edit control can automatically change the save format. Now _SAVECONMODE returns *ERROR* after a failed save. Documented /NH and /NI.
1.2.0.12021-07-13Minor tweaks to the VerInfo resource. No changes to the code.
1.2.02021-06-19A .htm extension triggers /H mode, the same as .html. Enabled the _SAVECONFILE and _SAVECONMODE variables.
1.1.12021-05-04If you combine /FS: and /Y:, /Y: wins.
1.1.02020-12-02Adds /Y: to embed CSS style info in the HTML header.
1.0.02020-11-16First release.

Status and Licensing:

This plugin is © Copyright 2023, Charles Dye. Unaltered copies of the binary and documentation files may be freely distributed without restriction. I make no guarantee and give no warranty for its operation. If you find a problem, you can report it in the JP Software support forum.

Download:

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