StripAnsi plugin for Take Command / TCC / TCC/LE

beta version 0.92.0     2024-11-15

Charles Dye

Purpose:

This plugin provides functions to remove and count ANSI escape sequences in strings.

I am using Wikipedia as my authority on what constitutes an ANSI escape sequence. This version should count or remove CSI, OSC, nF, Fp, Fe, and Fs type sequences.

Installation:

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

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

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

Plugin Features:

New Functions:
@HASANSI@STRIPANSI

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.

Examples are shown in a gray box:

rem   This is an example:
set promptbw=%@stripansi[%prompt]

New Functions:

@HASANSI — Counts ANSI sequences in text.

Syntax:
%@HASANSI[text]

textthe string to examine

If text is empty or if it doesn’t contain any ANSI escape sequences, @HASANSI returns 0.

set test=This is ^e[1;31monly^e[m a test.
echo %@hasansi[%test]



@STRIPANSI — Removes ANSI sequences from text.

Syntax:
%@STRIPANSI[text]

textthe string to strip

set test=This is ^e[1;31monly^e[m a test.
echo %@stripansi[%test]



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.

StripAnsi 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 this plugin from https://charlesdye.net/dl/stripansi.zip.