How to colorize the standard output in scala with ansi codes

陌路散爱 提交于 2019-12-08 10:24:38

问题


Is there a scala library that can help colorize text written to the standard output?

This library should take advantage of the scala string interpolation mechanic.


回答1:


If you're using scala 2.11+ you can use this library : https://github.com/backuity/ansi-interpolator

It uses a macro to transform your strings at compile time, and supports nesting:

ansi"Text containing ansi tags such as %bold{bold text} or %underline{can be %yellow{nested}}"

// you can also use string interpolation:
val someMsg = "hey"
ansi"My msg %bold{in bold: $someMsg}"


来源:https://stackoverflow.com/questions/27229533/how-to-colorize-the-standard-output-in-scala-with-ansi-codes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!