diff --git a/include/colored_output.hpp b/include/colored_output.hpp new file mode 100644 index 0000000..f855e85 --- /dev/null +++ b/include/colored_output.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include + +std::string colored_block(int color); diff --git a/lib/colored_output.cpp b/lib/colored_output.cpp new file mode 100644 index 0000000..68ce688 --- /dev/null +++ b/lib/colored_output.cpp @@ -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; + } +} diff --git a/lib/dynamic_grid.cpp b/lib/dynamic_grid.cpp index b1ab402..900f68a 100644 --- a/lib/dynamic_grid.cpp +++ b/lib/dynamic_grid.cpp @@ -1,4 +1,5 @@ #include "dynamic_grid.hpp" +#include "colored_output.hpp" #include @@ -90,7 +91,7 @@ void DynamicGrid::collapse(){ void DynamicGrid::print(std::ostream& out) const { for(auto y = H; y; --y){ 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" : ""); } } }