结合JNA的使用可以让groovy的控制台程序拥有linux终端一般的彩色数据效果。需要jna.jar包放到classpath可以找到的路径下就可以了。
  1. importcom.sun.jna.win32.StdCallLibrary;
  2. importcom.sun.jna.*;
  3. publicinterfaceKernel32extendsStdCallLibrary{
  4. Kernel32INSTANCE=(Kernel32)Native.loadLibrary("kernel32",Kernel32.class);
  5. intGetStdHandle(intstdHand);
  6. booleanSetConsoleTextAttribute(inthConsoleOutput,inttextAtt);
  7. }
  8. defout={color,str->
  9. intptr=Kernel32.INSTANCE.GetStdHandle(-11);
  10. Kernel32.INSTANCE.SetConsoleTextAttribute(ptr,color);
  11. print(str);
  12. Kernel32.INSTANCE.SetConsoleTextAttribute(ptr,3);
  13. }
  14. out(13,"windows?"+Platform.isWindows());
  15. out(14,"X11?"+Platform.isX11());
运行一下就可以看到彩色数据的效果了。其中color的参数的具体颜色,可以打开一个控制台然后查看属性
让groovy控制台程序拥有彩色输出"面孔"
黑色 是数字 0 以此类推

最后我再这个基础上改了一个数据比对程序,下面是效果图
让groovy控制台程序拥有彩色输出"面孔"

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-12-17
  • 2021-12-05
  • 2021-06-16
  • 2022-02-18
  • 2021-06-10
猜你喜欢
  • 2022-12-23
  • 2021-09-22
  • 2021-10-24
  • 2021-04-05
  • 2021-04-04
  • 2021-10-19
相关资源
相似解决方案