Skip to content

Commit

Permalink
Factor or generic escape code logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbierner committed Jun 24, 2015
1 parent 963016f commit b2c0581
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions stt tetris.xcodeproj/project.pbxproj
Expand Up @@ -244,6 +244,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand Down
1 change: 0 additions & 1 deletion tetris/buffer.h
Expand Up @@ -10,7 +10,6 @@
template <size_t width, size_t height>
using empty_buffer = gen_grid<width, height, empty_pixel>;


/**
Draw another buffer on top of this buffer.
*/
Expand Down
23 changes: 11 additions & 12 deletions tetris/color.h
Expand Up @@ -17,27 +17,26 @@ enum class Color : unsigned {
Default = 9
};

template <unsigned x>
using escape_code =
string_join<String<>,
decltype("\x1b["_string),
int_to_string<x>,
String<'m'>>;

/**
Convert a color to its foreground color code.
*/
template <Color c>
using color_to_fg_code =
string_join<String<>,
decltype("\x1b["_string),
int_to_string<30 + static_cast<unsigned>(c)>,
String<'m'>>;

using color_to_fg_code = escape_code<30 + static_cast<unsigned>(c)>;

/**
Convert a color to its background color code.
*/
template <Color c>
using color_to_bg_code =
string_join<String<>,
decltype("\x1b["_string),
int_to_string<40 + static_cast<unsigned>(c)>,
String<'m'>>;
using color_to_bg_code = escape_code<40 + static_cast<unsigned>(c)>;

/**
Reset all colors.
*/
using colorReset = decltype("\x1b[0m"_string);
using colorReset = escape_code<0>;
1 change: 0 additions & 1 deletion tetris/main.cpp
Expand Up @@ -29,7 +29,6 @@ void serialize_game()
{
std::ofstream s;
s.open("current_game.h");
s << "#import \"game.h\"\n";
s << "using state = ";
print(s, serialize<state>{});
s << ";";
Expand Down

0 comments on commit b2c0581

Please sign in to comment.