批处理之家's Archiver

CrLf 发表于 2015-10-31 14:46

ansicon 让命令行支持彩显等功能

[i=s] 本帖最后由 CrLf 于 2015-10-31 16:06 编辑 [/i]

32位或64位环境也都能支持 ansi 代码了

ansi 代码相关知识参考:[url]http://baike.baidu.com/link?url=7HFLjkKc222YGqQ0KRmZOFS8rHs5SmwTRQmdehj1dHDvSwCE-qiqmym-B1NxGrOyixMx5mSDdKlOGwIvWnHHrq[/url]
其中包含窗口、光标、前景背景色等功能

[quote]ANSICON by Jason Hood <jadoxa@yahoo.com.au>.
Version 1.66 (21 September, 2013).  Freeware.
[url]http://ansicon.adoxa.vze.com/[/url]

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).[/quote]

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

如果没有用到注入功能,可以不需要 ansi.dll

CrLf 发表于 2015-10-31 15:00

中文兼容性的问题已向作者反馈,但 xxxx | ansicon 的时候是没问题的,目前建议先使用这个写法

tmplinshi 发表于 2015-10-31 15:31

[quote]> grep --color=always \S+\.txt
grep: (standard input): Not enough space[/quote]
这是为什么?grep 从这个地址下载的 [url]http://batch-cn.qiniudn.com/tool/2.21/grep.exe[/url]

WIN7 X64 系统

CrLf 发表于 2015-10-31 15:49

[i=s] 本帖最后由 CrLf 于 2015-10-31 15:54 编辑 [/i]

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=176765&ptid=37885]3#[/url] [i]tmplinshi[/i] [/b]


    未指定 stdin 输入,突然发现例子写错了,应该是[code]dir | grep --color=always -P \S+\.txt | more[/code]

依山居 发表于 2015-10-31 21:59

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=176767&ptid=37885]4#[/url] [i]CrLf[/i] [/b]


    :lol gt 下载不了,这打包规则不合理。

CrLf 发表于 2015-10-31 22:35

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=176789&ptid=37885]5#[/url] [i]依山居[/i] [/b]


因为 Batch-CN 在下载多版本的工具时需要注明版本号和后缀名:[code]gt 1.66/ansicon.rar[/code]期待新版会有所改进

tmplinshi 发表于 2015-11-1 00:25

[i=s] 本帖最后由 tmplinshi 于 2015-11-1 00:28 编辑 [/i]

原来装了 [url=http://adoxa.altervista.org/cmdkey/index.html]CMDRead[/url] 之后直接支持彩色显示了。

[img]http://i11.tietuku.com/4218e415fe2ccc2d.png[/img]

CrLf 发表于 2015-11-1 01:19

[i=s] 本帖最后由 CrLf 于 2015-11-1 02:07 编辑 [/i]

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=176792&ptid=37885]7#[/url] [i]tmplinshi[/i] [/b]


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

bailong360 发表于 2015-11-1 10:31

[i=s] 本帖最后由 bailong360 于 2015-11-1 10:32 编辑 [/i]

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=176791&ptid=37885]6#[/url] [i]CrLf[/i] [/b]
[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=176789&ptid=37885]5#[/url] [i]依山居[/i] [/b]

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

不过这也是个bug,得捉

CrLf 发表于 2015-11-1 15:40

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=176802&ptid=37885]9#[/url] [i]bailong360[/i] [/b]


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

netbenton 发表于 2019-12-19 00:21

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=176794&ptid=37885]8#[/url] [i]CrLf[/i] [/b]


     clink 怎么用法?没有说明呢?

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.