I was looking at an old version of my site and I saw a Link to ANSI Escape Codes – you never really hear about anyone using these things any more – but they are still kind of great when you are writing terminal based code (which I often do) – I should probably start incorporating some of this into my terminal output for errors so that they stand out more.
EDIT: some notes on adding ANSI codes to shell scripts: http://misc.flogisoft.com/bash/tip_colors_and_formatting
#!/bin/env python
print "\033[31;5mERROR: \033[0m \033[31mSome message here \033[0m\n"
some examples:
colorfun.c – i was playing with ANSI colors back in about 1996
/*
* BiffSocko
* colorfun.c
* this program prints out a bunch of stuff in flashing colors
* it takes one command line string thingie to print or else it
* will default to something i choose
*/
#include
int main (int argc, char *argv[])
{
char *array;
int i=0;
/*
* check for correct usage and set up the variable array
*/
if( argc > 2){
printf("\033[31musage: %s
exit( -1);
}
if( argc == 1)
array=(char *)strdup("ANOTHER GREAT PROGRAM FROM BIFFSOCKO");
if(argc == 2)
array=(char *)strdup(argv[1]);
/*
* print out the array string in all the colors and
* make every other one flash
* (ANSI forground colors between 30 and 39 inclusive)
*/
system("clear");
for(i=31; i < 40; i++){
if( (i % 2) == 0)
printf("\033[31;5m %s \033[0m\n", array);
else
printf("\033[31m %s \033[0m\n", array);
}
exit( 0);
}
colortest.pl - more 1996 playing with ANSI escape characters
#!/usr/bin/perl
print "\033[31mERROR\033[0m\n";
print "\033[32mERROR\033[0m\n";
print "\033[33mERROR\033[0m\n";
print "\033[34mERROR\033[0m\n";
print "\033[35mERROR\033[0m\n";
print "\033[36mERROR\033[0m\n";
print "\033[37mERROR\033[0m\n";
print "\033[38mERROR\033[0m\n";
print "\033[39mERROR\033[0m\n";
print "=========================\n";
print "\033[41mERROR\033[0m\n";
print "\033[42mERROR\033[0m\n";
print "\033[33mERROR\033[0m\n";
print "\033[34mERROR\033[0m\n";
print "\033[35mERROR\033[0m\n";
print "\033[36mERROR\033[0m\n";
print "\033[37mERROR\033[0m\n";
print "\033[38mERROR\033[0m\n";
print "\033[39mERROR\033[0m\n";