找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 26821|回复: 10

[文本处理] ansicon 让命令行支持彩显等功能

[复制链接]
发表于 2015-10-31 14:46:56 | 显示全部楼层 |阅读模式
本帖最后由 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).


简单说常用的用法有:
  1. dir | grep --color=always -P \S+\.txt | ansicon
  2. ::从管道或重定向获取输入,并转义其中的 ansi 代码,此例为彩色显示
  3. ::该用法对中文的兼容性最好
复制代码
  1. dir | ansicon grep --color=always -P \S+\.txt
  2. ::和上一个例子效果基本一样的,但对中文的兼容性不佳
复制代码
  1. ansicon -i
  2. ::安装 ansicon,以后运行 cmd 时自动加载 ansicon
  3. ::还有个对应的 -u 开关可以反安装
复制代码
  1. ansicon -p
  2. ::注入到父进程中,使父进程支持 ansi 代码
复制代码
实测 -e 选项似乎有 bug,不建议使用该开关

如果没有用到注入功能,可以不需要 ansi.dll
 楼主| 发表于 2015-10-31 15:00:20 | 显示全部楼层
中文兼容性的问题已向作者反馈,但 xxxx | ansicon 的时候是没问题的,目前建议先使用这个写法
发表于 2015-10-31 15:31:07 | 显示全部楼层
> grep --color=always \S+\.txt
grep: (standard input): Not enough space

这是为什么?grep 从这个地址下载的 http://batch-cn.qiniudn.com/tool/2.21/grep.exe

WIN7 X64 系统
 楼主| 发表于 2015-10-31 15:49:57 | 显示全部楼层
本帖最后由 CrLf 于 2015-10-31 15:54 编辑

回复 3# tmplinshi


    未指定 stdin 输入,突然发现例子写错了,应该是
  1. dir | grep --color=always -P \S+\.txt | more
复制代码
发表于 2015-10-31 21:59:13 | 显示全部楼层
回复 4# CrLf


    gt 下载不了,这打包规则不合理。
 楼主| 发表于 2015-10-31 22:35:07 | 显示全部楼层
回复 5# 依山居


因为 Batch-CN 在下载多版本的工具时需要注明版本号和后缀名:
  1. gt 1.66/ansicon.rar
复制代码
期待新版会有所改进
发表于 2015-11-1 00:25:50 | 显示全部楼层
本帖最后由 tmplinshi 于 2015-11-1 00:28 编辑

原来装了 CMDRead 之后直接支持彩色显示了。

 楼主| 发表于 2015-11-1 01:19:43 | 显示全部楼层
本帖最后由 CrLf 于 2015-11-1 02:07 编辑

回复 7# tmplinshi


    实测 CMDRead 对输入输出无影响,兄台图中的红字估计是 ansicon 的效果
    倒是发现这个是 32/64 合一的,顺便一搜又发现了 clink,快捷键相当强大,还能加载 lua 扩展脚本
http://www.bathome.net/s/tool/?key=clink

评分

参与人数 1技术 +1 收起 理由
tmplinshi + 1 1

查看全部评分

发表于 2015-11-1 10:31:07 | 显示全部楼层
本帖最后由 bailong360 于 2015-11-1 10:32 编辑

回复 6# CrLf
回复 5# 依山居

这个问题已经改进过了
但是新版gt默认是从本地list中读取,而本地不一定是最新,所以就那个了...
先键入不带参数的gt更新一次列表后就可以不带版本号直接下载了

不过这也是个bug,得捉
 楼主| 发表于 2015-11-1 15:40:17 | 显示全部楼层
回复 9# bailong360


其实可以根据时间间隔判断是否更新列表,比如离上次下载时不是同一分钟就更新列表,但考虑到时间格式的问题,还需要作兼容设计:
文件修改时间刚好是精确到分钟的,所以可以下载时先创建一个空的临时文件,比较该文件与 tool.txt 的 %%~ti,不相同则更新 tool.txt

评分

参与人数 1技术 +1 收起 理由
bailong360 + 1 欸哟卧槽,我咋就没想到呢

查看全部评分

发表于 2019-12-19 00:21:15 | 显示全部楼层
回复 8# CrLf


     clink 怎么用法?没有说明呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:37 , Processed in 0.024667 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表