By default, Windows cmd.exe do not support ANSI escape sequence color code. But the old version of cmd.exe, i.e. command.exe support ANSI.SYS if you set it up in CONFIG.SYS.
I usually use cmd.exe, after google for awhile, I find a tool which can let you write a .bat file with color text display when you run the .bat in cmd.exe.
You can download the cecho executable in the site: Colors to Batch Files
Unzip it and put the cecho.exe in C:\Windows\System32.
I have write a test file color_win32.bat.txt for testing, download it and rename it to color_win32.bat then run in cmd.exe.
Here is the output:
2010年12月18日星期六
ANSICON provides ANSI escape sequences for Windows console programs
Project: adoxa/ansicon - GitHub
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.
Download: http://adoxa.110mb.com/ansicon/
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.
2010年12月15日星期三
Console2+cmd+cygwin replace cmd.exe
Console2
Console is a Windows console window enhancement. Console features include: multiple tabs, text editor-like text selection, different background types, alpha and color-key transparency, configurable font, different window styles
Create new tabs
File -> New tab
Edit -> Setting -> Tabs
Add cmd tab
Title: cmd
Icon: <default>
Shell: C:\WINDOWS\system32\cmd.exe
Add cygwin tab
Title: cygwin
Icon: C:\cygwin\Cygwin.ico
Shell: C:\cygwin\bin\bash.exe --login –i
Save settings to user directory
Customize setting
Console
Shell: C:\WINDOWS\system32\cmd.exe
Appearance
Check:
Use tab titles
Show command
Show command in tabs
Trim tab titles to
Use tab icons
Behavior
Check:
Copy on select
Don’t wrap long lines
Clear selection on copy
Trim trailing spaces
Hotkeys
Paste: Ctrl+V
Mouse
Copy/clear selection: None
Select text: Left (uncheck shift)
Paste text: Middle
Add to Right click menu
Open cmd here
Add registry key:
HKEY_CLASSES_ROOT\Directory\shell\Open cmd here\command
Default: C:\Program Files\Console2\Console.exe -t cmd "%1"\
Open cygwin here
Run cygwin setup.exe, install chere package.
Add registry key:
HKEY_CLASSES_ROOT\Directory\shell\Open cygwin\command
C:\Program Files\Console2\Console.exe -t cygwin -r "/bin/xhere /bin/bash.exe '%L'"
Add to Right click context menu
Create a .reg file, copy and paste below lines and run the .reg file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\Open cmd here...]
[HKEY_CLASSES_ROOT\Directory\shell\Open cmd here...\command]
@="\"C:\\Program Files\\Console2\\Console.exe\" -t cmd -r \"/bin/xhere /bin/bash.exe '%L'\""
@="\"C:\\Program Files\\Console2\\Console.exe\" -t cmd -r \"/bin/xhere /bin/bash.exe '%L'\""
[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin here...]
[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin Here...\command]
@="\"C:\\Program Files\\Console2\\Console.exe\" -t cygwin -r \"/bin/xhere /bin/bash.exe '%L'\""
@="\"C:\\Program Files\\Console2\\Console.exe\" -t cygwin -r \"/bin/xhere /bin/bash.exe '%L'\""
訂閱:
文章 (Atom)

