-
Notifications
You must be signed in to change notification settings - Fork 3
04 Printing to the console
Vladyslav Pekker edited this page Feb 2, 2017
·
14 revisions
In the StylePrintModule spells shadows* methods print
and println
, originally defined in scala.Predef. These methods merely wrap their respective inputs in a call to styled (read more) before delegating to scala.Console, which scala.Predef would have done:
def println(input: Any = "")(implicit style: AnsiModule#AnsiStyle = AnsiStyle.Reset) =
Console.println(styled(input)(style))
This allows you to do the following:
scala> println("yellow " + "green".green + " yellow")(AnsiStyle.Yellow)
yellow green yellow
The StylePrintModule also contains the method printerr
, which looks like this:
def printerr(error: Any): Unit = Console.err.println(erred(error))
def erred(error: Any): String = styled(error)(AnsiStyle.Red)
* Every time print
or println
are invoked with spells in scope, the ones defined in spells are called instead of the ones defined in scala.Predef.
The defaults can be found in the reference.conf file and the Configuration wiki page shows how to override as well as retrieve them programmatically.