I was hoping that would be as straight forward as
Console.out.println( "Test " + Console.RED + " RED " + Console.RESET )
but nothing happens, instead I see the control characters (e.g. "\033[31m"
). I tried both from within sbt (sbt run
) and normal IDEA run configuration run...
It works if your console supports color. I just tried it on a linux system via putty and got the expected result.
Edit: If you're looking to do this via windows you can use Ansicon to provide coloring in your standard command prompt.
Yup, the above works just fine. Also I've found that it's pretty neat to wrap those up as methods ".red" on String, like in this library https://github.com/ktoso/scala-rainbow
Lots of Ruby gems out there that do this, but not so much for Scala yet... :-)
from Scala Standard Library:
import scala.io.AnsiColor._
println(s"${REVERSED}${BOLD}My name ist ${GREEN}Green!${RESET} default font")
works in IntelliJ console too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With