1
Fork 0

Adds coloured output

This commit is contained in:
Joshua Moerman 2014-02-18 16:12:04 +01:00
parent 65a7153572
commit 9146cf168d
3 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1,5 @@
#pragma once
#include <string>
std::string colored_block(int color);

29
lib/colored_output.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "colored_output.hpp"
static const bool disable_colors = false;
static const std::string reset = "\x1b[49;39m";
static const std::string colors[12] = {
"\x1B[33;43m", //yellow
"\x1B[91;101m", //bright red
"\x1B[94;104m", //bright blue
"\x1B[92;102m", //bright green
"\x1B[95;105m", //bright magenta
"\x1B[96;106m", //bright cyan
"\x1B[93;103m", //bright yellow
"\x1B[31;41m", //red
"\x1B[34;44m", //blue
"\x1B[32;42m", //green
"\x1B[35;45m", //magenta
"\x1B[36;46m" //cyan
};
std::string colored_block(int color){
if(disable_colors){
if(color == 0) return " ";
else return std::to_string(color);
} else {
if(color == 0) return " ";
else return colors[color % 12] + std::to_string(color) + " " + reset;
}
}

View file

@ -1,4 +1,5 @@
#include "dynamic_grid.hpp" #include "dynamic_grid.hpp"
#include "colored_output.hpp"
#include <iostream> #include <iostream>
@ -90,7 +91,7 @@ void DynamicGrid::collapse(){
void DynamicGrid::print(std::ostream& out) const { void DynamicGrid::print(std::ostream& out) const {
for(auto y = H; y; --y){ for(auto y = H; y; --y){
for(auto x = 0; x < W; ++x){ for(auto x = 0; x < W; ++x){
out << get({x, y-1}) << (x == W-1 ? '\n' : ' '); out << colored_block(get({x, y-1})) << (x == W-1 ? "\n" : "");
} }
} }
} }