让groovy控制台程序拥有彩色输出"面孔"
结合JNA的使用可以让groovy的控制台程序拥有linux终端一般的彩色数据效果。需要jna.jar包放到classpath可以找到的路径下就可以了。<div class="highlighter">
[*]importcom.sun.jna.win32.StdCallLibrary;
[*]importcom.sun.jna.*;
[*]
[*]publicinterfaceKernel32extendsStdCallLibrary{
[*]Kernel32INSTANCE=(Kernel32)Native.loadLibrary("kernel32",Kernel32.class);
[*]intGetStdHandle(intstdHand);
[*]booleanSetConsoleTextAttribute(inthConsoleOutput,inttextAtt);
[*]}
[*]
[*]
[*]defout={color,str->
[*]intptr=Kernel32.INSTANCE.GetStdHandle(-11);
[*]Kernel32.INSTANCE.SetConsoleTextAttribute(ptr,color);
[*]print(str);
[*]Kernel32.INSTANCE.SetConsoleTextAttribute(ptr,3);
[*]}
[*]
[*]
[*]out(13,"windows?"+Platform.isWindows());
[*]out(14,"X11?"+Platform.isX11());
页:
[1]