views:

126

answers:

2

How to use colours in console output in Scala or Java?

+2  A: 

Sample code from JavaWorld

import java.awt.Color;
import enigma.console.*;
import enigma.core.Enigma;
public class Main
{
    public static void main(String[] args)
    {
        TextAttributes attrs = new TextAttributes(Color.BLUE, Color.WHITE);
        s_console.setTextAttributes(attrs);
        System.out.println("Hello World!");
    }
    private static final Console s_console;
    static
    {
        s_console = Enigma.getConsole("Hellow World!");
    }
}

Visit the above link for more details and approaches.

pavanlimo
+6  A: 

Try...

scala> Console.BLUE
res0: java.lang.String =

OK, well, the text has gone blue. Honest!

scala> Console.YELLOW_B
res2: java.lang.String =

And you can see the background is, um, yellow.

oxbow_lakes