|
[yoda-svn] r330 - trunk/testsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgTue Aug 23 09:51:13 BST 2011
Author: buckley Date: Tue Aug 23 09:51:12 2011 New Revision: 330 Log: Adding a bunch of macros for coloured terminal output in tests Added: trunk/tests/Formatting.h Modified: trunk/tests/TestHisto1Da.cc Added: trunk/tests/Formatting.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tests/Formatting.h Tue Aug 23 09:51:12 2011 (r330) @@ -0,0 +1,29 @@ +#ifndef YODA_FORMATTING_H +#define YODA_FORMATTING_H + +#include <iostream> +#include <unistd.h> + + +#define MSG(msg) \ + do { \ + std::cout << msg << std::endl; \ + } while (0) + + +#define COLOR_(msg, code) \ + (isatty(1) ? code : "") << msg << (isatty(1) ? "\033[0m" : "") + + +#define RED(msg) COLOR_(msg, "\033[0;31m") +#define GREEN(msg) COLOR_(msg, "\033[0;32m") +#define YELLOW(msg) COLOR_(msg, "\033[0;33m") +#define BLUE(msg) COLOR_(msg, "\033[0;34m") + +#define MSG_RED(x) MSG_(RED(x)) +#define MSG_GREEN(x) MSG_(GREEN(x)) +#define MSG_YELLOW(x) MSG_(YELLOW(x)) +#define MSG_BLUE(x) MSG_(BLUE(x)) + + +#endif Modified: trunk/tests/TestHisto1Da.cc ============================================================================== --- trunk/tests/TestHisto1Da.cc Tue Aug 23 01:54:26 2011 (r329) +++ trunk/tests/TestHisto1Da.cc Tue Aug 23 09:51:12 2011 (r330) @@ -1,7 +1,7 @@ #include "YODA/Histo1D.h" +#include "Formatting.h" #include <cmath> #include <iostream> -#include <unistd.h> using namespace std; using namespace YODA; @@ -29,10 +29,7 @@ cout << "Histo:" << endl; for (vector<HistoBin1D>::const_iterator b = h.bins().begin(); b != h.bins().end(); ++b) { const int numElements = static_cast<int>(round(20 * b->height()/maxHeight)); - cout << string().insert(0, numElements, '=') << " "; - cout << (isatty(1) ? "\033[0;37m" : "") - << b->height() - << (isatty(1) ? "\033[0m" : "") << endl; + MSG(string().insert(0, numElements, '=') << " " << RED(b->height())); } return EXIT_SUCCESS;
More information about the yoda-svn mailing list |