本帖最后由 CrLf 于 2015-10-31 16:06 编辑
32位或64位环境也都能支持 ansi 代码了
ansi 代码相关知识参考:http://baike.baidu.com/link?url= ... x5mSDdKlOGwIvWnHHrq
其中包含窗口、光标、前景背景色等功能
ANSICON by Jason Hood <jadoxa@yahoo.com.au>.
Version 1.66 (21 September, 2013). Freeware.
http://ansicon.adoxa.vze.com/
Process ANSI escape sequences in Windows console programs.
ansicon [-l<level>] [-i] [-I] [-u] [-U] [-m[<attr>]] [-p]
[-e|E string | -t|T [file(s)] | program [args]]
-l set the logging level (1=process, 2=module, 3=function,
+4=output, +8=append) for program (-p is unaffected)
-i install - add ANSICON to the AutoRun entry (also implies -p)
-u uninstall - remove ANSICON from the AutoRun entry
-I -U use local machine instead of current user
-m use grey on black ("monochrome") or <attr> as default color
-p hook into the parent process
-e echo string
-E echo string, don't append newline
-t display files ("-" for stdin), combined as a single stream
-T display files, name first, blank line before and after
program run the specified program
nothing run a new command processor, or display stdin if redirected
<attr> is one or two hexadecimal digits; please use "COLOR /?" for details.
It may start with '-' to reverse foreground and background (but not for -p).
简单说常用的用法有:- dir | grep --color=always -P \S+\.txt | ansicon
- ::从管道或重定向获取输入,并转义其中的 ansi 代码,此例为彩色显示
- ::该用法对中文的兼容性最好
复制代码
- dir | ansicon grep --color=always -P \S+\.txt
- ::和上一个例子效果基本一样的,但对中文的兼容性不佳
复制代码
- ansicon -i
- ::安装 ansicon,以后运行 cmd 时自动加载 ansicon
- ::还有个对应的 -u 开关可以反安装
复制代码
- ansicon -p
- ::注入到父进程中,使父进程支持 ansi 代码
复制代码 实测 -e 选项似乎有 bug,不建议使用该开关
如果没有用到注入功能,可以不需要 ansi.dll |