Adds coloured output
This commit is contained in:
parent
65a7153572
commit
9146cf168d
3 changed files with 36 additions and 1 deletions
5
include/colored_output.hpp
Normal file
5
include/colored_output.hpp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::string colored_block(int color);
|
29
lib/colored_output.cpp
Normal file
29
lib/colored_output.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue