Code Snippet: Unit Test Green/Red Bar for ANSI Terminals
If you like writing unit tests but you don't have a fancy "green bar/red bar" unit test window, here's a simple solution you can use in any ANSI terminal window. It looks like this:
It's a piece of cake with some ANSI escape codes. Here's the code:
#include <stdio.h>
void printTestResults(int numPass, int numFail)
{
if (numFail > 0)
printf("\x1b[37;41m"); /* white on red */
else
printf("\x1b[30;42m"); /* black on green */
printf("\x1b[2K"); /* clear to end of line */
printf("Test results: %d pass, %d fail (%d total)\n",
numPass, numFail, numPass + numFail);
printf("\x1b[0m"); /* reset colors */
printf("\x1b[2K"); /* clear to end of line */
}


Comments
ANSI terminals are one of the best ways to minimize the excess use of computing power. Not everyone needs full-fledged computers. For those that use computers for simple tasks, an inexpensive terminal connected to a server would not only save costs but would also help save the environment by saving a lot of energy in the long run. At the green news, we get people together who are interested in ecological issues, in order to make a lasting impact on our environment.
Posted by: J. Hoogstrate | December 20, 2009 1:53 AM
ANSI terminals are one of the best ways to minimize the excess use of computing power. Not everyone needs full-fledged computers. For those that use computers for simple tasks, an inexpensive terminal connected to a server would not only save costs but would also help save the environment by saving a lot of energy in the long run. At the green news, we get people together who are interested in ecological issues, in order to make a lasting impact on our environment.
Posted by: J. Hoogstrate | December 20, 2009 1:54 AM