diff --git a/Scoop-Search/Scoop-Search.cpp b/Scoop-Search/Scoop-Search.cpp index 88caf89..a3def6c 100644 --- a/Scoop-Search/Scoop-Search.cpp +++ b/Scoop-Search/Scoop-Search.cpp @@ -29,7 +29,7 @@ namespace scoop using search_result_t = std::vector>; - thread_pool worker{ max(std::thread::hardware_concurrency()-2 , 1) }; + thread_pool worker{max(std::thread::hardware_concurrency()-2, 1)}; std::string system_bit = util::get_system_bit(); fs::path get_path() @@ -49,7 +49,7 @@ namespace scoop std::vector buckets; for (const auto& bucket : fs::directory_iterator(scoop / "buckets")) { - if (bucket.is_directory() && fs::is_directory(fs::path{ bucket } / "bucket")) + if (bucket.is_directory() && is_directory(fs::path{bucket} / "bucket")) buckets.emplace_back(bucket); } return buckets; @@ -66,48 +66,48 @@ namespace scoop else return false; switch (bin.type()) - { + { case Json::stringValue: - if (util::string_find(bin.asString(),key_word)) - app.binaries.emplace_back(std::format("{:s} > {:s}", - bin.asString(), fs::path(bin.asString()).stem().string())); - break; - case Json::arrayValue: - for (const auto& value : bin) + if (util::string_find(bin.asString(), key_word)) + app.binaries.emplace_back(std::format("{:s} > {:s}", + bin.asString(), fs::path(bin.asString()).stem().string())); + break; + case Json::arrayValue: + for (const auto& value : bin) + { + switch (value.type()) { - switch (value.type()) + case Json::stringValue: + if (util::string_find(value.asString(), key_word)) + app.binaries.emplace_back(std::format("{:s} > {:s}", + value.asString(), + fs::path(value.asString()).stem().string())); + break; + case Json::arrayValue: + switch (value.size()) { - case Json::stringValue: - if (util::string_find(value.asString(), key_word)) + case 1: + if (util::string_find(value[0].asString(), key_word)) app.binaries.emplace_back(std::format("{:s} > {:s}", - value.asString(), - fs::path(value.asString()).stem().string())); - break; - case Json::arrayValue: - switch (value.size()) - { - case 1: - if(util::string_find(value[0].asString(),key_word)) - app.binaries.emplace_back(std::format("{:s} > {:s}", value[0].asString(), fs::path(value[0].asString()).stem().string())); - break; - case 2: - case 3: - if (util::string_find(value[0].asString(), key_word) || - util::string_find(value[1].asString(), key_word)) - app.binaries.emplace_back(std::format("{:s} > {:s}", + break; + case 2: + case 3: + if (util::string_find(value[0].asString(), key_word) || + util::string_find(value[1].asString(), key_word)) + app.binaries.emplace_back(std::format("{:s} > {:s}", value[0].asString(), value[1].asString())); - break; - default: break; - } break; default: break; } + break; + default: break; } - break; - default: break; } + break; + default: break; + } return !app.binaries.empty(); } @@ -129,7 +129,7 @@ namespace scoop continue; if (shortcut.size() < 2) continue; - if(util::string_find(shortcut[0].asString(),key_word) || + if (util::string_find(shortcut[0].asString(), key_word) || util::string_find(shortcut[1].asString(), key_word)) { app.shortcuts.emplace_back(std::format("{:s} > {:s}", shortcut[0].asString(), shortcut[1].asString())); @@ -153,11 +153,11 @@ namespace scoop matched = true; std::string desc = manifest["description"].asString(); app.description = desc; - if(util::string_find(desc,key_word)) + if (util::string_find(desc, key_word)) matched = true; if (search_binaries(app, manifest, key_word)) matched = true; - if(search_shortcuts(app, manifest, key_word)) + if (search_shortcuts(app, manifest, key_word)) matched = true; return matched ? std::optional(app) : std::optional(std::nullopt); } @@ -183,14 +183,16 @@ namespace scoop int main(int argc, char* argv[]) { + if (argc < 2) return 0; std::string key_word = util::a2u(argv[1]); - if(key_word == "--hook") + if (key_word == "--hook") { - std::cout << R"(function scoop { if ($args[0] -eq "search") { Scoop-Search.exe @($args | Select-Object -Skip 1) } else { scoop.ps1 @args } })"; + std::cout << + R"(function scoop { if ($args[0] -eq "search") { Scoop-Search.exe @($args | Select-Object -Skip 1) } else { scoop.ps1 @args } })"; } SetConsoleOutputCP(CP_UTF8); std::vector>> list; - std::wregex regex{ LR"((.*?)/(.*))" }; + std::wregex regex{LR"((.*?)/(.*))"}; std::optional special_bucket{}; auto key_word_utf16 = util::u2w(key_word); std::wsmatch match_result; @@ -201,14 +203,14 @@ int main(int argc, char* argv[]) } for (const auto& bucket : scoop::get_buckets()) { - if(!special_bucket) + if (!special_bucket) { const std::string bucket_name = bucket.stem().string(); auto future = scoop::worker.submit(scoop::search_app, bucket, key_word); list.emplace_back(bucket_name, std::move(future)); continue; } - if(special_bucket.value() == bucket.stem()) + if (special_bucket.value() == bucket.stem()) { const std::string bucket_name = bucket.stem().string(); auto future = scoop::worker.submit(scoop::search_app, bucket, key_word); @@ -225,7 +227,7 @@ int main(int argc, char* argv[]) std::cout << hue::yellow << bucket; std::cout << hue::reset << "/"; std::cout << hue::green << app.value().name - << hue::reset << std::endl; + << hue::reset << std::endl; std::cout << " Version: " << hue::blue << app.value().version << hue::reset << std::endl; std::cout << " Description: " << app.value().description << std::endl; @@ -237,7 +239,7 @@ int main(int argc, char* argv[]) std::cout << " - " << bin << std::endl; } } - if(!app.value().shortcuts.empty()) + if (!app.value().shortcuts.empty()) { std::cout << " Shortcuts:" << std::endl; for (const auto& shortcut : app.value().shortcuts) diff --git a/Scoop-Search/console_color.h b/Scoop-Search/console_color.h index ca03cb6..1ba7d4e 100644 --- a/Scoop-Search/console_color.h +++ b/Scoop-Search/console_color.h @@ -13,867 +13,2907 @@ namespace hue { - constexpr int DEFAULT_COLOR = 7; - constexpr int BAD_COLOR = -256; - - const std::map CODES = { - {"black", 0}, {"k", 0}, - {"blue", 1}, {"b", 1}, - {"green", 2}, {"g", 2}, - {"aqua", 3}, {"a", 3}, - {"red", 4}, {"r", 4}, - {"purple", 5}, {"p", 5}, - {"yellow", 6}, {"y", 6}, - {"white", 7}, {"w", 7}, - {"grey", 8}, {"e", 8}, - {"light blue", 9}, {"lb", 9}, - {"light green", 10}, {"lg", 10}, - {"light aqua", 11}, {"la", 11}, - {"light red", 12}, {"lr", 12}, - {"light purple", 13}, {"lp", 13}, - {"light yellow", 14}, {"ly", 14}, - {"bright white", 15}, {"bw", 15} - }; - - const std::map NAMES = { - { 0, "black"}, - { 1, "blue"}, - { 2, "green"}, - { 3, "aqua"}, - { 4, "red"}, - { 5, "purple"}, - { 6, "yellow"}, - { 7, "white"}, - { 8, "grey"}, - { 9, "light blue"}, - {10, "light green"}, - {11, "light aqua"}, - {12, "light red"}, - {13, "light purple"}, - {14, "light yellow"}, - {15, "bright white"} - }; - - inline bool is_good(int c) - { - return 0 <= c && c < 256; - } - - inline int itoc(int c) - { - return is_good(c) ? c : BAD_COLOR; - } - - inline int itoc(int a, int b) - { - return itoc(a + b * 16); - } - - // std::string to color - int stoc(std::string a) - { - // convert s to lowercase, and format variants like "light_blue" - std::transform(a.begin(), a.end(), a.begin(), [](char c) - { - if ('A' <= c && c <= 'Z') - c = c - 'A' + 'a'; - else if (c == '_' || c == '-') - c = ' '; - return c; - }); - - // operator[] on std::map is non-const, use std::map::at instead - return (CODES.find(a) != CODES.end()) ? CODES.at(a) : BAD_COLOR; - } - - int stoc(std::string a, std::string b) - { - return itoc(stoc(a), stoc(b)); - } - - std::string ctos(int c) - { - return (0 <= c && c < 256) ? - "(text) " + NAMES.at(c % 16) + " + " + - "(background) " + NAMES.at(c / 16) : - "BAD COLOR"; - } - - int get() - { - CONSOLE_SCREEN_BUFFER_INFO i; - return GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &i) ? - i.wAttributes : BAD_COLOR; - } - - int get_text() - { - return (get() != BAD_COLOR) ? get() % 16 : BAD_COLOR; - } - - int get_background() - { - return (get() != BAD_COLOR) ? get() / 16 : BAD_COLOR; - } - - void set(int c) - { - if (is_good(c)) - SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c); - } - - void set(int a, int b) - { - set(a + b * 16); - } - - void set(std::string a, std::string b) - { - set(stoc(a) + stoc(b) * 16); - } - - void set_text(std::string a) - { - set(stoc(a), get_background()); - } - - void set_background(std::string b) - { - set(get_text(), stoc(b)); - } - - void reset() - { - set(DEFAULT_COLOR); - } - - int invert(int c) - { - if (is_good(c)) { - int a = c % 16; - int b = c / 16; - return b + a * 16; - } - else - return BAD_COLOR; - } - - std::ostream& reset(std::ostream& os) { reset(); return os; } - std::ostream& black(std::ostream& os) { set_text("k"); return os; } - std::ostream& blue(std::ostream& os) { set_text("b"); return os; } - std::ostream& green(std::ostream& os) { set_text("g"); return os; } - std::ostream& aqua(std::ostream& os) { set_text("a"); return os; } - std::ostream& red(std::ostream& os) { set_text("r"); return os; } - std::ostream& purple(std::ostream& os) { set_text("p"); return os; } - std::ostream& yellow(std::ostream& os) { set_text("y"); return os; } - std::ostream& white(std::ostream& os) { set_text("w"); return os; } - std::ostream& grey(std::ostream& os) { set_text("e"); return os; } - std::ostream& light_blue(std::ostream& os) { set_text("lb"); return os; } - std::ostream& light_green(std::ostream& os) { set_text("lg"); return os; } - std::ostream& light_aqua(std::ostream& os) { set_text("la"); return os; } - std::ostream& light_red(std::ostream& os) { set_text("lr"); return os; } - std::ostream& light_purple(std::ostream& os) { set_text("lp"); return os; } - std::ostream& light_yellow(std::ostream& os) { set_text("ly"); return os; } - std::ostream& bright_white(std::ostream& os) { set_text("bw"); return os; } - std::ostream& on_black(std::ostream& os) { set_background("k"); return os; } - std::ostream& on_blue(std::ostream& os) { set_background("b"); return os; } - std::ostream& on_green(std::ostream& os) { set_background("g"); return os; } - std::ostream& on_aqua(std::ostream& os) { set_background("a"); return os; } - std::ostream& on_red(std::ostream& os) { set_background("r"); return os; } - std::ostream& on_purple(std::ostream& os) { set_background("p"); return os; } - std::ostream& on_yellow(std::ostream& os) { set_background("y"); return os; } - std::ostream& on_white(std::ostream& os) { set_background("w"); return os; } - std::ostream& on_grey(std::ostream& os) { set_background("e"); return os; } - std::ostream& on_light_blue(std::ostream& os) { set_background("lb"); return os; } - std::ostream& on_light_green(std::ostream& os) { set_background("lg"); return os; } - std::ostream& on_light_aqua(std::ostream& os) { set_background("la"); return os; } - std::ostream& on_light_red(std::ostream& os) { set_background("lr"); return os; } - std::ostream& on_light_purple(std::ostream& os) { set_background("lp"); return os; } - std::ostream& on_light_yellow(std::ostream& os) { set_background("ly"); return os; } - std::ostream& on_bright_white(std::ostream& os) { set_background("bw"); return os; } - std::ostream& black_on_black(std::ostream& os) { set("k", "k"); return os; } - std::ostream& black_on_blue(std::ostream& os) { set("k", "b"); return os; } - std::ostream& black_on_green(std::ostream& os) { set("k", "g"); return os; } - std::ostream& black_on_aqua(std::ostream& os) { set("k", "a"); return os; } - std::ostream& black_on_red(std::ostream& os) { set("k", "r"); return os; } - std::ostream& black_on_purple(std::ostream& os) { set("k", "p"); return os; } - std::ostream& black_on_yellow(std::ostream& os) { set("k", "y"); return os; } - std::ostream& black_on_white(std::ostream& os) { set("k", "w"); return os; } - std::ostream& black_on_grey(std::ostream& os) { set("k", "e"); return os; } - std::ostream& black_on_light_blue(std::ostream& os) { set("k", "lb"); return os; } - std::ostream& black_on_light_green(std::ostream& os) { set("k", "lg"); return os; } - std::ostream& black_on_light_aqua(std::ostream& os) { set("k", "la"); return os; } - std::ostream& black_on_light_red(std::ostream& os) { set("k", "lr"); return os; } - std::ostream& black_on_light_purple(std::ostream& os) { set("k", "lp"); return os; } - std::ostream& black_on_light_yellow(std::ostream& os) { set("k", "ly"); return os; } - std::ostream& black_on_bright_white(std::ostream& os) { set("k", "bw"); return os; } - std::ostream& blue_on_black(std::ostream& os) { set("b", "k"); return os; } - std::ostream& blue_on_blue(std::ostream& os) { set("b", "b"); return os; } - std::ostream& blue_on_green(std::ostream& os) { set("b", "g"); return os; } - std::ostream& blue_on_aqua(std::ostream& os) { set("b", "a"); return os; } - std::ostream& blue_on_red(std::ostream& os) { set("b", "r"); return os; } - std::ostream& blue_on_purple(std::ostream& os) { set("b", "p"); return os; } - std::ostream& blue_on_yellow(std::ostream& os) { set("b", "y"); return os; } - std::ostream& blue_on_white(std::ostream& os) { set("b", "w"); return os; } - std::ostream& blue_on_grey(std::ostream& os) { set("b", "e"); return os; } - std::ostream& blue_on_light_blue(std::ostream& os) { set("b", "lb"); return os; } - std::ostream& blue_on_light_green(std::ostream& os) { set("b", "lg"); return os; } - std::ostream& blue_on_light_aqua(std::ostream& os) { set("b", "la"); return os; } - std::ostream& blue_on_light_red(std::ostream& os) { set("b", "lr"); return os; } - std::ostream& blue_on_light_purple(std::ostream& os) { set("b", "lp"); return os; } - std::ostream& blue_on_light_yellow(std::ostream& os) { set("b", "ly"); return os; } - std::ostream& blue_on_bright_white(std::ostream& os) { set("b", "bw"); return os; } - std::ostream& green_on_black(std::ostream& os) { set("g", "k"); return os; } - std::ostream& green_on_blue(std::ostream& os) { set("g", "b"); return os; } - std::ostream& green_on_green(std::ostream& os) { set("g", "g"); return os; } - std::ostream& green_on_aqua(std::ostream& os) { set("g", "a"); return os; } - std::ostream& green_on_red(std::ostream& os) { set("g", "r"); return os; } - std::ostream& green_on_purple(std::ostream& os) { set("g", "p"); return os; } - std::ostream& green_on_yellow(std::ostream& os) { set("g", "y"); return os; } - std::ostream& green_on_white(std::ostream& os) { set("g", "w"); return os; } - std::ostream& green_on_grey(std::ostream& os) { set("g", "e"); return os; } - std::ostream& green_on_light_blue(std::ostream& os) { set("g", "lb"); return os; } - std::ostream& green_on_light_green(std::ostream& os) { set("g", "lg"); return os; } - std::ostream& green_on_light_aqua(std::ostream& os) { set("g", "la"); return os; } - std::ostream& green_on_light_red(std::ostream& os) { set("g", "lr"); return os; } - std::ostream& green_on_light_purple(std::ostream& os) { set("g", "lp"); return os; } - std::ostream& green_on_light_yellow(std::ostream& os) { set("g", "ly"); return os; } - std::ostream& green_on_bright_white(std::ostream& os) { set("g", "bw"); return os; } - std::ostream& aqua_on_black(std::ostream& os) { set("a", "k"); return os; } - std::ostream& aqua_on_blue(std::ostream& os) { set("a", "b"); return os; } - std::ostream& aqua_on_green(std::ostream& os) { set("a", "g"); return os; } - std::ostream& aqua_on_aqua(std::ostream& os) { set("a", "a"); return os; } - std::ostream& aqua_on_red(std::ostream& os) { set("a", "r"); return os; } - std::ostream& aqua_on_purple(std::ostream& os) { set("a", "p"); return os; } - std::ostream& aqua_on_yellow(std::ostream& os) { set("a", "y"); return os; } - std::ostream& aqua_on_white(std::ostream& os) { set("a", "w"); return os; } - std::ostream& aqua_on_grey(std::ostream& os) { set("a", "e"); return os; } - std::ostream& aqua_on_light_blue(std::ostream& os) { set("a", "lb"); return os; } - std::ostream& aqua_on_light_green(std::ostream& os) { set("a", "lg"); return os; } - std::ostream& aqua_on_light_aqua(std::ostream& os) { set("a", "la"); return os; } - std::ostream& aqua_on_light_red(std::ostream& os) { set("a", "lr"); return os; } - std::ostream& aqua_on_light_purple(std::ostream& os) { set("a", "lp"); return os; } - std::ostream& aqua_on_light_yellow(std::ostream& os) { set("a", "ly"); return os; } - std::ostream& aqua_on_bright_white(std::ostream& os) { set("a", "bw"); return os; } - std::ostream& red_on_black(std::ostream& os) { set("r", "k"); return os; } - std::ostream& red_on_blue(std::ostream& os) { set("r", "b"); return os; } - std::ostream& red_on_green(std::ostream& os) { set("r", "g"); return os; } - std::ostream& red_on_aqua(std::ostream& os) { set("r", "a"); return os; } - std::ostream& red_on_red(std::ostream& os) { set("r", "r"); return os; } - std::ostream& red_on_purple(std::ostream& os) { set("r", "p"); return os; } - std::ostream& red_on_yellow(std::ostream& os) { set("r", "y"); return os; } - std::ostream& red_on_white(std::ostream& os) { set("r", "w"); return os; } - std::ostream& red_on_grey(std::ostream& os) { set("r", "e"); return os; } - std::ostream& red_on_light_blue(std::ostream& os) { set("r", "lb"); return os; } - std::ostream& red_on_light_green(std::ostream& os) { set("r", "lg"); return os; } - std::ostream& red_on_light_aqua(std::ostream& os) { set("r", "la"); return os; } - std::ostream& red_on_light_red(std::ostream& os) { set("r", "lr"); return os; } - std::ostream& red_on_light_purple(std::ostream& os) { set("r", "lp"); return os; } - std::ostream& red_on_light_yellow(std::ostream& os) { set("r", "ly"); return os; } - std::ostream& red_on_bright_white(std::ostream& os) { set("r", "bw"); return os; } - std::ostream& purple_on_black(std::ostream& os) { set("p", "k"); return os; } - std::ostream& purple_on_blue(std::ostream& os) { set("p", "b"); return os; } - std::ostream& purple_on_green(std::ostream& os) { set("p", "g"); return os; } - std::ostream& purple_on_aqua(std::ostream& os) { set("p", "a"); return os; } - std::ostream& purple_on_red(std::ostream& os) { set("p", "r"); return os; } - std::ostream& purple_on_purple(std::ostream& os) { set("p", "p"); return os; } - std::ostream& purple_on_yellow(std::ostream& os) { set("p", "y"); return os; } - std::ostream& purple_on_white(std::ostream& os) { set("p", "w"); return os; } - std::ostream& purple_on_grey(std::ostream& os) { set("p", "e"); return os; } - std::ostream& purple_on_light_blue(std::ostream& os) { set("p", "lb"); return os; } - std::ostream& purple_on_light_green(std::ostream& os) { set("p", "lg"); return os; } - std::ostream& purple_on_light_aqua(std::ostream& os) { set("p", "la"); return os; } - std::ostream& purple_on_light_red(std::ostream& os) { set("p", "lr"); return os; } - std::ostream& purple_on_light_purple(std::ostream& os) { set("p", "lp"); return os; } - std::ostream& purple_on_light_yellow(std::ostream& os) { set("p", "ly"); return os; } - std::ostream& purple_on_bright_white(std::ostream& os) { set("p", "bw"); return os; } - std::ostream& yellow_on_black(std::ostream& os) { set("y", "k"); return os; } - std::ostream& yellow_on_blue(std::ostream& os) { set("y", "b"); return os; } - std::ostream& yellow_on_green(std::ostream& os) { set("y", "g"); return os; } - std::ostream& yellow_on_aqua(std::ostream& os) { set("y", "a"); return os; } - std::ostream& yellow_on_red(std::ostream& os) { set("y", "r"); return os; } - std::ostream& yellow_on_purple(std::ostream& os) { set("y", "p"); return os; } - std::ostream& yellow_on_yellow(std::ostream& os) { set("y", "y"); return os; } - std::ostream& yellow_on_white(std::ostream& os) { set("y", "w"); return os; } - std::ostream& yellow_on_grey(std::ostream& os) { set("y", "e"); return os; } - std::ostream& yellow_on_light_blue(std::ostream& os) { set("y", "lb"); return os; } - std::ostream& yellow_on_light_green(std::ostream& os) { set("y", "lg"); return os; } - std::ostream& yellow_on_light_aqua(std::ostream& os) { set("y", "la"); return os; } - std::ostream& yellow_on_light_red(std::ostream& os) { set("y", "lr"); return os; } - std::ostream& yellow_on_light_purple(std::ostream& os) { set("y", "lp"); return os; } - std::ostream& yellow_on_light_yellow(std::ostream& os) { set("y", "ly"); return os; } - std::ostream& yellow_on_bright_white(std::ostream& os) { set("y", "bw"); return os; } - std::ostream& white_on_black(std::ostream& os) { set("w", "k"); return os; } - std::ostream& white_on_blue(std::ostream& os) { set("w", "b"); return os; } - std::ostream& white_on_green(std::ostream& os) { set("w", "g"); return os; } - std::ostream& white_on_aqua(std::ostream& os) { set("w", "a"); return os; } - std::ostream& white_on_red(std::ostream& os) { set("w", "r"); return os; } - std::ostream& white_on_purple(std::ostream& os) { set("w", "p"); return os; } - std::ostream& white_on_yellow(std::ostream& os) { set("w", "y"); return os; } - std::ostream& white_on_white(std::ostream& os) { set("w", "w"); return os; } - std::ostream& white_on_grey(std::ostream& os) { set("w", "e"); return os; } - std::ostream& white_on_light_blue(std::ostream& os) { set("w", "lb"); return os; } - std::ostream& white_on_light_green(std::ostream& os) { set("w", "lg"); return os; } - std::ostream& white_on_light_aqua(std::ostream& os) { set("w", "la"); return os; } - std::ostream& white_on_light_red(std::ostream& os) { set("w", "lr"); return os; } - std::ostream& white_on_light_purple(std::ostream& os) { set("w", "lp"); return os; } - std::ostream& white_on_light_yellow(std::ostream& os) { set("w", "ly"); return os; } - std::ostream& white_on_bright_white(std::ostream& os) { set("w", "bw"); return os; } - std::ostream& grey_on_black(std::ostream& os) { set("e", "k"); return os; } - std::ostream& grey_on_blue(std::ostream& os) { set("e", "b"); return os; } - std::ostream& grey_on_green(std::ostream& os) { set("e", "g"); return os; } - std::ostream& grey_on_aqua(std::ostream& os) { set("e", "a"); return os; } - std::ostream& grey_on_red(std::ostream& os) { set("e", "r"); return os; } - std::ostream& grey_on_purple(std::ostream& os) { set("e", "p"); return os; } - std::ostream& grey_on_yellow(std::ostream& os) { set("e", "y"); return os; } - std::ostream& grey_on_white(std::ostream& os) { set("e", "w"); return os; } - std::ostream& grey_on_grey(std::ostream& os) { set("e", "e"); return os; } - std::ostream& grey_on_light_blue(std::ostream& os) { set("e", "lb"); return os; } - std::ostream& grey_on_light_green(std::ostream& os) { set("e", "lg"); return os; } - std::ostream& grey_on_light_aqua(std::ostream& os) { set("e", "la"); return os; } - std::ostream& grey_on_light_red(std::ostream& os) { set("e", "lr"); return os; } - std::ostream& grey_on_light_purple(std::ostream& os) { set("e", "lp"); return os; } - std::ostream& grey_on_light_yellow(std::ostream& os) { set("e", "ly"); return os; } - std::ostream& grey_on_bright_white(std::ostream& os) { set("e", "bw"); return os; } - std::ostream& light_blue_on_black(std::ostream& os) { set("lb", "k"); return os; } - std::ostream& light_blue_on_blue(std::ostream& os) { set("lb", "b"); return os; } - std::ostream& light_blue_on_green(std::ostream& os) { set("lb", "g"); return os; } - std::ostream& light_blue_on_aqua(std::ostream& os) { set("lb", "a"); return os; } - std::ostream& light_blue_on_red(std::ostream& os) { set("lb", "r"); return os; } - std::ostream& light_blue_on_purple(std::ostream& os) { set("lb", "p"); return os; } - std::ostream& light_blue_on_yellow(std::ostream& os) { set("lb", "y"); return os; } - std::ostream& light_blue_on_white(std::ostream& os) { set("lb", "w"); return os; } - std::ostream& light_blue_on_grey(std::ostream& os) { set("lb", "e"); return os; } - std::ostream& light_blue_on_light_blue(std::ostream& os) { set("lb", "lb"); return os; } - std::ostream& light_blue_on_light_green(std::ostream& os) { set("lb", "lg"); return os; } - std::ostream& light_blue_on_light_aqua(std::ostream& os) { set("lb", "la"); return os; } - std::ostream& light_blue_on_light_red(std::ostream& os) { set("lb", "lr"); return os; } - std::ostream& light_blue_on_light_purple(std::ostream& os) { set("lb", "lp"); return os; } - std::ostream& light_blue_on_light_yellow(std::ostream& os) { set("lb", "ly"); return os; } - std::ostream& light_blue_on_bright_white(std::ostream& os) { set("lb", "bw"); return os; } - std::ostream& light_green_on_black(std::ostream& os) { set("lg", "k"); return os; } - std::ostream& light_green_on_blue(std::ostream& os) { set("lg", "b"); return os; } - std::ostream& light_green_on_green(std::ostream& os) { set("lg", "g"); return os; } - std::ostream& light_green_on_aqua(std::ostream& os) { set("lg", "a"); return os; } - std::ostream& light_green_on_red(std::ostream& os) { set("lg", "r"); return os; } - std::ostream& light_green_on_purple(std::ostream& os) { set("lg", "p"); return os; } - std::ostream& light_green_on_yellow(std::ostream& os) { set("lg", "y"); return os; } - std::ostream& light_green_on_white(std::ostream& os) { set("lg", "w"); return os; } - std::ostream& light_green_on_grey(std::ostream& os) { set("lg", "e"); return os; } - std::ostream& light_green_on_light_blue(std::ostream& os) { set("lg", "lb"); return os; } - std::ostream& light_green_on_light_green(std::ostream& os) { set("lg", "lg"); return os; } - std::ostream& light_green_on_light_aqua(std::ostream& os) { set("lg", "la"); return os; } - std::ostream& light_green_on_light_red(std::ostream& os) { set("lg", "lr"); return os; } - std::ostream& light_green_on_light_purple(std::ostream& os) { set("lg", "lp"); return os; } - std::ostream& light_green_on_light_yellow(std::ostream& os) { set("lg", "ly"); return os; } - std::ostream& light_green_on_bright_white(std::ostream& os) { set("lg", "bw"); return os; } - std::ostream& light_aqua_on_black(std::ostream& os) { set("la", "k"); return os; } - std::ostream& light_aqua_on_blue(std::ostream& os) { set("la", "b"); return os; } - std::ostream& light_aqua_on_green(std::ostream& os) { set("la", "g"); return os; } - std::ostream& light_aqua_on_aqua(std::ostream& os) { set("la", "a"); return os; } - std::ostream& light_aqua_on_red(std::ostream& os) { set("la", "r"); return os; } - std::ostream& light_aqua_on_purple(std::ostream& os) { set("la", "p"); return os; } - std::ostream& light_aqua_on_yellow(std::ostream& os) { set("la", "y"); return os; } - std::ostream& light_aqua_on_white(std::ostream& os) { set("la", "w"); return os; } - std::ostream& light_aqua_on_grey(std::ostream& os) { set("la", "e"); return os; } - std::ostream& light_aqua_on_light_blue(std::ostream& os) { set("la", "lb"); return os; } - std::ostream& light_aqua_on_light_green(std::ostream& os) { set("la", "lg"); return os; } - std::ostream& light_aqua_on_light_aqua(std::ostream& os) { set("la", "la"); return os; } - std::ostream& light_aqua_on_light_red(std::ostream& os) { set("la", "lr"); return os; } - std::ostream& light_aqua_on_light_purple(std::ostream& os) { set("la", "lp"); return os; } - std::ostream& light_aqua_on_light_yellow(std::ostream& os) { set("la", "ly"); return os; } - std::ostream& light_aqua_on_bright_white(std::ostream& os) { set("la", "bw"); return os; } - std::ostream& light_red_on_black(std::ostream& os) { set("lr", "k"); return os; } - std::ostream& light_red_on_blue(std::ostream& os) { set("lr", "b"); return os; } - std::ostream& light_red_on_green(std::ostream& os) { set("lr", "g"); return os; } - std::ostream& light_red_on_aqua(std::ostream& os) { set("lr", "a"); return os; } - std::ostream& light_red_on_red(std::ostream& os) { set("lr", "r"); return os; } - std::ostream& light_red_on_purple(std::ostream& os) { set("lr", "p"); return os; } - std::ostream& light_red_on_yellow(std::ostream& os) { set("lr", "y"); return os; } - std::ostream& light_red_on_white(std::ostream& os) { set("lr", "w"); return os; } - std::ostream& light_red_on_grey(std::ostream& os) { set("lr", "e"); return os; } - std::ostream& light_red_on_light_blue(std::ostream& os) { set("lr", "lb"); return os; } - std::ostream& light_red_on_light_green(std::ostream& os) { set("lr", "lg"); return os; } - std::ostream& light_red_on_light_aqua(std::ostream& os) { set("lr", "la"); return os; } - std::ostream& light_red_on_light_red(std::ostream& os) { set("lr", "lr"); return os; } - std::ostream& light_red_on_light_purple(std::ostream& os) { set("lr", "lp"); return os; } - std::ostream& light_red_on_light_yellow(std::ostream& os) { set("lr", "ly"); return os; } - std::ostream& light_red_on_bright_white(std::ostream& os) { set("lr", "bw"); return os; } - std::ostream& light_purple_on_black(std::ostream& os) { set("lp", "k"); return os; } - std::ostream& light_purple_on_blue(std::ostream& os) { set("lp", "b"); return os; } - std::ostream& light_purple_on_green(std::ostream& os) { set("lp", "g"); return os; } - std::ostream& light_purple_on_aqua(std::ostream& os) { set("lp", "a"); return os; } - std::ostream& light_purple_on_red(std::ostream& os) { set("lp", "r"); return os; } - std::ostream& light_purple_on_purple(std::ostream& os) { set("lp", "p"); return os; } - std::ostream& light_purple_on_yellow(std::ostream& os) { set("lp", "y"); return os; } - std::ostream& light_purple_on_white(std::ostream& os) { set("lp", "w"); return os; } - std::ostream& light_purple_on_grey(std::ostream& os) { set("lp", "e"); return os; } - std::ostream& light_purple_on_light_blue(std::ostream& os) { set("lp", "lb"); return os; } - std::ostream& light_purple_on_light_green(std::ostream& os) { set("lp", "lg"); return os; } - std::ostream& light_purple_on_light_aqua(std::ostream& os) { set("lp", "la"); return os; } - std::ostream& light_purple_on_light_red(std::ostream& os) { set("lp", "lr"); return os; } - std::ostream& light_purple_on_light_purple(std::ostream& os) { set("lp", "lp"); return os; } - std::ostream& light_purple_on_light_yellow(std::ostream& os) { set("lp", "ly"); return os; } - std::ostream& light_purple_on_bright_white(std::ostream& os) { set("lp", "bw"); return os; } - std::ostream& light_yellow_on_black(std::ostream& os) { set("ly", "k"); return os; } - std::ostream& light_yellow_on_blue(std::ostream& os) { set("ly", "b"); return os; } - std::ostream& light_yellow_on_green(std::ostream& os) { set("ly", "g"); return os; } - std::ostream& light_yellow_on_aqua(std::ostream& os) { set("ly", "a"); return os; } - std::ostream& light_yellow_on_red(std::ostream& os) { set("ly", "r"); return os; } - std::ostream& light_yellow_on_purple(std::ostream& os) { set("ly", "p"); return os; } - std::ostream& light_yellow_on_yellow(std::ostream& os) { set("ly", "y"); return os; } - std::ostream& light_yellow_on_white(std::ostream& os) { set("ly", "w"); return os; } - std::ostream& light_yellow_on_grey(std::ostream& os) { set("ly", "e"); return os; } - std::ostream& light_yellow_on_light_blue(std::ostream& os) { set("ly", "lb"); return os; } - std::ostream& light_yellow_on_light_green(std::ostream& os) { set("ly", "lg"); return os; } - std::ostream& light_yellow_on_light_aqua(std::ostream& os) { set("ly", "la"); return os; } - std::ostream& light_yellow_on_light_red(std::ostream& os) { set("ly", "lr"); return os; } - std::ostream& light_yellow_on_light_purple(std::ostream& os) { set("ly", "lp"); return os; } - std::ostream& light_yellow_on_light_yellow(std::ostream& os) { set("ly", "ly"); return os; } - std::ostream& light_yellow_on_bright_white(std::ostream& os) { set("ly", "bw"); return os; } - std::ostream& bright_white_on_black(std::ostream& os) { set("bw", "k"); return os; } - std::ostream& bright_white_on_blue(std::ostream& os) { set("bw", "b"); return os; } - std::ostream& bright_white_on_green(std::ostream& os) { set("bw", "g"); return os; } - std::ostream& bright_white_on_aqua(std::ostream& os) { set("bw", "a"); return os; } - std::ostream& bright_white_on_red(std::ostream& os) { set("bw", "r"); return os; } - std::ostream& bright_white_on_purple(std::ostream& os) { set("bw", "p"); return os; } - std::ostream& bright_white_on_yellow(std::ostream& os) { set("bw", "y"); return os; } - std::ostream& bright_white_on_white(std::ostream& os) { set("bw", "w"); return os; } - std::ostream& bright_white_on_grey(std::ostream& os) { set("bw", "e"); return os; } - std::ostream& bright_white_on_light_blue(std::ostream& os) { set("bw", "lb"); return os; } - std::ostream& bright_white_on_light_green(std::ostream& os) { set("bw", "lg"); return os; } - std::ostream& bright_white_on_light_aqua(std::ostream& os) { set("bw", "la"); return os; } - std::ostream& bright_white_on_light_red(std::ostream& os) { set("bw", "lr"); return os; } - std::ostream& bright_white_on_light_purple(std::ostream& os) { set("bw", "lp"); return os; } - std::ostream& bright_white_on_light_yellow(std::ostream& os) { set("bw", "ly"); return os; } - std::ostream& bright_white_on_bright_white(std::ostream& os) { set("bw", "bw"); return os; } + constexpr int DEFAULT_COLOR = 7; + constexpr int BAD_COLOR = -256; + + const std::map CODES = { + {"black", 0}, {"k", 0}, + {"blue", 1}, {"b", 1}, + {"green", 2}, {"g", 2}, + {"aqua", 3}, {"a", 3}, + {"red", 4}, {"r", 4}, + {"purple", 5}, {"p", 5}, + {"yellow", 6}, {"y", 6}, + {"white", 7}, {"w", 7}, + {"grey", 8}, {"e", 8}, + {"light blue", 9}, {"lb", 9}, + {"light green", 10}, {"lg", 10}, + {"light aqua", 11}, {"la", 11}, + {"light red", 12}, {"lr", 12}, + {"light purple", 13}, {"lp", 13}, + {"light yellow", 14}, {"ly", 14}, + {"bright white", 15}, {"bw", 15} + }; + + const std::map NAMES = { + {0, "black"}, + {1, "blue"}, + {2, "green"}, + {3, "aqua"}, + {4, "red"}, + {5, "purple"}, + {6, "yellow"}, + {7, "white"}, + {8, "grey"}, + {9, "light blue"}, + {10, "light green"}, + {11, "light aqua"}, + {12, "light red"}, + {13, "light purple"}, + {14, "light yellow"}, + {15, "bright white"} + }; + + inline bool is_good(int c) + { + return 0 <= c && c < 256; + } + + inline int itoc(int c) + { + return is_good(c) ? c : BAD_COLOR; + } + + inline int itoc(int a, int b) + { + return itoc(a + b * 16); + } + + // std::string to color + int stoc(std::string a) + { + // convert s to lowercase, and format variants like "light_blue" + std::transform(a.begin(), a.end(), a.begin(), [](char c) + { + if ('A' <= c && c <= 'Z') + c = c - 'A' + 'a'; + else if (c == '_' || c == '-') + c = ' '; + return c; + }); + + // operator[] on std::map is non-const, use std::map::at instead + return (CODES.contains(a)) ? CODES.at(a) : BAD_COLOR; + } + + int stoc(std::string a, std::string b) + { + return itoc(stoc(a), stoc(b)); + } + + std::string ctos(int c) + { + return (0 <= c && c < 256) + ? "(text) " + NAMES.at(c % 16) + " + " + + "(background) " + NAMES.at(c / 16) + : "BAD COLOR"; + } + + int get() + { + CONSOLE_SCREEN_BUFFER_INFO i; + return GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &i) ? i.wAttributes : BAD_COLOR; + } + + int get_text() + { + return (get() != BAD_COLOR) ? get() % 16 : BAD_COLOR; + } + + int get_background() + { + return (get() != BAD_COLOR) ? get() / 16 : BAD_COLOR; + } + + void set(int c) + { + if (is_good(c)) + SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c); + } + + void set(int a, int b) + { + set(a + b * 16); + } + + void set(std::string a, std::string b) + { + set(stoc(a) + stoc(b) * 16); + } + + void set_text(std::string a) + { + set(stoc(a), get_background()); + } + + void set_background(std::string b) + { + set(get_text(), stoc(b)); + } + + void reset() + { + set(DEFAULT_COLOR); + } + + int invert(int c) + { + if (is_good(c)) + { + int a = c % 16; + int b = c / 16; + return b + a * 16; + } + return BAD_COLOR; + } + + std::ostream& reset(std::ostream& os) + { + reset(); + return os; + } + + std::ostream& black(std::ostream& os) + { + set_text("k"); + return os; + } + + std::ostream& blue(std::ostream& os) + { + set_text("b"); + return os; + } + + std::ostream& green(std::ostream& os) + { + set_text("g"); + return os; + } + + std::ostream& aqua(std::ostream& os) + { + set_text("a"); + return os; + } + + std::ostream& red(std::ostream& os) + { + set_text("r"); + return os; + } + + std::ostream& purple(std::ostream& os) + { + set_text("p"); + return os; + } + + std::ostream& yellow(std::ostream& os) + { + set_text("y"); + return os; + } + + std::ostream& white(std::ostream& os) + { + set_text("w"); + return os; + } + + std::ostream& grey(std::ostream& os) + { + set_text("e"); + return os; + } + + std::ostream& light_blue(std::ostream& os) + { + set_text("lb"); + return os; + } + + std::ostream& light_green(std::ostream& os) + { + set_text("lg"); + return os; + } + + std::ostream& light_aqua(std::ostream& os) + { + set_text("la"); + return os; + } + + std::ostream& light_red(std::ostream& os) + { + set_text("lr"); + return os; + } + + std::ostream& light_purple(std::ostream& os) + { + set_text("lp"); + return os; + } + + std::ostream& light_yellow(std::ostream& os) + { + set_text("ly"); + return os; + } + + std::ostream& bright_white(std::ostream& os) + { + set_text("bw"); + return os; + } + + std::ostream& on_black(std::ostream& os) + { + set_background("k"); + return os; + } + + std::ostream& on_blue(std::ostream& os) + { + set_background("b"); + return os; + } + + std::ostream& on_green(std::ostream& os) + { + set_background("g"); + return os; + } + + std::ostream& on_aqua(std::ostream& os) + { + set_background("a"); + return os; + } + + std::ostream& on_red(std::ostream& os) + { + set_background("r"); + return os; + } + + std::ostream& on_purple(std::ostream& os) + { + set_background("p"); + return os; + } + + std::ostream& on_yellow(std::ostream& os) + { + set_background("y"); + return os; + } + + std::ostream& on_white(std::ostream& os) + { + set_background("w"); + return os; + } + + std::ostream& on_grey(std::ostream& os) + { + set_background("e"); + return os; + } + + std::ostream& on_light_blue(std::ostream& os) + { + set_background("lb"); + return os; + } + + std::ostream& on_light_green(std::ostream& os) + { + set_background("lg"); + return os; + } + + std::ostream& on_light_aqua(std::ostream& os) + { + set_background("la"); + return os; + } + + std::ostream& on_light_red(std::ostream& os) + { + set_background("lr"); + return os; + } + + std::ostream& on_light_purple(std::ostream& os) + { + set_background("lp"); + return os; + } + + std::ostream& on_light_yellow(std::ostream& os) + { + set_background("ly"); + return os; + } + + std::ostream& on_bright_white(std::ostream& os) + { + set_background("bw"); + return os; + } + + std::ostream& black_on_black(std::ostream& os) + { + set("k", "k"); + return os; + } + + std::ostream& black_on_blue(std::ostream& os) + { + set("k", "b"); + return os; + } + + std::ostream& black_on_green(std::ostream& os) + { + set("k", "g"); + return os; + } + + std::ostream& black_on_aqua(std::ostream& os) + { + set("k", "a"); + return os; + } + + std::ostream& black_on_red(std::ostream& os) + { + set("k", "r"); + return os; + } + + std::ostream& black_on_purple(std::ostream& os) + { + set("k", "p"); + return os; + } + + std::ostream& black_on_yellow(std::ostream& os) + { + set("k", "y"); + return os; + } + + std::ostream& black_on_white(std::ostream& os) + { + set("k", "w"); + return os; + } + + std::ostream& black_on_grey(std::ostream& os) + { + set("k", "e"); + return os; + } + + std::ostream& black_on_light_blue(std::ostream& os) + { + set("k", "lb"); + return os; + } + + std::ostream& black_on_light_green(std::ostream& os) + { + set("k", "lg"); + return os; + } + + std::ostream& black_on_light_aqua(std::ostream& os) + { + set("k", "la"); + return os; + } + + std::ostream& black_on_light_red(std::ostream& os) + { + set("k", "lr"); + return os; + } + + std::ostream& black_on_light_purple(std::ostream& os) + { + set("k", "lp"); + return os; + } + + std::ostream& black_on_light_yellow(std::ostream& os) + { + set("k", "ly"); + return os; + } + + std::ostream& black_on_bright_white(std::ostream& os) + { + set("k", "bw"); + return os; + } + + std::ostream& blue_on_black(std::ostream& os) + { + set("b", "k"); + return os; + } + + std::ostream& blue_on_blue(std::ostream& os) + { + set("b", "b"); + return os; + } + + std::ostream& blue_on_green(std::ostream& os) + { + set("b", "g"); + return os; + } + + std::ostream& blue_on_aqua(std::ostream& os) + { + set("b", "a"); + return os; + } + + std::ostream& blue_on_red(std::ostream& os) + { + set("b", "r"); + return os; + } + + std::ostream& blue_on_purple(std::ostream& os) + { + set("b", "p"); + return os; + } + + std::ostream& blue_on_yellow(std::ostream& os) + { + set("b", "y"); + return os; + } + + std::ostream& blue_on_white(std::ostream& os) + { + set("b", "w"); + return os; + } + + std::ostream& blue_on_grey(std::ostream& os) + { + set("b", "e"); + return os; + } + + std::ostream& blue_on_light_blue(std::ostream& os) + { + set("b", "lb"); + return os; + } + + std::ostream& blue_on_light_green(std::ostream& os) + { + set("b", "lg"); + return os; + } + + std::ostream& blue_on_light_aqua(std::ostream& os) + { + set("b", "la"); + return os; + } + + std::ostream& blue_on_light_red(std::ostream& os) + { + set("b", "lr"); + return os; + } + + std::ostream& blue_on_light_purple(std::ostream& os) + { + set("b", "lp"); + return os; + } + + std::ostream& blue_on_light_yellow(std::ostream& os) + { + set("b", "ly"); + return os; + } + + std::ostream& blue_on_bright_white(std::ostream& os) + { + set("b", "bw"); + return os; + } + + std::ostream& green_on_black(std::ostream& os) + { + set("g", "k"); + return os; + } + + std::ostream& green_on_blue(std::ostream& os) + { + set("g", "b"); + return os; + } + + std::ostream& green_on_green(std::ostream& os) + { + set("g", "g"); + return os; + } + + std::ostream& green_on_aqua(std::ostream& os) + { + set("g", "a"); + return os; + } + + std::ostream& green_on_red(std::ostream& os) + { + set("g", "r"); + return os; + } + + std::ostream& green_on_purple(std::ostream& os) + { + set("g", "p"); + return os; + } + + std::ostream& green_on_yellow(std::ostream& os) + { + set("g", "y"); + return os; + } + + std::ostream& green_on_white(std::ostream& os) + { + set("g", "w"); + return os; + } + + std::ostream& green_on_grey(std::ostream& os) + { + set("g", "e"); + return os; + } + + std::ostream& green_on_light_blue(std::ostream& os) + { + set("g", "lb"); + return os; + } + + std::ostream& green_on_light_green(std::ostream& os) + { + set("g", "lg"); + return os; + } + + std::ostream& green_on_light_aqua(std::ostream& os) + { + set("g", "la"); + return os; + } + + std::ostream& green_on_light_red(std::ostream& os) + { + set("g", "lr"); + return os; + } + + std::ostream& green_on_light_purple(std::ostream& os) + { + set("g", "lp"); + return os; + } + + std::ostream& green_on_light_yellow(std::ostream& os) + { + set("g", "ly"); + return os; + } + + std::ostream& green_on_bright_white(std::ostream& os) + { + set("g", "bw"); + return os; + } + + std::ostream& aqua_on_black(std::ostream& os) + { + set("a", "k"); + return os; + } + + std::ostream& aqua_on_blue(std::ostream& os) + { + set("a", "b"); + return os; + } + + std::ostream& aqua_on_green(std::ostream& os) + { + set("a", "g"); + return os; + } + + std::ostream& aqua_on_aqua(std::ostream& os) + { + set("a", "a"); + return os; + } + + std::ostream& aqua_on_red(std::ostream& os) + { + set("a", "r"); + return os; + } + + std::ostream& aqua_on_purple(std::ostream& os) + { + set("a", "p"); + return os; + } + + std::ostream& aqua_on_yellow(std::ostream& os) + { + set("a", "y"); + return os; + } + + std::ostream& aqua_on_white(std::ostream& os) + { + set("a", "w"); + return os; + } + + std::ostream& aqua_on_grey(std::ostream& os) + { + set("a", "e"); + return os; + } + + std::ostream& aqua_on_light_blue(std::ostream& os) + { + set("a", "lb"); + return os; + } + + std::ostream& aqua_on_light_green(std::ostream& os) + { + set("a", "lg"); + return os; + } + + std::ostream& aqua_on_light_aqua(std::ostream& os) + { + set("a", "la"); + return os; + } + + std::ostream& aqua_on_light_red(std::ostream& os) + { + set("a", "lr"); + return os; + } + + std::ostream& aqua_on_light_purple(std::ostream& os) + { + set("a", "lp"); + return os; + } + + std::ostream& aqua_on_light_yellow(std::ostream& os) + { + set("a", "ly"); + return os; + } + + std::ostream& aqua_on_bright_white(std::ostream& os) + { + set("a", "bw"); + return os; + } + + std::ostream& red_on_black(std::ostream& os) + { + set("r", "k"); + return os; + } + + std::ostream& red_on_blue(std::ostream& os) + { + set("r", "b"); + return os; + } + + std::ostream& red_on_green(std::ostream& os) + { + set("r", "g"); + return os; + } + + std::ostream& red_on_aqua(std::ostream& os) + { + set("r", "a"); + return os; + } + + std::ostream& red_on_red(std::ostream& os) + { + set("r", "r"); + return os; + } + + std::ostream& red_on_purple(std::ostream& os) + { + set("r", "p"); + return os; + } + + std::ostream& red_on_yellow(std::ostream& os) + { + set("r", "y"); + return os; + } + + std::ostream& red_on_white(std::ostream& os) + { + set("r", "w"); + return os; + } + + std::ostream& red_on_grey(std::ostream& os) + { + set("r", "e"); + return os; + } + + std::ostream& red_on_light_blue(std::ostream& os) + { + set("r", "lb"); + return os; + } + + std::ostream& red_on_light_green(std::ostream& os) + { + set("r", "lg"); + return os; + } + + std::ostream& red_on_light_aqua(std::ostream& os) + { + set("r", "la"); + return os; + } + + std::ostream& red_on_light_red(std::ostream& os) + { + set("r", "lr"); + return os; + } + + std::ostream& red_on_light_purple(std::ostream& os) + { + set("r", "lp"); + return os; + } + + std::ostream& red_on_light_yellow(std::ostream& os) + { + set("r", "ly"); + return os; + } + + std::ostream& red_on_bright_white(std::ostream& os) + { + set("r", "bw"); + return os; + } + + std::ostream& purple_on_black(std::ostream& os) + { + set("p", "k"); + return os; + } + + std::ostream& purple_on_blue(std::ostream& os) + { + set("p", "b"); + return os; + } + + std::ostream& purple_on_green(std::ostream& os) + { + set("p", "g"); + return os; + } + + std::ostream& purple_on_aqua(std::ostream& os) + { + set("p", "a"); + return os; + } + + std::ostream& purple_on_red(std::ostream& os) + { + set("p", "r"); + return os; + } + + std::ostream& purple_on_purple(std::ostream& os) + { + set("p", "p"); + return os; + } + + std::ostream& purple_on_yellow(std::ostream& os) + { + set("p", "y"); + return os; + } + + std::ostream& purple_on_white(std::ostream& os) + { + set("p", "w"); + return os; + } + + std::ostream& purple_on_grey(std::ostream& os) + { + set("p", "e"); + return os; + } + + std::ostream& purple_on_light_blue(std::ostream& os) + { + set("p", "lb"); + return os; + } + + std::ostream& purple_on_light_green(std::ostream& os) + { + set("p", "lg"); + return os; + } + + std::ostream& purple_on_light_aqua(std::ostream& os) + { + set("p", "la"); + return os; + } + + std::ostream& purple_on_light_red(std::ostream& os) + { + set("p", "lr"); + return os; + } + + std::ostream& purple_on_light_purple(std::ostream& os) + { + set("p", "lp"); + return os; + } + + std::ostream& purple_on_light_yellow(std::ostream& os) + { + set("p", "ly"); + return os; + } + + std::ostream& purple_on_bright_white(std::ostream& os) + { + set("p", "bw"); + return os; + } + + std::ostream& yellow_on_black(std::ostream& os) + { + set("y", "k"); + return os; + } + + std::ostream& yellow_on_blue(std::ostream& os) + { + set("y", "b"); + return os; + } + + std::ostream& yellow_on_green(std::ostream& os) + { + set("y", "g"); + return os; + } + + std::ostream& yellow_on_aqua(std::ostream& os) + { + set("y", "a"); + return os; + } + + std::ostream& yellow_on_red(std::ostream& os) + { + set("y", "r"); + return os; + } + + std::ostream& yellow_on_purple(std::ostream& os) + { + set("y", "p"); + return os; + } + + std::ostream& yellow_on_yellow(std::ostream& os) + { + set("y", "y"); + return os; + } + + std::ostream& yellow_on_white(std::ostream& os) + { + set("y", "w"); + return os; + } + + std::ostream& yellow_on_grey(std::ostream& os) + { + set("y", "e"); + return os; + } + + std::ostream& yellow_on_light_blue(std::ostream& os) + { + set("y", "lb"); + return os; + } + + std::ostream& yellow_on_light_green(std::ostream& os) + { + set("y", "lg"); + return os; + } + + std::ostream& yellow_on_light_aqua(std::ostream& os) + { + set("y", "la"); + return os; + } + + std::ostream& yellow_on_light_red(std::ostream& os) + { + set("y", "lr"); + return os; + } + + std::ostream& yellow_on_light_purple(std::ostream& os) + { + set("y", "lp"); + return os; + } + + std::ostream& yellow_on_light_yellow(std::ostream& os) + { + set("y", "ly"); + return os; + } + + std::ostream& yellow_on_bright_white(std::ostream& os) + { + set("y", "bw"); + return os; + } + + std::ostream& white_on_black(std::ostream& os) + { + set("w", "k"); + return os; + } + + std::ostream& white_on_blue(std::ostream& os) + { + set("w", "b"); + return os; + } + + std::ostream& white_on_green(std::ostream& os) + { + set("w", "g"); + return os; + } + + std::ostream& white_on_aqua(std::ostream& os) + { + set("w", "a"); + return os; + } + + std::ostream& white_on_red(std::ostream& os) + { + set("w", "r"); + return os; + } + + std::ostream& white_on_purple(std::ostream& os) + { + set("w", "p"); + return os; + } + + std::ostream& white_on_yellow(std::ostream& os) + { + set("w", "y"); + return os; + } + + std::ostream& white_on_white(std::ostream& os) + { + set("w", "w"); + return os; + } + + std::ostream& white_on_grey(std::ostream& os) + { + set("w", "e"); + return os; + } + + std::ostream& white_on_light_blue(std::ostream& os) + { + set("w", "lb"); + return os; + } + + std::ostream& white_on_light_green(std::ostream& os) + { + set("w", "lg"); + return os; + } + + std::ostream& white_on_light_aqua(std::ostream& os) + { + set("w", "la"); + return os; + } + + std::ostream& white_on_light_red(std::ostream& os) + { + set("w", "lr"); + return os; + } + + std::ostream& white_on_light_purple(std::ostream& os) + { + set("w", "lp"); + return os; + } + + std::ostream& white_on_light_yellow(std::ostream& os) + { + set("w", "ly"); + return os; + } + + std::ostream& white_on_bright_white(std::ostream& os) + { + set("w", "bw"); + return os; + } + + std::ostream& grey_on_black(std::ostream& os) + { + set("e", "k"); + return os; + } + + std::ostream& grey_on_blue(std::ostream& os) + { + set("e", "b"); + return os; + } + + std::ostream& grey_on_green(std::ostream& os) + { + set("e", "g"); + return os; + } + + std::ostream& grey_on_aqua(std::ostream& os) + { + set("e", "a"); + return os; + } + + std::ostream& grey_on_red(std::ostream& os) + { + set("e", "r"); + return os; + } + + std::ostream& grey_on_purple(std::ostream& os) + { + set("e", "p"); + return os; + } + + std::ostream& grey_on_yellow(std::ostream& os) + { + set("e", "y"); + return os; + } + + std::ostream& grey_on_white(std::ostream& os) + { + set("e", "w"); + return os; + } + + std::ostream& grey_on_grey(std::ostream& os) + { + set("e", "e"); + return os; + } + + std::ostream& grey_on_light_blue(std::ostream& os) + { + set("e", "lb"); + return os; + } + + std::ostream& grey_on_light_green(std::ostream& os) + { + set("e", "lg"); + return os; + } + + std::ostream& grey_on_light_aqua(std::ostream& os) + { + set("e", "la"); + return os; + } + + std::ostream& grey_on_light_red(std::ostream& os) + { + set("e", "lr"); + return os; + } + + std::ostream& grey_on_light_purple(std::ostream& os) + { + set("e", "lp"); + return os; + } + + std::ostream& grey_on_light_yellow(std::ostream& os) + { + set("e", "ly"); + return os; + } + + std::ostream& grey_on_bright_white(std::ostream& os) + { + set("e", "bw"); + return os; + } + + std::ostream& light_blue_on_black(std::ostream& os) + { + set("lb", "k"); + return os; + } + + std::ostream& light_blue_on_blue(std::ostream& os) + { + set("lb", "b"); + return os; + } + + std::ostream& light_blue_on_green(std::ostream& os) + { + set("lb", "g"); + return os; + } + + std::ostream& light_blue_on_aqua(std::ostream& os) + { + set("lb", "a"); + return os; + } + + std::ostream& light_blue_on_red(std::ostream& os) + { + set("lb", "r"); + return os; + } + + std::ostream& light_blue_on_purple(std::ostream& os) + { + set("lb", "p"); + return os; + } + + std::ostream& light_blue_on_yellow(std::ostream& os) + { + set("lb", "y"); + return os; + } + + std::ostream& light_blue_on_white(std::ostream& os) + { + set("lb", "w"); + return os; + } + + std::ostream& light_blue_on_grey(std::ostream& os) + { + set("lb", "e"); + return os; + } + + std::ostream& light_blue_on_light_blue(std::ostream& os) + { + set("lb", "lb"); + return os; + } + + std::ostream& light_blue_on_light_green(std::ostream& os) + { + set("lb", "lg"); + return os; + } + + std::ostream& light_blue_on_light_aqua(std::ostream& os) + { + set("lb", "la"); + return os; + } + + std::ostream& light_blue_on_light_red(std::ostream& os) + { + set("lb", "lr"); + return os; + } + + std::ostream& light_blue_on_light_purple(std::ostream& os) + { + set("lb", "lp"); + return os; + } + + std::ostream& light_blue_on_light_yellow(std::ostream& os) + { + set("lb", "ly"); + return os; + } + + std::ostream& light_blue_on_bright_white(std::ostream& os) + { + set("lb", "bw"); + return os; + } + + std::ostream& light_green_on_black(std::ostream& os) + { + set("lg", "k"); + return os; + } + + std::ostream& light_green_on_blue(std::ostream& os) + { + set("lg", "b"); + return os; + } + + std::ostream& light_green_on_green(std::ostream& os) + { + set("lg", "g"); + return os; + } + + std::ostream& light_green_on_aqua(std::ostream& os) + { + set("lg", "a"); + return os; + } + + std::ostream& light_green_on_red(std::ostream& os) + { + set("lg", "r"); + return os; + } + + std::ostream& light_green_on_purple(std::ostream& os) + { + set("lg", "p"); + return os; + } + + std::ostream& light_green_on_yellow(std::ostream& os) + { + set("lg", "y"); + return os; + } + + std::ostream& light_green_on_white(std::ostream& os) + { + set("lg", "w"); + return os; + } + + std::ostream& light_green_on_grey(std::ostream& os) + { + set("lg", "e"); + return os; + } + + std::ostream& light_green_on_light_blue(std::ostream& os) + { + set("lg", "lb"); + return os; + } + + std::ostream& light_green_on_light_green(std::ostream& os) + { + set("lg", "lg"); + return os; + } + + std::ostream& light_green_on_light_aqua(std::ostream& os) + { + set("lg", "la"); + return os; + } + + std::ostream& light_green_on_light_red(std::ostream& os) + { + set("lg", "lr"); + return os; + } + + std::ostream& light_green_on_light_purple(std::ostream& os) + { + set("lg", "lp"); + return os; + } + + std::ostream& light_green_on_light_yellow(std::ostream& os) + { + set("lg", "ly"); + return os; + } + + std::ostream& light_green_on_bright_white(std::ostream& os) + { + set("lg", "bw"); + return os; + } + + std::ostream& light_aqua_on_black(std::ostream& os) + { + set("la", "k"); + return os; + } + + std::ostream& light_aqua_on_blue(std::ostream& os) + { + set("la", "b"); + return os; + } + + std::ostream& light_aqua_on_green(std::ostream& os) + { + set("la", "g"); + return os; + } + + std::ostream& light_aqua_on_aqua(std::ostream& os) + { + set("la", "a"); + return os; + } + + std::ostream& light_aqua_on_red(std::ostream& os) + { + set("la", "r"); + return os; + } + + std::ostream& light_aqua_on_purple(std::ostream& os) + { + set("la", "p"); + return os; + } + + std::ostream& light_aqua_on_yellow(std::ostream& os) + { + set("la", "y"); + return os; + } + + std::ostream& light_aqua_on_white(std::ostream& os) + { + set("la", "w"); + return os; + } + + std::ostream& light_aqua_on_grey(std::ostream& os) + { + set("la", "e"); + return os; + } + + std::ostream& light_aqua_on_light_blue(std::ostream& os) + { + set("la", "lb"); + return os; + } + + std::ostream& light_aqua_on_light_green(std::ostream& os) + { + set("la", "lg"); + return os; + } + + std::ostream& light_aqua_on_light_aqua(std::ostream& os) + { + set("la", "la"); + return os; + } + + std::ostream& light_aqua_on_light_red(std::ostream& os) + { + set("la", "lr"); + return os; + } + + std::ostream& light_aqua_on_light_purple(std::ostream& os) + { + set("la", "lp"); + return os; + } + + std::ostream& light_aqua_on_light_yellow(std::ostream& os) + { + set("la", "ly"); + return os; + } + + std::ostream& light_aqua_on_bright_white(std::ostream& os) + { + set("la", "bw"); + return os; + } + + std::ostream& light_red_on_black(std::ostream& os) + { + set("lr", "k"); + return os; + } + + std::ostream& light_red_on_blue(std::ostream& os) + { + set("lr", "b"); + return os; + } + + std::ostream& light_red_on_green(std::ostream& os) + { + set("lr", "g"); + return os; + } + + std::ostream& light_red_on_aqua(std::ostream& os) + { + set("lr", "a"); + return os; + } + + std::ostream& light_red_on_red(std::ostream& os) + { + set("lr", "r"); + return os; + } + + std::ostream& light_red_on_purple(std::ostream& os) + { + set("lr", "p"); + return os; + } + + std::ostream& light_red_on_yellow(std::ostream& os) + { + set("lr", "y"); + return os; + } + + std::ostream& light_red_on_white(std::ostream& os) + { + set("lr", "w"); + return os; + } + + std::ostream& light_red_on_grey(std::ostream& os) + { + set("lr", "e"); + return os; + } + + std::ostream& light_red_on_light_blue(std::ostream& os) + { + set("lr", "lb"); + return os; + } + + std::ostream& light_red_on_light_green(std::ostream& os) + { + set("lr", "lg"); + return os; + } + + std::ostream& light_red_on_light_aqua(std::ostream& os) + { + set("lr", "la"); + return os; + } + + std::ostream& light_red_on_light_red(std::ostream& os) + { + set("lr", "lr"); + return os; + } + + std::ostream& light_red_on_light_purple(std::ostream& os) + { + set("lr", "lp"); + return os; + } + + std::ostream& light_red_on_light_yellow(std::ostream& os) + { + set("lr", "ly"); + return os; + } + + std::ostream& light_red_on_bright_white(std::ostream& os) + { + set("lr", "bw"); + return os; + } + + std::ostream& light_purple_on_black(std::ostream& os) + { + set("lp", "k"); + return os; + } + + std::ostream& light_purple_on_blue(std::ostream& os) + { + set("lp", "b"); + return os; + } + + std::ostream& light_purple_on_green(std::ostream& os) + { + set("lp", "g"); + return os; + } + + std::ostream& light_purple_on_aqua(std::ostream& os) + { + set("lp", "a"); + return os; + } + + std::ostream& light_purple_on_red(std::ostream& os) + { + set("lp", "r"); + return os; + } + + std::ostream& light_purple_on_purple(std::ostream& os) + { + set("lp", "p"); + return os; + } + + std::ostream& light_purple_on_yellow(std::ostream& os) + { + set("lp", "y"); + return os; + } + + std::ostream& light_purple_on_white(std::ostream& os) + { + set("lp", "w"); + return os; + } + + std::ostream& light_purple_on_grey(std::ostream& os) + { + set("lp", "e"); + return os; + } + + std::ostream& light_purple_on_light_blue(std::ostream& os) + { + set("lp", "lb"); + return os; + } + + std::ostream& light_purple_on_light_green(std::ostream& os) + { + set("lp", "lg"); + return os; + } + + std::ostream& light_purple_on_light_aqua(std::ostream& os) + { + set("lp", "la"); + return os; + } + + std::ostream& light_purple_on_light_red(std::ostream& os) + { + set("lp", "lr"); + return os; + } + + std::ostream& light_purple_on_light_purple(std::ostream& os) + { + set("lp", "lp"); + return os; + } + + std::ostream& light_purple_on_light_yellow(std::ostream& os) + { + set("lp", "ly"); + return os; + } + + std::ostream& light_purple_on_bright_white(std::ostream& os) + { + set("lp", "bw"); + return os; + } + + std::ostream& light_yellow_on_black(std::ostream& os) + { + set("ly", "k"); + return os; + } + + std::ostream& light_yellow_on_blue(std::ostream& os) + { + set("ly", "b"); + return os; + } + + std::ostream& light_yellow_on_green(std::ostream& os) + { + set("ly", "g"); + return os; + } + + std::ostream& light_yellow_on_aqua(std::ostream& os) + { + set("ly", "a"); + return os; + } + + std::ostream& light_yellow_on_red(std::ostream& os) + { + set("ly", "r"); + return os; + } + + std::ostream& light_yellow_on_purple(std::ostream& os) + { + set("ly", "p"); + return os; + } + + std::ostream& light_yellow_on_yellow(std::ostream& os) + { + set("ly", "y"); + return os; + } + + std::ostream& light_yellow_on_white(std::ostream& os) + { + set("ly", "w"); + return os; + } + + std::ostream& light_yellow_on_grey(std::ostream& os) + { + set("ly", "e"); + return os; + } + + std::ostream& light_yellow_on_light_blue(std::ostream& os) + { + set("ly", "lb"); + return os; + } + + std::ostream& light_yellow_on_light_green(std::ostream& os) + { + set("ly", "lg"); + return os; + } + + std::ostream& light_yellow_on_light_aqua(std::ostream& os) + { + set("ly", "la"); + return os; + } + + std::ostream& light_yellow_on_light_red(std::ostream& os) + { + set("ly", "lr"); + return os; + } + + std::ostream& light_yellow_on_light_purple(std::ostream& os) + { + set("ly", "lp"); + return os; + } + + std::ostream& light_yellow_on_light_yellow(std::ostream& os) + { + set("ly", "ly"); + return os; + } + + std::ostream& light_yellow_on_bright_white(std::ostream& os) + { + set("ly", "bw"); + return os; + } + + std::ostream& bright_white_on_black(std::ostream& os) + { + set("bw", "k"); + return os; + } + + std::ostream& bright_white_on_blue(std::ostream& os) + { + set("bw", "b"); + return os; + } + + std::ostream& bright_white_on_green(std::ostream& os) + { + set("bw", "g"); + return os; + } + + std::ostream& bright_white_on_aqua(std::ostream& os) + { + set("bw", "a"); + return os; + } + + std::ostream& bright_white_on_red(std::ostream& os) + { + set("bw", "r"); + return os; + } + + std::ostream& bright_white_on_purple(std::ostream& os) + { + set("bw", "p"); + return os; + } + + std::ostream& bright_white_on_yellow(std::ostream& os) + { + set("bw", "y"); + return os; + } + + std::ostream& bright_white_on_white(std::ostream& os) + { + set("bw", "w"); + return os; + } + + std::ostream& bright_white_on_grey(std::ostream& os) + { + set("bw", "e"); + return os; + } + + std::ostream& bright_white_on_light_blue(std::ostream& os) + { + set("bw", "lb"); + return os; + } + + std::ostream& bright_white_on_light_green(std::ostream& os) + { + set("bw", "lg"); + return os; + } + + std::ostream& bright_white_on_light_aqua(std::ostream& os) + { + set("bw", "la"); + return os; + } + + std::ostream& bright_white_on_light_red(std::ostream& os) + { + set("bw", "lr"); + return os; + } + + std::ostream& bright_white_on_light_purple(std::ostream& os) + { + set("bw", "lp"); + return os; + } + + std::ostream& bright_white_on_light_yellow(std::ostream& os) + { + set("bw", "ly"); + return os; + } + + std::ostream& bright_white_on_bright_white(std::ostream& os) + { + set("bw", "bw"); + return os; + } } -namespace dye -{ - template - using bar = typename std::conditional::value, std::string, T>::type; - - template class colorful; - template class item; - - template - class colorful : private std::list> - { - public: - using std::list>::list; - - colorful& operator+=(const colorful& rhs) - { - this->insert(this->end(), rhs.begin(), rhs.end()); - return *this; - } - - colorful& operator+=(colorful&& rhs) - { - this->splice(this->end(), std::move(rhs)); - return *this; - } - - colorful& operator+=(T t) - { - this->push_back(std::move(t)); - return *this; - } - - void push_front(T t) - { - this->std::list>::push_front(item(std::move(t))); - } - - void push_back(T t) - { - this->std::list>::push_back(item(std::move(t))); - } - - colorful& invert() - { - for (auto& elem : *this) - elem.invert(); - return *this; - } - - template - friend std::ostream& operator<<(std::ostream&, const colorful&); - - template - friend colorful invert(colorful col); - }; - - template - colorful operator+(colorful lhs, colorful rhs) - { - colorful res(std::move(lhs)); - return res += rhs; - } - - template - colorful operator+(colorful lhs, std::string rhs) - { - colorful res(std::move(lhs)); - res.push_back(std::move(rhs)); - return res; - } - - template - colorful operator+(const std::string& lhs, colorful rhs) - { - colorful res(std::move(rhs)); - res.push_front(std::move(lhs)); - return res; - } - - template - std::ostream& operator<<(std::ostream& os, const colorful& colorful) - { - for (const auto& elem : colorful) - os << elem; - return os; - } - - template - colorful invert(colorful col) - { - colorful res(std::move(col)); - for (auto& elem : res) - elem.invert(); - return res; - } - - template - class item - { - T thing; - int color; - - public: - item(T t) : thing(std::move(t)), color(hue::get()) {} - item(T t, int a) : thing(std::move(t)), color(hue::itoc(a)) {} - item(T t, int a, int b) : thing(std::move(t)), color(hue::itoc(a, b)) {} - item(T t, std::string a) : thing(std::move(t)), color(hue::stoc(a)) {} - item(T t, std::string a, std::string b) : thing(std::move(t)), color(hue::stoc(a, b)) {} - - item& invert() - { - color = hue::invert(color); - return *this; - } - - template - friend class colorful; - - template - friend std::ostream& operator<<(std::ostream&, const item&); - }; - - template - std::ostream& operator<<(std::ostream& os, const item& it) - { - hue::set(it.color); - os << it.thing; - hue::reset(); - return os; - } - - template using R = colorful>; - template using S = item>; - - template R colorize(T t, std::string a) { return R { S(t, a) }; } - template R vanilla(T t) { return R { S(t) }; } - template R black(T t) { return R { S(t, "k") }; } - template R blue(T t) { return R { S(t, "b") }; } - template R green(T t) { return R { S(t, "g") }; } - template R aqua(T t) { return R { S(t, "a") }; } - template R red(T t) { return R { S(t, "r") }; } - template R purple(T t) { return R { S(t, "p") }; } - template R yellow(T t) { return R { S(t, "y") }; } - template R white(T t) { return R { S(t, "w") }; } - template R grey(T t) { return R { S(t, "e") }; } - template R light_blue(T t) { return R { S(t, "lb") }; } - template R light_green(T t) { return R { S(t, "lg") }; } - template R light_aqua(T t) { return R { S(t, "la") }; } - template R light_red(T t) { return R { S(t, "lr") }; } - template R light_purple(T t) { return R { S(t, "lp") }; } - template R light_yellow(T t) { return R { S(t, "ly") }; } - template R bright_white(T t) { return R { S(t, "bw") }; } - template R on_black(T t) { return R { S(t, "k", "k") }; } - template R on_blue(T t) { return R { S(t, "k", "b") }; } - template R on_green(T t) { return R { S(t, "k", "g") }; } - template R on_aqua(T t) { return R { S(t, "k", "a") }; } - template R on_red(T t) { return R { S(t, "k", "r") }; } - template R on_purple(T t) { return R { S(t, "k", "p") }; } - template R on_yellow(T t) { return R { S(t, "k", "y") }; } - template R on_white(T t) { return R { S(t, "k", "w") }; } - template R on_grey(T t) { return R { S(t, "k", "e") }; } - template R on_light_blue(T t) { return R { S(t, "k", "lb") }; } - template R on_light_green(T t) { return R { S(t, "k", "lg") }; } - template R on_light_aqua(T t) { return R { S(t, "k", "la") }; } - template R on_light_red(T t) { return R { S(t, "k", "lr") }; } - template R on_light_purple(T t) { return R { S(t, "k", "lp") }; } - template R on_light_yellow(T t) { return R { S(t, "k", "ly") }; } - template R on_bright_white(T t) { return R { S(t, "k", "bw") }; } - template R black_on_black(T t) { return R { S(t, "k", "k") }; } - template R black_on_blue(T t) { return R { S(t, "k", "b") }; } - template R black_on_green(T t) { return R { S(t, "k", "g") }; } - template R black_on_aqua(T t) { return R { S(t, "k", "a") }; } - template R black_on_red(T t) { return R { S(t, "k", "r") }; } - template R black_on_purple(T t) { return R { S(t, "k", "p") }; } - template R black_on_yellow(T t) { return R { S(t, "k", "y") }; } - template R black_on_white(T t) { return R { S(t, "k", "w") }; } - template R black_on_grey(T t) { return R { S(t, "k", "e") }; } - template R black_on_light_blue(T t) { return R { S(t, "k", "lb") }; } - template R black_on_light_green(T t) { return R { S(t, "k", "lg") }; } - template R black_on_light_aqua(T t) { return R { S(t, "k", "la") }; } - template R black_on_light_red(T t) { return R { S(t, "k", "lr") }; } - template R black_on_light_purple(T t) { return R { S(t, "k", "lp") }; } - template R black_on_light_yellow(T t) { return R { S(t, "k", "ly") }; } - template R black_on_bright_white(T t) { return R { S(t, "k", "bw") }; } - template R blue_on_black(T t) { return R { S(t, "b", "k") }; } - template R blue_on_blue(T t) { return R { S(t, "b", "b") }; } - template R blue_on_green(T t) { return R { S(t, "b", "g") }; } - template R blue_on_aqua(T t) { return R { S(t, "b", "a") }; } - template R blue_on_red(T t) { return R { S(t, "b", "r") }; } - template R blue_on_purple(T t) { return R { S(t, "b", "p") }; } - template R blue_on_yellow(T t) { return R { S(t, "b", "y") }; } - template R blue_on_white(T t) { return R { S(t, "b", "w") }; } - template R blue_on_grey(T t) { return R { S(t, "b", "e") }; } - template R blue_on_light_blue(T t) { return R { S(t, "b", "lb") }; } - template R blue_on_light_green(T t) { return R { S(t, "b", "lg") }; } - template R blue_on_light_aqua(T t) { return R { S(t, "b", "la") }; } - template R blue_on_light_red(T t) { return R { S(t, "b", "lr") }; } - template R blue_on_light_purple(T t) { return R { S(t, "b", "lp") }; } - template R blue_on_light_yellow(T t) { return R { S(t, "b", "ly") }; } - template R blue_on_bright_white(T t) { return R { S(t, "b", "bw") }; } - template R green_on_black(T t) { return R { S(t, "g", "k") }; } - template R green_on_blue(T t) { return R { S(t, "g", "b") }; } - template R green_on_green(T t) { return R { S(t, "g", "g") }; } - template R green_on_aqua(T t) { return R { S(t, "g", "a") }; } - template R green_on_red(T t) { return R { S(t, "g", "r") }; } - template R green_on_purple(T t) { return R { S(t, "g", "p") }; } - template R green_on_yellow(T t) { return R { S(t, "g", "y") }; } - template R green_on_white(T t) { return R { S(t, "g", "w") }; } - template R green_on_grey(T t) { return R { S(t, "g", "e") }; } - template R green_on_light_blue(T t) { return R { S(t, "g", "lb") }; } - template R green_on_light_green(T t) { return R { S(t, "g", "lg") }; } - template R green_on_light_aqua(T t) { return R { S(t, "g", "la") }; } - template R green_on_light_red(T t) { return R { S(t, "g", "lr") }; } - template R green_on_light_purple(T t) { return R { S(t, "g", "lp") }; } - template R green_on_light_yellow(T t) { return R { S(t, "g", "ly") }; } - template R green_on_bright_white(T t) { return R { S(t, "g", "bw") }; } - template R aqua_on_black(T t) { return R { S(t, "a", "k") }; } - template R aqua_on_blue(T t) { return R { S(t, "a", "b") }; } - template R aqua_on_green(T t) { return R { S(t, "a", "g") }; } - template R aqua_on_aqua(T t) { return R { S(t, "a", "a") }; } - template R aqua_on_red(T t) { return R { S(t, "a", "r") }; } - template R aqua_on_purple(T t) { return R { S(t, "a", "p") }; } - template R aqua_on_yellow(T t) { return R { S(t, "a", "y") }; } - template R aqua_on_white(T t) { return R { S(t, "a", "w") }; } - template R aqua_on_grey(T t) { return R { S(t, "a", "e") }; } - template R aqua_on_light_blue(T t) { return R { S(t, "a", "lb") }; } - template R aqua_on_light_green(T t) { return R { S(t, "a", "lg") }; } - template R aqua_on_light_aqua(T t) { return R { S(t, "a", "la") }; } - template R aqua_on_light_red(T t) { return R { S(t, "a", "lr") }; } - template R aqua_on_light_purple(T t) { return R { S(t, "a", "lp") }; } - template R aqua_on_light_yellow(T t) { return R { S(t, "a", "ly") }; } - template R aqua_on_bright_white(T t) { return R { S(t, "a", "bw") }; } - template R red_on_black(T t) { return R { S(t, "r", "k") }; } - template R red_on_blue(T t) { return R { S(t, "r", "b") }; } - template R red_on_green(T t) { return R { S(t, "r", "g") }; } - template R red_on_aqua(T t) { return R { S(t, "r", "a") }; } - template R red_on_red(T t) { return R { S(t, "r", "r") }; } - template R red_on_purple(T t) { return R { S(t, "r", "p") }; } - template R red_on_yellow(T t) { return R { S(t, "r", "y") }; } - template R red_on_white(T t) { return R { S(t, "r", "w") }; } - template R red_on_grey(T t) { return R { S(t, "r", "e") }; } - template R red_on_light_blue(T t) { return R { S(t, "r", "lb") }; } - template R red_on_light_green(T t) { return R { S(t, "r", "lg") }; } - template R red_on_light_aqua(T t) { return R { S(t, "r", "la") }; } - template R red_on_light_red(T t) { return R { S(t, "r", "lr") }; } - template R red_on_light_purple(T t) { return R { S(t, "r", "lp") }; } - template R red_on_light_yellow(T t) { return R { S(t, "r", "ly") }; } - template R red_on_bright_white(T t) { return R { S(t, "r", "bw") }; } - template R purple_on_black(T t) { return R { S(t, "p", "k") }; } - template R purple_on_blue(T t) { return R { S(t, "p", "b") }; } - template R purple_on_green(T t) { return R { S(t, "p", "g") }; } - template R purple_on_aqua(T t) { return R { S(t, "p", "a") }; } - template R purple_on_red(T t) { return R { S(t, "p", "r") }; } - template R purple_on_purple(T t) { return R { S(t, "p", "p") }; } - template R purple_on_yellow(T t) { return R { S(t, "p", "y") }; } - template R purple_on_white(T t) { return R { S(t, "p", "w") }; } - template R purple_on_grey(T t) { return R { S(t, "p", "e") }; } - template R purple_on_light_blue(T t) { return R { S(t, "p", "lb") }; } - template R purple_on_light_green(T t) { return R { S(t, "p", "lg") }; } - template R purple_on_light_aqua(T t) { return R { S(t, "p", "la") }; } - template R purple_on_light_red(T t) { return R { S(t, "p", "lr") }; } - template R purple_on_light_purple(T t) { return R { S(t, "p", "lp") }; } - template R purple_on_light_yellow(T t) { return R { S(t, "p", "ly") }; } - template R purple_on_bright_white(T t) { return R { S(t, "p", "bw") }; } - template R yellow_on_black(T t) { return R { S(t, "y", "k") }; } - template R yellow_on_blue(T t) { return R { S(t, "y", "b") }; } - template R yellow_on_green(T t) { return R { S(t, "y", "g") }; } - template R yellow_on_aqua(T t) { return R { S(t, "y", "a") }; } - template R yellow_on_red(T t) { return R { S(t, "y", "r") }; } - template R yellow_on_purple(T t) { return R { S(t, "y", "p") }; } - template R yellow_on_yellow(T t) { return R { S(t, "y", "y") }; } - template R yellow_on_white(T t) { return R { S(t, "y", "w") }; } - template R yellow_on_grey(T t) { return R { S(t, "y", "e") }; } - template R yellow_on_light_blue(T t) { return R { S(t, "y", "lb") }; } - template R yellow_on_light_green(T t) { return R { S(t, "y", "lg") }; } - template R yellow_on_light_aqua(T t) { return R { S(t, "y", "la") }; } - template R yellow_on_light_red(T t) { return R { S(t, "y", "lr") }; } - template R yellow_on_light_purple(T t) { return R { S(t, "y", "lp") }; } - template R yellow_on_light_yellow(T t) { return R { S(t, "y", "ly") }; } - template R yellow_on_bright_white(T t) { return R { S(t, "y", "bw") }; } - template R white_on_black(T t) { return R { S(t, "w", "k") }; } - template R white_on_blue(T t) { return R { S(t, "w", "b") }; } - template R white_on_green(T t) { return R { S(t, "w", "g") }; } - template R white_on_aqua(T t) { return R { S(t, "w", "a") }; } - template R white_on_red(T t) { return R { S(t, "w", "r") }; } - template R white_on_purple(T t) { return R { S(t, "w", "p") }; } - template R white_on_yellow(T t) { return R { S(t, "w", "y") }; } - template R white_on_white(T t) { return R { S(t, "w", "w") }; } - template R white_on_grey(T t) { return R { S(t, "w", "e") }; } - template R white_on_light_blue(T t) { return R { S(t, "w", "lb") }; } - template R white_on_light_green(T t) { return R { S(t, "w", "lg") }; } - template R white_on_light_aqua(T t) { return R { S(t, "w", "la") }; } - template R white_on_light_red(T t) { return R { S(t, "w", "lr") }; } - template R white_on_light_purple(T t) { return R { S(t, "w", "lp") }; } - template R white_on_light_yellow(T t) { return R { S(t, "w", "ly") }; } - template R white_on_bright_white(T t) { return R { S(t, "w", "bw") }; } - template R grey_on_black(T t) { return R { S(t, "e", "k") }; } - template R grey_on_blue(T t) { return R { S(t, "e", "b") }; } - template R grey_on_green(T t) { return R { S(t, "e", "g") }; } - template R grey_on_aqua(T t) { return R { S(t, "e", "a") }; } - template R grey_on_red(T t) { return R { S(t, "e", "r") }; } - template R grey_on_purple(T t) { return R { S(t, "e", "p") }; } - template R grey_on_yellow(T t) { return R { S(t, "e", "y") }; } - template R grey_on_white(T t) { return R { S(t, "e", "w") }; } - template R grey_on_grey(T t) { return R { S(t, "e", "e") }; } - template R grey_on_light_blue(T t) { return R { S(t, "e", "lb") }; } - template R grey_on_light_green(T t) { return R { S(t, "e", "lg") }; } - template R grey_on_light_aqua(T t) { return R { S(t, "e", "la") }; } - template R grey_on_light_red(T t) { return R { S(t, "e", "lr") }; } - template R grey_on_light_purple(T t) { return R { S(t, "e", "lp") }; } - template R grey_on_light_yellow(T t) { return R { S(t, "e", "ly") }; } - template R grey_on_bright_white(T t) { return R { S(t, "e", "bw") }; } - template R light_blue_on_black(T t) { return R { S(t, "lb", "k") }; } - template R light_blue_on_blue(T t) { return R { S(t, "lb", "b") }; } - template R light_blue_on_green(T t) { return R { S(t, "lb", "g") }; } - template R light_blue_on_aqua(T t) { return R { S(t, "lb", "a") }; } - template R light_blue_on_red(T t) { return R { S(t, "lb", "r") }; } - template R light_blue_on_purple(T t) { return R { S(t, "lb", "p") }; } - template R light_blue_on_yellow(T t) { return R { S(t, "lb", "y") }; } - template R light_blue_on_white(T t) { return R { S(t, "lb", "w") }; } - template R light_blue_on_grey(T t) { return R { S(t, "lb", "e") }; } - template R light_blue_on_light_blue(T t) { return R { S(t, "lb", "lb") }; } - template R light_blue_on_light_green(T t) { return R { S(t, "lb", "lg") }; } - template R light_blue_on_light_aqua(T t) { return R { S(t, "lb", "la") }; } - template R light_blue_on_light_red(T t) { return R { S(t, "lb", "lr") }; } - template R light_blue_on_light_purple(T t) { return R { S(t, "lb", "lp") }; } - template R light_blue_on_light_yellow(T t) { return R { S(t, "lb", "ly") }; } - template R light_blue_on_bright_white(T t) { return R { S(t, "lb", "bw") }; } - template R light_green_on_black(T t) { return R { S(t, "lg", "k") }; } - template R light_green_on_blue(T t) { return R { S(t, "lg", "b") }; } - template R light_green_on_green(T t) { return R { S(t, "lg", "g") }; } - template R light_green_on_aqua(T t) { return R { S(t, "lg", "a") }; } - template R light_green_on_red(T t) { return R { S(t, "lg", "r") }; } - template R light_green_on_purple(T t) { return R { S(t, "lg", "p") }; } - template R light_green_on_yellow(T t) { return R { S(t, "lg", "y") }; } - template R light_green_on_white(T t) { return R { S(t, "lg", "w") }; } - template R light_green_on_grey(T t) { return R { S(t, "lg", "e") }; } - template R light_green_on_light_blue(T t) { return R { S(t, "lg", "lb") }; } - template R light_green_on_light_green(T t) { return R { S(t, "lg", "lg") }; } - template R light_green_on_light_aqua(T t) { return R { S(t, "lg", "la") }; } - template R light_green_on_light_red(T t) { return R { S(t, "lg", "lr") }; } - template R light_green_on_light_purple(T t) { return R { S(t, "lg", "lp") }; } - template R light_green_on_light_yellow(T t) { return R { S(t, "lg", "ly") }; } - template R light_green_on_bright_white(T t) { return R { S(t, "lg", "bw") }; } - template R light_aqua_on_black(T t) { return R { S(t, "la", "k") }; } - template R light_aqua_on_blue(T t) { return R { S(t, "la", "b") }; } - template R light_aqua_on_green(T t) { return R { S(t, "la", "g") }; } - template R light_aqua_on_aqua(T t) { return R { S(t, "la", "a") }; } - template R light_aqua_on_red(T t) { return R { S(t, "la", "r") }; } - template R light_aqua_on_purple(T t) { return R { S(t, "la", "p") }; } - template R light_aqua_on_yellow(T t) { return R { S(t, "la", "y") }; } - template R light_aqua_on_white(T t) { return R { S(t, "la", "w") }; } - template R light_aqua_on_grey(T t) { return R { S(t, "la", "e") }; } - template R light_aqua_on_light_blue(T t) { return R { S(t, "la", "lb") }; } - template R light_aqua_on_light_green(T t) { return R { S(t, "la", "lg") }; } - template R light_aqua_on_light_aqua(T t) { return R { S(t, "la", "la") }; } - template R light_aqua_on_light_red(T t) { return R { S(t, "la", "lr") }; } - template R light_aqua_on_light_purple(T t) { return R { S(t, "la", "lp") }; } - template R light_aqua_on_light_yellow(T t) { return R { S(t, "la", "ly") }; } - template R light_aqua_on_bright_white(T t) { return R { S(t, "la", "bw") }; } - template R light_red_on_black(T t) { return R { S(t, "lr", "k") }; } - template R light_red_on_blue(T t) { return R { S(t, "lr", "b") }; } - template R light_red_on_green(T t) { return R { S(t, "lr", "g") }; } - template R light_red_on_aqua(T t) { return R { S(t, "lr", "a") }; } - template R light_red_on_red(T t) { return R { S(t, "lr", "r") }; } - template R light_red_on_purple(T t) { return R { S(t, "lr", "p") }; } - template R light_red_on_yellow(T t) { return R { S(t, "lr", "y") }; } - template R light_red_on_white(T t) { return R { S(t, "lr", "w") }; } - template R light_red_on_grey(T t) { return R { S(t, "lr", "e") }; } - template R light_red_on_light_blue(T t) { return R { S(t, "lr", "lb") }; } - template R light_red_on_light_green(T t) { return R { S(t, "lr", "lg") }; } - template R light_red_on_light_aqua(T t) { return R { S(t, "lr", "la") }; } - template R light_red_on_light_red(T t) { return R { S(t, "lr", "lr") }; } - template R light_red_on_light_purple(T t) { return R { S(t, "lr", "lp") }; } - template R light_red_on_light_yellow(T t) { return R { S(t, "lr", "ly") }; } - template R light_red_on_bright_white(T t) { return R { S(t, "lr", "bw") }; } - template R light_purple_on_black(T t) { return R { S(t, "lp", "k") }; } - template R light_purple_on_blue(T t) { return R { S(t, "lp", "b") }; } - template R light_purple_on_green(T t) { return R { S(t, "lp", "g") }; } - template R light_purple_on_aqua(T t) { return R { S(t, "lp", "a") }; } - template R light_purple_on_red(T t) { return R { S(t, "lp", "r") }; } - template R light_purple_on_purple(T t) { return R { S(t, "lp", "p") }; } - template R light_purple_on_yellow(T t) { return R { S(t, "lp", "y") }; } - template R light_purple_on_white(T t) { return R { S(t, "lp", "w") }; } - template R light_purple_on_grey(T t) { return R { S(t, "lp", "e") }; } - template R light_purple_on_light_blue(T t) { return R { S(t, "lp", "lb") }; } - template R light_purple_on_light_green(T t) { return R { S(t, "lp", "lg") }; } - template R light_purple_on_light_aqua(T t) { return R { S(t, "lp", "la") }; } - template R light_purple_on_light_red(T t) { return R { S(t, "lp", "lr") }; } - template R light_purple_on_light_purple(T t) { return R { S(t, "lp", "lp") }; } - template R light_purple_on_light_yellow(T t) { return R { S(t, "lp", "ly") }; } - template R light_purple_on_bright_white(T t) { return R { S(t, "lp", "bw") }; } - template R light_yellow_on_black(T t) { return R { S(t, "ly", "k") }; } - template R light_yellow_on_blue(T t) { return R { S(t, "ly", "b") }; } - template R light_yellow_on_green(T t) { return R { S(t, "ly", "g") }; } - template R light_yellow_on_aqua(T t) { return R { S(t, "ly", "a") }; } - template R light_yellow_on_red(T t) { return R { S(t, "ly", "r") }; } - template R light_yellow_on_purple(T t) { return R { S(t, "ly", "p") }; } - template R light_yellow_on_yellow(T t) { return R { S(t, "ly", "y") }; } - template R light_yellow_on_white(T t) { return R { S(t, "ly", "w") }; } - template R light_yellow_on_grey(T t) { return R { S(t, "ly", "e") }; } - template R light_yellow_on_light_blue(T t) { return R { S(t, "ly", "lb") }; } - template R light_yellow_on_light_green(T t) { return R { S(t, "ly", "lg") }; } - template R light_yellow_on_light_aqua(T t) { return R { S(t, "ly", "la") }; } - template R light_yellow_on_light_red(T t) { return R { S(t, "ly", "lr") }; } - template R light_yellow_on_light_purple(T t) { return R { S(t, "ly", "lp") }; } - template R light_yellow_on_light_yellow(T t) { return R { S(t, "ly", "ly") }; } - template R light_yellow_on_bright_white(T t) { return R { S(t, "ly", "bw") }; } - template R bright_white_on_black(T t) { return R { S(t, "bw", "k") }; } - template R bright_white_on_blue(T t) { return R { S(t, "bw", "b") }; } - template R bright_white_on_green(T t) { return R { S(t, "bw", "g") }; } - template R bright_white_on_aqua(T t) { return R { S(t, "bw", "a") }; } - template R bright_white_on_red(T t) { return R { S(t, "bw", "r") }; } - template R bright_white_on_purple(T t) { return R { S(t, "bw", "p") }; } - template R bright_white_on_yellow(T t) { return R { S(t, "bw", "y") }; } - template R bright_white_on_white(T t) { return R { S(t, "bw", "w") }; } - template R bright_white_on_grey(T t) { return R { S(t, "bw", "e") }; } - template R bright_white_on_light_blue(T t) { return R { S(t, "bw", "lb") }; } - template R bright_white_on_light_green(T t) { return R { S(t, "bw", "lg") }; } - template R bright_white_on_light_aqua(T t) { return R { S(t, "bw", "la") }; } - template R bright_white_on_light_red(T t) { return R { S(t, "bw", "lr") }; } - template R bright_white_on_light_purple(T t) { return R { S(t, "bw", "lp") }; } - template R bright_white_on_light_yellow(T t) { return R { S(t, "bw", "ly") }; } - template R bright_white_on_bright_white(T t) { return R { S(t, "bw", "bw") }; } +namespace dye +{ + template + using bar = std::conditional_t, std::string, T>; + + template + class colorful; + template + class item; + + template + class colorful : std::list> + { + public: + using std::list>::list; + + colorful& operator+=(const colorful& rhs) + { + this->insert(this->end(), rhs.begin(), rhs.end()); + return *this; + } + + colorful& operator+=(colorful&& rhs) + { + this->splice(this->end(), std::move(rhs)); + return *this; + } + + colorful& operator+=(T t) + { + this->push_back(std::move(t)); + return *this; + } + + void push_front(T t) + { + this->std::list>::push_front(item(std::move(t))); + } + + void push_back(T t) + { + this->std::list>::push_back(item(std::move(t))); + } + + colorful& invert() + { + for (auto& elem : *this) + elem.invert(); + return *this; + } + + template + friend std::ostream& operator<<(std::ostream&, const colorful&); + + template + friend colorful invert(colorful col); + }; + + template + colorful operator+(colorful lhs, colorful rhs) + { + colorful res(std::move(lhs)); + return res += rhs; + } + + template + colorful operator+(colorful lhs, std::string rhs) + { + colorful res(std::move(lhs)); + res.push_back(std::move(rhs)); + return res; + } + + template + colorful operator+(const std::string& lhs, colorful rhs) + { + colorful res(std::move(rhs)); + res.push_front(std::move(lhs)); + return res; + } + + template + std::ostream& operator<<(std::ostream& os, const colorful& colorful) + { + for (const auto& elem : colorful) + os << elem; + return os; + } + + template + colorful invert(colorful col) + { + colorful res(std::move(col)); + for (auto& elem : res) + elem.invert(); + return res; + } + + template + class item + { + T thing; + int color; + + public: + item(T t) : thing(std::move(t)), color(hue::get()) + { + } + + item(T t, int a) : thing(std::move(t)), color(hue::itoc(a)) + { + } + + item(T t, int a, int b) : thing(std::move(t)), color(hue::itoc(a, b)) + { + } + + item(T t, std::string a) : thing(std::move(t)), color(hue::stoc(a)) + { + } + + item(T t, std::string a, std::string b) : thing(std::move(t)), color(hue::stoc(a, b)) + { + } + + item& invert() + { + color = hue::invert(color); + return *this; + } + + template + friend class colorful; + + template + friend std::ostream& operator<<(std::ostream&, const item&); + }; + + template + std::ostream& operator<<(std::ostream& os, const item& it) + { + hue::set(it.color); + os << it.thing; + hue::reset(); + return os; + } + + template + using R = colorful>; + template + using S = item>; + + template + R colorize(T t, std::string a) { return R{S(t, a)}; } + + template + R vanilla(T t) { return R{S(t)}; } + + template + R black(T t) { return R{S(t, "k")}; } + + template + R blue(T t) { return R{S(t, "b")}; } + + template + R green(T t) { return R{S(t, "g")}; } + + template + R aqua(T t) { return R{S(t, "a")}; } + + template + R red(T t) { return R{S(t, "r")}; } + + template + R purple(T t) { return R{S(t, "p")}; } + + template + R yellow(T t) { return R{S(t, "y")}; } + + template + R white(T t) { return R{S(t, "w")}; } + + template + R grey(T t) { return R{S(t, "e")}; } + + template + R light_blue(T t) { return R{S(t, "lb")}; } + + template + R light_green(T t) { return R{S(t, "lg")}; } + + template + R light_aqua(T t) { return R{S(t, "la")}; } + + template + R light_red(T t) { return R{S(t, "lr")}; } + + template + R light_purple(T t) { return R{S(t, "lp")}; } + + template + R light_yellow(T t) { return R{S(t, "ly")}; } + + template + R bright_white(T t) { return R{S(t, "bw")}; } + + template + R on_black(T t) { return R{S(t, "k", "k")}; } + + template + R on_blue(T t) { return R{S(t, "k", "b")}; } + + template + R on_green(T t) { return R{S(t, "k", "g")}; } + + template + R on_aqua(T t) { return R{S(t, "k", "a")}; } + + template + R on_red(T t) { return R{S(t, "k", "r")}; } + + template + R on_purple(T t) { return R{S(t, "k", "p")}; } + + template + R on_yellow(T t) { return R{S(t, "k", "y")}; } + + template + R on_white(T t) { return R{S(t, "k", "w")}; } + + template + R on_grey(T t) { return R{S(t, "k", "e")}; } + + template + R on_light_blue(T t) { return R{S(t, "k", "lb")}; } + + template + R on_light_green(T t) { return R{S(t, "k", "lg")}; } + + template + R on_light_aqua(T t) { return R{S(t, "k", "la")}; } + + template + R on_light_red(T t) { return R{S(t, "k", "lr")}; } + + template + R on_light_purple(T t) { return R{S(t, "k", "lp")}; } + + template + R on_light_yellow(T t) { return R{S(t, "k", "ly")}; } + + template + R on_bright_white(T t) { return R{S(t, "k", "bw")}; } + + template + R black_on_black(T t) { return R{S(t, "k", "k")}; } + + template + R black_on_blue(T t) { return R{S(t, "k", "b")}; } + + template + R black_on_green(T t) { return R{S(t, "k", "g")}; } + + template + R black_on_aqua(T t) { return R{S(t, "k", "a")}; } + + template + R black_on_red(T t) { return R{S(t, "k", "r")}; } + + template + R black_on_purple(T t) { return R{S(t, "k", "p")}; } + + template + R black_on_yellow(T t) { return R{S(t, "k", "y")}; } + + template + R black_on_white(T t) { return R{S(t, "k", "w")}; } + + template + R black_on_grey(T t) { return R{S(t, "k", "e")}; } + + template + R black_on_light_blue(T t) { return R{S(t, "k", "lb")}; } + + template + R black_on_light_green(T t) { return R{S(t, "k", "lg")}; } + + template + R black_on_light_aqua(T t) { return R{S(t, "k", "la")}; } + + template + R black_on_light_red(T t) { return R{S(t, "k", "lr")}; } + + template + R black_on_light_purple(T t) { return R{S(t, "k", "lp")}; } + + template + R black_on_light_yellow(T t) { return R{S(t, "k", "ly")}; } + + template + R black_on_bright_white(T t) { return R{S(t, "k", "bw")}; } + + template + R blue_on_black(T t) { return R{S(t, "b", "k")}; } + + template + R blue_on_blue(T t) { return R{S(t, "b", "b")}; } + + template + R blue_on_green(T t) { return R{S(t, "b", "g")}; } + + template + R blue_on_aqua(T t) { return R{S(t, "b", "a")}; } + + template + R blue_on_red(T t) { return R{S(t, "b", "r")}; } + + template + R blue_on_purple(T t) { return R{S(t, "b", "p")}; } + + template + R blue_on_yellow(T t) { return R{S(t, "b", "y")}; } + + template + R blue_on_white(T t) { return R{S(t, "b", "w")}; } + + template + R blue_on_grey(T t) { return R{S(t, "b", "e")}; } + + template + R blue_on_light_blue(T t) { return R{S(t, "b", "lb")}; } + + template + R blue_on_light_green(T t) { return R{S(t, "b", "lg")}; } + + template + R blue_on_light_aqua(T t) { return R{S(t, "b", "la")}; } + + template + R blue_on_light_red(T t) { return R{S(t, "b", "lr")}; } + + template + R blue_on_light_purple(T t) { return R{S(t, "b", "lp")}; } + + template + R blue_on_light_yellow(T t) { return R{S(t, "b", "ly")}; } + + template + R blue_on_bright_white(T t) { return R{S(t, "b", "bw")}; } + + template + R green_on_black(T t) { return R{S(t, "g", "k")}; } + + template + R green_on_blue(T t) { return R{S(t, "g", "b")}; } + + template + R green_on_green(T t) { return R{S(t, "g", "g")}; } + + template + R green_on_aqua(T t) { return R{S(t, "g", "a")}; } + + template + R green_on_red(T t) { return R{S(t, "g", "r")}; } + + template + R green_on_purple(T t) { return R{S(t, "g", "p")}; } + + template + R green_on_yellow(T t) { return R{S(t, "g", "y")}; } + + template + R green_on_white(T t) { return R{S(t, "g", "w")}; } + + template + R green_on_grey(T t) { return R{S(t, "g", "e")}; } + + template + R green_on_light_blue(T t) { return R{S(t, "g", "lb")}; } + + template + R green_on_light_green(T t) { return R{S(t, "g", "lg")}; } + + template + R green_on_light_aqua(T t) { return R{S(t, "g", "la")}; } + + template + R green_on_light_red(T t) { return R{S(t, "g", "lr")}; } + + template + R green_on_light_purple(T t) { return R{S(t, "g", "lp")}; } + + template + R green_on_light_yellow(T t) { return R{S(t, "g", "ly")}; } + + template + R green_on_bright_white(T t) { return R{S(t, "g", "bw")}; } + + template + R aqua_on_black(T t) { return R{S(t, "a", "k")}; } + + template + R aqua_on_blue(T t) { return R{S(t, "a", "b")}; } + + template + R aqua_on_green(T t) { return R{S(t, "a", "g")}; } + + template + R aqua_on_aqua(T t) { return R{S(t, "a", "a")}; } + + template + R aqua_on_red(T t) { return R{S(t, "a", "r")}; } + + template + R aqua_on_purple(T t) { return R{S(t, "a", "p")}; } + + template + R aqua_on_yellow(T t) { return R{S(t, "a", "y")}; } + + template + R aqua_on_white(T t) { return R{S(t, "a", "w")}; } + + template + R aqua_on_grey(T t) { return R{S(t, "a", "e")}; } + + template + R aqua_on_light_blue(T t) { return R{S(t, "a", "lb")}; } + + template + R aqua_on_light_green(T t) { return R{S(t, "a", "lg")}; } + + template + R aqua_on_light_aqua(T t) { return R{S(t, "a", "la")}; } + + template + R aqua_on_light_red(T t) { return R{S(t, "a", "lr")}; } + + template + R aqua_on_light_purple(T t) { return R{S(t, "a", "lp")}; } + + template + R aqua_on_light_yellow(T t) { return R{S(t, "a", "ly")}; } + + template + R aqua_on_bright_white(T t) { return R{S(t, "a", "bw")}; } + + template + R red_on_black(T t) { return R{S(t, "r", "k")}; } + + template + R red_on_blue(T t) { return R{S(t, "r", "b")}; } + + template + R red_on_green(T t) { return R{S(t, "r", "g")}; } + + template + R red_on_aqua(T t) { return R{S(t, "r", "a")}; } + + template + R red_on_red(T t) { return R{S(t, "r", "r")}; } + + template + R red_on_purple(T t) { return R{S(t, "r", "p")}; } + + template + R red_on_yellow(T t) { return R{S(t, "r", "y")}; } + + template + R red_on_white(T t) { return R{S(t, "r", "w")}; } + + template + R red_on_grey(T t) { return R{S(t, "r", "e")}; } + + template + R red_on_light_blue(T t) { return R{S(t, "r", "lb")}; } + + template + R red_on_light_green(T t) { return R{S(t, "r", "lg")}; } + + template + R red_on_light_aqua(T t) { return R{S(t, "r", "la")}; } + + template + R red_on_light_red(T t) { return R{S(t, "r", "lr")}; } + + template + R red_on_light_purple(T t) { return R{S(t, "r", "lp")}; } + + template + R red_on_light_yellow(T t) { return R{S(t, "r", "ly")}; } + + template + R red_on_bright_white(T t) { return R{S(t, "r", "bw")}; } + + template + R purple_on_black(T t) { return R{S(t, "p", "k")}; } + + template + R purple_on_blue(T t) { return R{S(t, "p", "b")}; } + + template + R purple_on_green(T t) { return R{S(t, "p", "g")}; } + + template + R purple_on_aqua(T t) { return R{S(t, "p", "a")}; } + + template + R purple_on_red(T t) { return R{S(t, "p", "r")}; } + + template + R purple_on_purple(T t) { return R{S(t, "p", "p")}; } + + template + R purple_on_yellow(T t) { return R{S(t, "p", "y")}; } + + template + R purple_on_white(T t) { return R{S(t, "p", "w")}; } + + template + R purple_on_grey(T t) { return R{S(t, "p", "e")}; } + + template + R purple_on_light_blue(T t) { return R{S(t, "p", "lb")}; } + + template + R purple_on_light_green(T t) { return R{S(t, "p", "lg")}; } + + template + R purple_on_light_aqua(T t) { return R{S(t, "p", "la")}; } + + template + R purple_on_light_red(T t) { return R{S(t, "p", "lr")}; } + + template + R purple_on_light_purple(T t) { return R{S(t, "p", "lp")}; } + + template + R purple_on_light_yellow(T t) { return R{S(t, "p", "ly")}; } + + template + R purple_on_bright_white(T t) { return R{S(t, "p", "bw")}; } + + template + R yellow_on_black(T t) { return R{S(t, "y", "k")}; } + + template + R yellow_on_blue(T t) { return R{S(t, "y", "b")}; } + + template + R yellow_on_green(T t) { return R{S(t, "y", "g")}; } + + template + R yellow_on_aqua(T t) { return R{S(t, "y", "a")}; } + + template + R yellow_on_red(T t) { return R{S(t, "y", "r")}; } + + template + R yellow_on_purple(T t) { return R{S(t, "y", "p")}; } + + template + R yellow_on_yellow(T t) { return R{S(t, "y", "y")}; } + + template + R yellow_on_white(T t) { return R{S(t, "y", "w")}; } + + template + R yellow_on_grey(T t) { return R{S(t, "y", "e")}; } + + template + R yellow_on_light_blue(T t) { return R{S(t, "y", "lb")}; } + + template + R yellow_on_light_green(T t) { return R{S(t, "y", "lg")}; } + + template + R yellow_on_light_aqua(T t) { return R{S(t, "y", "la")}; } + + template + R yellow_on_light_red(T t) { return R{S(t, "y", "lr")}; } + + template + R yellow_on_light_purple(T t) { return R{S(t, "y", "lp")}; } + + template + R yellow_on_light_yellow(T t) { return R{S(t, "y", "ly")}; } + + template + R yellow_on_bright_white(T t) { return R{S(t, "y", "bw")}; } + + template + R white_on_black(T t) { return R{S(t, "w", "k")}; } + + template + R white_on_blue(T t) { return R{S(t, "w", "b")}; } + + template + R white_on_green(T t) { return R{S(t, "w", "g")}; } + + template + R white_on_aqua(T t) { return R{S(t, "w", "a")}; } + + template + R white_on_red(T t) { return R{S(t, "w", "r")}; } + + template + R white_on_purple(T t) { return R{S(t, "w", "p")}; } + + template + R white_on_yellow(T t) { return R{S(t, "w", "y")}; } + + template + R white_on_white(T t) { return R{S(t, "w", "w")}; } + + template + R white_on_grey(T t) { return R{S(t, "w", "e")}; } + + template + R white_on_light_blue(T t) { return R{S(t, "w", "lb")}; } + + template + R white_on_light_green(T t) { return R{S(t, "w", "lg")}; } + + template + R white_on_light_aqua(T t) { return R{S(t, "w", "la")}; } + + template + R white_on_light_red(T t) { return R{S(t, "w", "lr")}; } + + template + R white_on_light_purple(T t) { return R{S(t, "w", "lp")}; } + + template + R white_on_light_yellow(T t) { return R{S(t, "w", "ly")}; } + + template + R white_on_bright_white(T t) { return R{S(t, "w", "bw")}; } + + template + R grey_on_black(T t) { return R{S(t, "e", "k")}; } + + template + R grey_on_blue(T t) { return R{S(t, "e", "b")}; } + + template + R grey_on_green(T t) { return R{S(t, "e", "g")}; } + + template + R grey_on_aqua(T t) { return R{S(t, "e", "a")}; } + + template + R grey_on_red(T t) { return R{S(t, "e", "r")}; } + + template + R grey_on_purple(T t) { return R{S(t, "e", "p")}; } + + template + R grey_on_yellow(T t) { return R{S(t, "e", "y")}; } + + template + R grey_on_white(T t) { return R{S(t, "e", "w")}; } + + template + R grey_on_grey(T t) { return R{S(t, "e", "e")}; } + + template + R grey_on_light_blue(T t) { return R{S(t, "e", "lb")}; } + + template + R grey_on_light_green(T t) { return R{S(t, "e", "lg")}; } + + template + R grey_on_light_aqua(T t) { return R{S(t, "e", "la")}; } + + template + R grey_on_light_red(T t) { return R{S(t, "e", "lr")}; } + + template + R grey_on_light_purple(T t) { return R{S(t, "e", "lp")}; } + + template + R grey_on_light_yellow(T t) { return R{S(t, "e", "ly")}; } + + template + R grey_on_bright_white(T t) { return R{S(t, "e", "bw")}; } + + template + R light_blue_on_black(T t) { return R{S(t, "lb", "k")}; } + + template + R light_blue_on_blue(T t) { return R{S(t, "lb", "b")}; } + + template + R light_blue_on_green(T t) { return R{S(t, "lb", "g")}; } + + template + R light_blue_on_aqua(T t) { return R{S(t, "lb", "a")}; } + + template + R light_blue_on_red(T t) { return R{S(t, "lb", "r")}; } + + template + R light_blue_on_purple(T t) { return R{S(t, "lb", "p")}; } + + template + R light_blue_on_yellow(T t) { return R{S(t, "lb", "y")}; } + + template + R light_blue_on_white(T t) { return R{S(t, "lb", "w")}; } + + template + R light_blue_on_grey(T t) { return R{S(t, "lb", "e")}; } + + template + R light_blue_on_light_blue(T t) { return R{S(t, "lb", "lb")}; } + + template + R light_blue_on_light_green(T t) { return R{S(t, "lb", "lg")}; } + + template + R light_blue_on_light_aqua(T t) { return R{S(t, "lb", "la")}; } + + template + R light_blue_on_light_red(T t) { return R{S(t, "lb", "lr")}; } + + template + R light_blue_on_light_purple(T t) { return R{S(t, "lb", "lp")}; } + + template + R light_blue_on_light_yellow(T t) { return R{S(t, "lb", "ly")}; } + + template + R light_blue_on_bright_white(T t) { return R{S(t, "lb", "bw")}; } + + template + R light_green_on_black(T t) { return R{S(t, "lg", "k")}; } + + template + R light_green_on_blue(T t) { return R{S(t, "lg", "b")}; } + + template + R light_green_on_green(T t) { return R{S(t, "lg", "g")}; } + + template + R light_green_on_aqua(T t) { return R{S(t, "lg", "a")}; } + + template + R light_green_on_red(T t) { return R{S(t, "lg", "r")}; } + + template + R light_green_on_purple(T t) { return R{S(t, "lg", "p")}; } + + template + R light_green_on_yellow(T t) { return R{S(t, "lg", "y")}; } + + template + R light_green_on_white(T t) { return R{S(t, "lg", "w")}; } + + template + R light_green_on_grey(T t) { return R{S(t, "lg", "e")}; } + + template + R light_green_on_light_blue(T t) { return R{S(t, "lg", "lb")}; } + + template + R light_green_on_light_green(T t) { return R{S(t, "lg", "lg")}; } + + template + R light_green_on_light_aqua(T t) { return R{S(t, "lg", "la")}; } + + template + R light_green_on_light_red(T t) { return R{S(t, "lg", "lr")}; } + + template + R light_green_on_light_purple(T t) { return R{S(t, "lg", "lp")}; } + + template + R light_green_on_light_yellow(T t) { return R{S(t, "lg", "ly")}; } + + template + R light_green_on_bright_white(T t) { return R{S(t, "lg", "bw")}; } + + template + R light_aqua_on_black(T t) { return R{S(t, "la", "k")}; } + + template + R light_aqua_on_blue(T t) { return R{S(t, "la", "b")}; } + + template + R light_aqua_on_green(T t) { return R{S(t, "la", "g")}; } + + template + R light_aqua_on_aqua(T t) { return R{S(t, "la", "a")}; } + + template + R light_aqua_on_red(T t) { return R{S(t, "la", "r")}; } + + template + R light_aqua_on_purple(T t) { return R{S(t, "la", "p")}; } + + template + R light_aqua_on_yellow(T t) { return R{S(t, "la", "y")}; } + + template + R light_aqua_on_white(T t) { return R{S(t, "la", "w")}; } + + template + R light_aqua_on_grey(T t) { return R{S(t, "la", "e")}; } + + template + R light_aqua_on_light_blue(T t) { return R{S(t, "la", "lb")}; } + + template + R light_aqua_on_light_green(T t) { return R{S(t, "la", "lg")}; } + + template + R light_aqua_on_light_aqua(T t) { return R{S(t, "la", "la")}; } + + template + R light_aqua_on_light_red(T t) { return R{S(t, "la", "lr")}; } + + template + R light_aqua_on_light_purple(T t) { return R{S(t, "la", "lp")}; } + + template + R light_aqua_on_light_yellow(T t) { return R{S(t, "la", "ly")}; } + + template + R light_aqua_on_bright_white(T t) { return R{S(t, "la", "bw")}; } + + template + R light_red_on_black(T t) { return R{S(t, "lr", "k")}; } + + template + R light_red_on_blue(T t) { return R{S(t, "lr", "b")}; } + + template + R light_red_on_green(T t) { return R{S(t, "lr", "g")}; } + + template + R light_red_on_aqua(T t) { return R{S(t, "lr", "a")}; } + + template + R light_red_on_red(T t) { return R{S(t, "lr", "r")}; } + + template + R light_red_on_purple(T t) { return R{S(t, "lr", "p")}; } + + template + R light_red_on_yellow(T t) { return R{S(t, "lr", "y")}; } + + template + R light_red_on_white(T t) { return R{S(t, "lr", "w")}; } + + template + R light_red_on_grey(T t) { return R{S(t, "lr", "e")}; } + + template + R light_red_on_light_blue(T t) { return R{S(t, "lr", "lb")}; } + + template + R light_red_on_light_green(T t) { return R{S(t, "lr", "lg")}; } + + template + R light_red_on_light_aqua(T t) { return R{S(t, "lr", "la")}; } + + template + R light_red_on_light_red(T t) { return R{S(t, "lr", "lr")}; } + + template + R light_red_on_light_purple(T t) { return R{S(t, "lr", "lp")}; } + + template + R light_red_on_light_yellow(T t) { return R{S(t, "lr", "ly")}; } + + template + R light_red_on_bright_white(T t) { return R{S(t, "lr", "bw")}; } + + template + R light_purple_on_black(T t) { return R{S(t, "lp", "k")}; } + + template + R light_purple_on_blue(T t) { return R{S(t, "lp", "b")}; } + + template + R light_purple_on_green(T t) { return R{S(t, "lp", "g")}; } + + template + R light_purple_on_aqua(T t) { return R{S(t, "lp", "a")}; } + + template + R light_purple_on_red(T t) { return R{S(t, "lp", "r")}; } + + template + R light_purple_on_purple(T t) { return R{S(t, "lp", "p")}; } + + template + R light_purple_on_yellow(T t) { return R{S(t, "lp", "y")}; } + + template + R light_purple_on_white(T t) { return R{S(t, "lp", "w")}; } + + template + R light_purple_on_grey(T t) { return R{S(t, "lp", "e")}; } + + template + R light_purple_on_light_blue(T t) { return R{S(t, "lp", "lb")}; } + + template + R light_purple_on_light_green(T t) { return R{S(t, "lp", "lg")}; } + + template + R light_purple_on_light_aqua(T t) { return R{S(t, "lp", "la")}; } + + template + R light_purple_on_light_red(T t) { return R{S(t, "lp", "lr")}; } + + template + R light_purple_on_light_purple(T t) { return R{S(t, "lp", "lp")}; } + + template + R light_purple_on_light_yellow(T t) { return R{S(t, "lp", "ly")}; } + + template + R light_purple_on_bright_white(T t) { return R{S(t, "lp", "bw")}; } + + template + R light_yellow_on_black(T t) { return R{S(t, "ly", "k")}; } + + template + R light_yellow_on_blue(T t) { return R{S(t, "ly", "b")}; } + + template + R light_yellow_on_green(T t) { return R{S(t, "ly", "g")}; } + + template + R light_yellow_on_aqua(T t) { return R{S(t, "ly", "a")}; } + + template + R light_yellow_on_red(T t) { return R{S(t, "ly", "r")}; } + + template + R light_yellow_on_purple(T t) { return R{S(t, "ly", "p")}; } + + template + R light_yellow_on_yellow(T t) { return R{S(t, "ly", "y")}; } + + template + R light_yellow_on_white(T t) { return R{S(t, "ly", "w")}; } + + template + R light_yellow_on_grey(T t) { return R{S(t, "ly", "e")}; } + + template + R light_yellow_on_light_blue(T t) { return R{S(t, "ly", "lb")}; } + + template + R light_yellow_on_light_green(T t) { return R{S(t, "ly", "lg")}; } + + template + R light_yellow_on_light_aqua(T t) { return R{S(t, "ly", "la")}; } + + template + R light_yellow_on_light_red(T t) { return R{S(t, "ly", "lr")}; } + + template + R light_yellow_on_light_purple(T t) { return R{S(t, "ly", "lp")}; } + + template + R light_yellow_on_light_yellow(T t) { return R{S(t, "ly", "ly")}; } + + template + R light_yellow_on_bright_white(T t) { return R{S(t, "ly", "bw")}; } + + template + R bright_white_on_black(T t) { return R{S(t, "bw", "k")}; } + + template + R bright_white_on_blue(T t) { return R{S(t, "bw", "b")}; } + + template + R bright_white_on_green(T t) { return R{S(t, "bw", "g")}; } + + template + R bright_white_on_aqua(T t) { return R{S(t, "bw", "a")}; } + + template + R bright_white_on_red(T t) { return R{S(t, "bw", "r")}; } + + template + R bright_white_on_purple(T t) { return R{S(t, "bw", "p")}; } + + template + R bright_white_on_yellow(T t) { return R{S(t, "bw", "y")}; } + + template + R bright_white_on_white(T t) { return R{S(t, "bw", "w")}; } + + template + R bright_white_on_grey(T t) { return R{S(t, "bw", "e")}; } + + template + R bright_white_on_light_blue(T t) { return R{S(t, "bw", "lb")}; } + + template + R bright_white_on_light_green(T t) { return R{S(t, "bw", "lg")}; } + + template + R bright_white_on_light_aqua(T t) { return R{S(t, "bw", "la")}; } + + template + R bright_white_on_light_red(T t) { return R{S(t, "bw", "lr")}; } + + template + R bright_white_on_light_purple(T t) { return R{S(t, "bw", "lp")}; } + + template + R bright_white_on_light_yellow(T t) { return R{S(t, "bw", "ly")}; } + + template + R bright_white_on_bright_white(T t) { return R{S(t, "bw", "bw")}; } } -#endif \ No newline at end of file +#endif diff --git a/Scoop-Search/util.cpp b/Scoop-Search/util.cpp index 2bce741..4e20c26 100644 --- a/Scoop-Search/util.cpp +++ b/Scoop-Search/util.cpp @@ -19,21 +19,21 @@ namespace util std::wstring u2w(const std::string_view& input) { const size_t wlen = MultiByteToWideChar(CP_UTF8, NULL, - input.data(), input.size(), nullptr, 0); + input.data(), input.size(), nullptr, 0); const auto wstr = std::make_shared(wlen); MultiByteToWideChar(CP_UTF8,NULL, input.data(), input.size(), wstr.get(), wlen); - return { wstr.get(), wlen }; + return {wstr.get(), wlen}; } std::wstring a2w(const std::string_view& input) { const size_t wlen = MultiByteToWideChar(CP_ACP, NULL, - input.data(), input.size(), nullptr, 0); + input.data(), input.size(), nullptr, 0); const auto wstr = std::make_shared(wlen); MultiByteToWideChar(CP_ACP, NULL, input.data(), input.size(), wstr.get(), wlen); - return { wstr.get(), wlen }; + return {wstr.get(), wlen}; } std::string w2u(const std::wstring_view& input) @@ -43,17 +43,17 @@ namespace util const auto str = std::make_shared(len); WideCharToMultiByte(CP_UTF8, NULL, input.data(), input.size(), str.get(), len, nullptr, nullptr); - return { str.get(), len }; + return {str.get(), len}; } std::string w2a(const std::wstring_view& input) { size_t len = WideCharToMultiByte(CP_ACP, NULL, - input.data(), input.size(), nullptr, 0, nullptr, nullptr); + input.data(), input.size(), nullptr, 0, nullptr, nullptr); const auto str = std::make_shared(len); WideCharToMultiByte(CP_ACP, NULL, input.data(), input.size(), str.get(), len, nullptr, nullptr); - return { str.get(), len }; + return {str.get(), len}; } std::string u2a(const std::string_view& input) @@ -75,13 +75,15 @@ namespace util }; } - bool string_find(const std::string& str1, const std::string& str2, bool ignore_case) + bool string_find(const std::string& str1, const std::string& str2, const bool ignore_case) { if (ignore_case) { const auto it = std::ranges::search(str1, str2, - [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); } - ).begin(); + [](const char ch1, const char ch2) + { + return std::toupper(ch1) == std::toupper(ch2); + }).begin(); return (it != str1.end()); } return str1.find(str2) != std::string::npos;