Saturday, August 16, 2008

Java Color Console


Here's a Java snippet that prints color output to the console (in a VT100 emulating terminal, i.e., in linux only):

for (int i = 30; i < 38; i++) {
System.out.println("\033[" + i + "mHello " +
"\033[1;" + i + "mWorld!\033[m");
}

It works by "printing" special terminal control commands that change the color. There are other VT100 terminal control commands that let you move the cursor around, clear the screen, and other things.

Who needs Swing, when you can make old-school ASCII interfaces, right? No fancy libraries required either.

No comments: