问题
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