Created
August 9, 2014 09:36
-
-
Save ShigekiKarita/d91fa0bdcd213c609604 to your computer and use it in GitHub Desktop.
corlor_stdout.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
// kaki sute module | |
namespace ksm | |
{ | |
enum class colors : std::uint8_t | |
{ | |
black, red, green, yellow, blue, magenta, cyan, white, none | |
}; | |
std::string to_string( const colors c ) | |
{ | |
return std::to_string(static_cast<std::uint8_t>(c)); | |
} | |
void write() {} | |
template < class T, class ... Ts > | |
void write( const T & head, const Ts & ... rest ) | |
{ | |
std::cout << head; | |
write(rest ...); | |
} | |
template < class ... Ts > | |
void write( colors forground, const Ts ... content ) | |
{ | |
const auto prefix = "\x1b[3" + to_string(forground) + "m"; | |
write(prefix, content ..., "\x1b[m"); | |
} | |
template < class ... Ts > | |
void writeln( colors forground, const Ts & ... content ) | |
{ | |
write(forground, content ...); | |
std::cout << std::endl; | |
} | |
} | |
int main() | |
{ | |
using namespace ksm; | |
writeln(colors::red, "赤", 1, 'r'); | |
write(colors::blue, "青"); | |
write(colors::green, "緑"); | |
write(colors::yellow, "黄"); | |
write(colors::magenta, "紫"); | |
std::cout << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment