SaveConsole plugin for Take Command / TCC / TCC/LE
Version 1.4.9.1 2024-10-03
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:
- It generates HTML that is... peculiar, let’s say. Missing elements and unclosed tags are among the more obvious issues.
- It produces files that are much larger than they need to be.
- It does strange things when it encounters an attribute word with any of the top eight bits set.
- It’s very very slow. On my system,
SAVECONSOLE /H
takes more than 30 seconds to save a 7,500-line console dump. - And finally, the resulting file doesn’t even look nice in a web browser. It renders, but it ain’t pretty.
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.
Note that this command will not work as intended under Windows Terminal.
In Windows Terminal, SAVECONSOLE
will only save the visible
portion of the console window, not the contents of the scrollback buffer.
This is because Windows Terminal is not fully compatible with the documented
Windows console APIs. TCC’s internal SAVECONSOLE
command
has the same issue. I don’t see any workaround unless Microsoft
chooses to improve Windows Terminal’s compatibility —
don’t hold your breath.
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 CODE | indicates text which must be typed exactly as shown. |
CODE | indicates optional text, which may be typed as shown or omitted. |
Bold italic | names a required argument; a value must be supplied. |
Regular italic | names 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:
flags /O /Q /R /T /UTF
x /V /W /X:
cssfile /Y:
css
filename
/CP | use the console palette (HTML only) |
/CR | Macintosh line ends |
/CRLF | Windows line ends |
/BG: color | specify a background color (HTML only) |
/D | do not save colors (HTML and RTF only) |
/FS: size | font size (HTML and RTF only) |
/H | save as HTML |
/L | line numbers |
/LF | Unix line ends (default) |
/N: flags | disable features |
/O | open the output file when finished |
/Q | quietly |
/R | save as RTF |
/T | include a header line |
/UTF8 | save as UTF-8 (the default) |
/UTF16 | save as UTF-16 |
/V | save only the visible area of the console |
/W | full width (text only) |
/X: cssfile | link to an external style sheet (HTML only) |
/Y: css | adds internal CSS for the PRE tag (HTML only) |
filename | the 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:
flags
lets you disable features:
B | do not write a Byte Order Mark |
C | do not save colors (synonym for /D ) |
D | disable the ‘Save As’ dialog (you must supply a filename) |
H | disable the custom hook procedure for the dialog |
I | do not create an RTF info block (only affects RTF files) |
T | disable the ‘Save as type:’ control in the dialog |
Suboptions may be combined in any order, 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:
- Writing to the CLIP: device always uses UTF-16.
- RTF files always use ASCII.
- You can use
/UTF16
to create UTF-16 HTML files. But note that such files may fail validation; UTF-16 is discouraged in HTML5.
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:
- text
- HTML
- RTF
- *ERROR*
… 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.9.1 | 2024-10-03 | Changed http:// to https:// in the PLUGININFO block.
ParseInt() now supports octal with a leading 0o . |
1.4.9 | 2024-06-07 | Uses FindMyWindow() to get the correct owner
window for the ‘Save As’ dialog. (Should help with restoring focus
after closing a dialog launched from, say, Windows Terminal.) Tweaks to the ‘short’ help text. |
1.4.8.1 | 2024-06-06 | Improved the /N: help text a bit. |
1.4.8 | 2024-06-05 | Now SAVECONSOLE uses
SetWindowSubclass(),
RemoveWindowSubclass(),
DefSubclassProc(),
etc. to subclass the combo-box control: probably safer than hacking around with
Get/SetWindowLongPtr(). Added /N: to the help text. |
1.4.7.3 | 2023-10-15 | Updated ShowCmdHelp() to return all four components of the plugin’s version number. |
1.4.7.2 | 2023-10-12 | Updated the plugin’s web address. |
1.4.7 | 2023-09-07 | Added help text for SAVECONSOLE /N? . |
1.4.6.2 | 2023-07-24 | Updated to the current version of w3ccolors.cpp. |
1.4.6.1 | 2023-07-24 | Updated to the current version of ParseArgs.cpp. |
1.4.6 | 2023-06-13 | Removed calls to QueryIsFile() to work around an issue in TCC v30.00.20. |
1.4.5.3 | 2023-05-23 | Removed the trailing slash from the end of the charset tag. |
1.4.5.2 | 2022-07-18 | Spelling correction. No changes to functionality. |
1.4.5.1 | 2022-06-14 | Made RTF support a compile-time option (#define SAVECON_RTF_SUPPORT to enable). |
1.4.5 | 2022-01-05 | Fix 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.4 | 2021-11-24 | No longer entitizes non-breaking spaces. |
1.2.3 | 2021-11-01 | Help text is now displayed via ShowCmdHelp(). Tweaked the default background color a bit. |
1.2.2 | 2021-10-23 | Reduced the size of the UTF-8 translation buffer. |
1.2.1 | 2021-10-16 | Added /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.1 | 2021-07-13 | Minor tweaks to the VerInfo resource. No changes to the code. |
1.2.0 | 2021-06-19 | A .htm extension triggers /H
mode, the same as .html. Enabled the _SAVECONFILE
and _SAVECONMODE variables. |
1.1.1 | 2021-05-04 | If you combine /FS:
and /Y: , /Y: wins. |
1.1.0 | 2020-12-02 | Adds /Y: to embed CSS
style info in the HTML header. |
1.0.0 | 2020-11-16 | First release. |
Status and Licensing:
This plugin is © Copyright 2024, 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 https://charlesdye.net/dl/saveconsole.zip.