diff --git a/cli-flag-collection.cpp b/cli-flag-collection.cpp index 5216ff7..f5b7122 100644 --- a/cli-flag-collection.cpp +++ b/cli-flag-collection.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -12,10 +11,23 @@ int flagWidth; int flagHeight; -std::string flagChar(" "); +std::string flagStr(" "); void drawFlag(const unsigned char flagArray[][3], unsigned char flagStripes) { - short i, y, j; + short i, y, j, uni = 0; + short divLen = flagStr.size(); + + // Hopefully will handle all unicode things in a string + for (int k : flagStr) { + if (k < 0 && uni != 2) { + uni++; + } + if (uni == 2) { + divLen -= 1; + uni = 0; + } + } + //std::println("Divided length: {0} ({1} / {2})", (flagWidth / divLen), flagWidth, divLen); for (i = 0; i < flagStripes; i++) { if (flagHeight / flagStripes <= 0) { @@ -23,20 +35,19 @@ void drawFlag(const unsigned char flagArray[][3], unsigned char flagStripes) { break; } for (y = 0; y < flagHeight / flagStripes; y++) { - if (flagChar != " ") { - flagChar.shrink_to_fit(); + if (flagStr != " ") { + flagStr.shrink_to_fit(); std::print("\x1b[38;2;{0};{1};{2}m", flagArray[i][0], flagArray[i][1], flagArray[i][2]); } else { std::print("\x1b[48;2;{0};{1};{2}m", flagArray[i][0], flagArray[i][1], flagArray[i][2]); } - for (j = 0; j < flagWidth; j++) { - std::print("{0}", flagChar.at(0)); // Imma leave this how it is before i deal with bs letters like 'รค' + for (j = 0; j < flagWidth / divLen; j++) { + std::print("{0}", flagStr); } } std::println("\x1b[0m"); } - //std::println("Divided length: {0}\nflagWidth: {1}", (flagWidth / flagChar.size()), flagWidth); } int main(int argc, char **argv) { @@ -56,7 +67,7 @@ int main(int argc, char **argv) { {"list", no_argument, nullptr, LIST}, {"flag", required_argument, nullptr, 'f'}, {"height", required_argument, nullptr, 'h'}, - {"character", required_argument, nullptr, 'c'}, + {"string", required_argument, nullptr, 's'}, {nullptr, 0, nullptr, 0}, }; @@ -79,7 +90,7 @@ int main(int argc, char **argv) { short allFlagsSize = sizeof(allFlags) / sizeof(allFlags[0]); int opt; - while ((opt = getopt_long(argc, argv, "h:c:f:", long_options, nullptr)) != -1) { + while ((opt = getopt_long(argc, argv, "h:s:f:", long_options, nullptr)) != -1) { switch (opt) { case '0': std::print("{}", opt); @@ -93,13 +104,13 @@ int main(int argc, char **argv) { flagHeight = atoi(argv[optind - 1]); } break; - case 'c': + case 's': if (argc == 3 || argc == 2) { std::cerr << "You can't run '" << argv[1] << "' alone!\n"; return 1; } else { - flagChar.insert(0, argv[optind - 1]); // I will keep this at index 0 so it can't even break it for now + flagStr = argv[optind - 1]; // I will keep this at index 0 so it can't even break it for now } break; case 'f': @@ -149,8 +160,8 @@ int main(int argc, char **argv) { << "All options:\n" << "\t-f, --flag [FLAG]\t\tPrints the chosen flag\n" << "\t-h, --height [Integer]\t\tPrints the flag with the chosen positive integer\n" - << "\t-c, --character \'[Char]\'\tPrint the chosen flag with the given character (Only supports ASCII for now)\n" - << "\t--list\t\t\tList all available flags\n" + << "\t-s, --string \'[String]\'\t\tPrint the chosen flag with the given string (Flag width is not yet perfectly variable)\n" + << "\t--list\t\t\t\tList all available flags\n" << "\t--help\t\t\t\tPrints out the help screen\n"; return 0; case '?':