# TIP 305: ANSI Escape Sequence Support for Windows's Console Channel Driver
	Author:         David Gravereaux <davygrvy@pobox.com>
	State:          Withdrawn
	Type:           Project
	Vote:           Pending
	Created:        21-Feb-2007
	Post-History:   
	Discussions-To: news:comp.lang.tcl
	Tcl-Version:    8.5
-----

# Abstract

The console channel driver for windows \(win/tclWinConsole.c\) could support colors, cursor movement, and scrolling by embedding such commands in the stream to the console in the age-old tradition of ANSI\_X3.64-1979 escapes. By filtering-out such commands in the DriverOutputProc and doing the command actions, greater cross-platform support is enabled to other platforms \(such as Linux\) that have ANSI support.

# Rationale

A long time ago, in a land far, far away... DOS programmers wrote character-mode applications for a screen that was 80x25 cells large and had 16 colors and a few special attributes using a strange codepage called _IBM PC_ or _CP437_. And life wasn't that bad.

Currently, there appears to only be two ways to write such an application in Tcl:

 * Use the services of TWAPI to call the native Console API intrinsics.

 * Use the ck shell \(Curses Tcl Toolkit\).

This change proposal is similar to the first option, but the commands are placed in the stream in a standardized manner that gains us immediate support with Linux.

This change proposal is different than the second option in that only the output direction of the console driver is modified. No support is proposed for such things as raw keyscan and mouse events.

This change proposal will not effect the opening modes of the console,
therefore will not have an adverse change to any current scripts.

# Specification

This TIP proposes two changes visible at the script level. Firstly, the
**fconfigure** command will be able to set the speed of channels directed to the Windows console \(often being stdout and stderr\) via a **-baud** option. Secondly, channels directed to the Windows console will interpret ANSI control sequences as ANSI control sequences \(subject to the limitations outlined below\) and not directives to write characters.

The _blink_ and _underline_ SGR modes can not be supported due to OS limitations, nor can the color palette be modified to affirm color consistency.  _reverse_ and _concealed_ SGR modes can both be emulated, but _concealed_ has a security risk and is not a replacement for turning local echo off.

# Reference Implementation

A patch is currently being worked on. There is an ANSI test extension for wish available <http://www.pobox.com/~davygrvy/tclstuff/winAnsiCon12_pack.zip>  that
contains numerous test screens \(some with ansimations\) and appears to work perfectly.

# Copyright

This document has been placed in the public domain.

