加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

让groovy控制台程序拥有彩色输出"面孔"

发布时间:2020-12-14 16:58:00 所属栏目:大数据 来源:网络整理
导读:?结合JNA的使用可以让groovy的控制台程序拥有linux终端一般的彩色数据效果。需要jna.jar包放到classpath可以找到的路径下就可以了。 import ?com.sun.jna.win32.StdCallLibrary; import ?com.sun.jna.*; public ? interface ?Kernel32? extends ?StdCallLibr
?结合JNA的使用可以让groovy的控制台程序拥有linux终端一般的彩色数据效果。需要jna.jar包放到classpath可以找到的路径下就可以了。
  1. import?com.sun.jna.win32.StdCallLibrary;
  2. import?com.sun.jna.*;
  3. public?interface?Kernel32?extends?StdCallLibrary?{
  4. ???Kernel32?INSTANCE?=?(Kernel32)?Native.loadLibrary("kernel32",?Kernel32.class);
  5. ???int?GetStdHandle(int?stdHand);
  6. ???boolean?SetConsoleTextAttribute(int?hConsoleOutput,?int?textAtt);
  7. }
  8. def?out={color,str->
  9. ????int?ptr=?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的参数的具体颜色,可以打开一个控制台然后查看属性


黑色 是数字 0? 以此类推

最后我再这个基础上改了一个数据比对程序,下面是效果图

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读