ANSICON
Copyright 2005-2010 Jason Hood
Version 1.32. Freeware
===========
Description
===========
ANSICON provides ANSI escape sequences for Windows console programs. It
provides much the same functionality as `ANSI.SYS' does for MS-DOS.
============
Requirements
============
Windows 2000 Professional and later (it won't work with NT or 9X).
============
Installation
============
Add x86 (if your OS is 32-bit) or x64 (if 64-bit) to your PATH, or copy
the relevant files to a directory already on the PATH. Alternatively,
use option `-i' (or `-I') to install it permanently, by adding an entry
to CMD.EXE's AutoRun registry value (current user or local machine,
respectively). Uninstall simply involves closing any programs that are
currently using it, running with `-u' (and again with `-U') to remove
the AutoRun entry/ies, then removing the directory from PATH or deleting
the files.
No other changes are made.
---------
Upgrading
---------
Delete ANSI.dll, it has been replaced with ANSI32.dll.
Delete ANSI-LLA.dll, it has been replaced with ANSI-LLW.dll.
=====
Usage
=====
Running ANSICON with no arguments will start a new instance of the com-
mand processor (the program defined by the `ComSpec' environment var-
iable, typically `CMD.EXE'), or display standard input if it is redir-
ected. Passing the option `-p' (case sensitive) will enable the parent
process to recognise escapes (i.e. the command shell used to run ANSI-
CON). Use `-m' to set the current (and default) attribute to grey on
black ("monochrome"), or the attribute following the `m' (please use
`COLOR /?' for attribute values). The option `-e' will echo the command
line - the character after the `e' is ignored, the remainder is display-
ed verbatim; use `-E' to prevent a newline being written. The option
`-t' will display each file (or standard input if none or it is "-"), as
though they are a single file; `-T' will display the file name (in be-
tween "==> " and " <=="), a blank line (or an error message), the file
and another blank line. Anything else will be treated as a program and
its arguments. Eg: `ansicon -m30 -t file.ans' will display `file.ans'
using black on cyan as the default color.
Once installed, the ANSICON environment variable will be created. This
variable is of the form "WxH (wxh)", where W & H are the width and
height of the buffer and w & h are the width and height of the window.
The variable is updated whenever a program reads it directly (i.e. as
an individual request, not as part of the entire environment block).
For example, "set an" will not update it, but "echo %ansicon%" will.
The Windows API WriteFile and WriteConsoleA functions will set the num-
ber of characters written, not the number of bytes. When using a multi-
byte character set, this results in a smaller number (since multiple
bytes are used to represent a single character). Some programs recog-
nise this as a reduced write and will inadvertently repeat previous
characters. If you discover such a program, use the ANSICON_API envir-
onment variable to record it and override the API, returning the origin-
al byte count. Ruby is an example of such a program (at least, up till
1.9.2p0), so use "set ANSICON_API=ruby" to avoid the repitition. The
full syntax of the variable is:
ANSICON_API=[!]program;program;program...
PROGRAM is the name of the program, with no path and extension. The
leading exclamation inverts the usage, meaning the API will always be
overridden, unless the program is in the list. The variable can be made
permanent by going to System Properties, selecting the Advanced tab and
clicking Environment Variables (using XP; Vista/7 may be different).
=========
Sequences
=========
The following escape sequences are recognised.
\e[#A
CUU: CUrsor Up
\e[#B
CUD: CUrsor Down
\e[#C
CUF: CUrsor Forward
\e[#D
CUB: CUrsor Backward
\e[#E
CNL: Cursor Next Line
\e[#F
CPL: Cursor Preceding Line
\e[#G
CHA: Cursor Horizontal Absolute
\e[#;#H CUP: CUrsor Position
\e[#;#f HVP: Horizontal and Vertical Position
\e[s
SCP: Save Cursor Position
\e[u
RCP: Restore Cursor Position
\e[#J
ED: Erase Display
\e[#K
EL: Erase Line
\e[#L
IL: Insert Lines
\e[#M
DL: Delete Lines
\e[#@
ICH: Insert CHaracter
\e[#P
DCH: Delete CHaracter
\e[#;#;#m SGM: Set Graphics Mode
\e[#n
DSR: Device Status Report
\e[21t
Report (xterm) window's title
\e]0;titleBEL
Set (xterm) window's title (and icon)
`\e' represents the escape character (ASCII 27); `#' represents a
decimal number (optional, in most cases defaulting to 1). Regarding
SGM: bold will set the foreground intensity; underline and blink will
set the background intensity; conceal uses background as foreground.
I make a distinction between "\e[m" and "\e[0;...m". Both will restore
the original foreground/background colors (and so "0" should be the
first parameter); the former will also restore the original bold and
underline attributes, whilst the latter will explicitly reset them.
===========
Limitations
===========
The entire console buffer is used, not just the visible window.
If running CMD.EXE, its own COLOR will be the initial color.
The 64-bit version can inject into a 32-bit process, but the 32-bit
version will not inject into a 64-bit process.