其实是 context.exe 的副产品,索性也编译成 exe,需要 .net 库支持
没有什么独特的功能,只是将以往需要用 ANSI.SYS 才能支持的部分特性移植到 JScript8.0 上,仅支持其中的彩色显示功能。
请参考 ANSI.SYS 的例子和百科
其实功能没有 ansicon 多,所以更建议用 ansicon
例子: | dir | context --color txt | ansicolor | | ::彩色显示 dir 输出中包含 txt 的行及上下文 | | | | dir | grep --color=always -P \S+\.txt$ | ansicolor | | ::彩色显示 dir 输出中的 txt 文件名COPY |
源码: | @cc_on | | | | import System | | | | try{ | | ansisys_ConsoleColor(System.Console.In.ReadToEnd()) | | } | | catch(Err){ | | Environment.Exit(1) | | } | | | | function ansisys_ConsoleColor(strText){ | | strText.replace( | | /[^\x1b]+|(\x1b\[\x1b)|\x1b\[(\d\d(?:;\d\d)*)m|./g, | | function($0,$1,$2,$3){ | | if($1)return Console.Write('\x1b[') | | if($2){ | | var $2_regexp = /(\d)(\d)/g | | var exec | | while(exec = $2_regexp.exec($2)){ | | if(exec[0]=='00'){ | | Console.ResetColor() | | } else if(exec[1]=='3'){ | | Console.ForegroundColor = AnsiColor2ConsoleColor(exec[2]) | | } else if(exec[1]=='4'){ | | Console.BackgroundColor = AnsiColor2ConsoleColor(exec[2]) | | } | | } | | } else { | | Console.Write($0) | | } | | } | | ) | | | | function AnsiColor2ConsoleColor(strColor){ | | var ConsoleColorList = { | | '0':'Black', | | '1':'Red', | | '2':'Green', | | '3':'Yellow', | | '4':'Blue', | | '5':'Magenta', | | '6':'Cyan', | | '7':'White' | | } | | return(ConsoleColorList[strColor]) | | } | | }COPY |
|