From a89bdd4110a2bf521d6188a99c8508e838675ad3 Mon Sep 17 00:00:00 2001 From: MysteryBirb Date: Sun, 13 Sep 2026 21:10:57 +0200 Subject: [PATCH] Trying around with strings instead of char for future unicode support --- cli-flag-collection.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cli-flag-collection.cpp b/cli-flag-collection.cpp index 130c7c0..5216ff7 100644 --- a/cli-flag-collection.cpp +++ b/cli-flag-collection.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -11,29 +12,31 @@ int flagWidth; int flagHeight; -char flagChar = ' '; +std::string flagChar(" "); void drawFlag(const unsigned char flagArray[][3], unsigned char flagStripes) { short i, y, j; - + for (i = 0; i < flagStripes; i++) { if (flagHeight / flagStripes <= 0) { std::cerr << "Integer too small!" << std::endl; break; } for (y = 0; y < flagHeight / flagStripes; y++) { - if (flagChar != ' ') { + if (flagChar != " ") { + flagChar.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); + std::print("{0}", flagChar.at(0)); // Imma leave this how it is before i deal with bs letters like 'รค' } } std::println("\x1b[0m"); } + //std::println("Divided length: {0}\nflagWidth: {1}", (flagWidth / flagChar.size()), flagWidth); } int main(int argc, char **argv) { @@ -41,9 +44,13 @@ int main(int argc, char **argv) { * TODO: * - Bi flag handle * - add more flags for inclusivity - * - Handle Unicode argv + * - Handle Unicode argv (This fucking bitch is driving me insane I can't take it anymore) + * - ^ Handle strings(?) */ + //std::setlocale(LC_CTYPE, "de_DE.utf8"); + //std::locale::global(std::locale("de_DE.utf8")); + static struct option long_options[] { {"help", no_argument, nullptr, HELP}, {"list", no_argument, nullptr, LIST}, @@ -72,8 +79,6 @@ int main(int argc, char **argv) { short allFlagsSize = sizeof(allFlags) / sizeof(allFlags[0]); int opt; - // getopt(argc, argv, "lfh") - while ((opt = getopt_long(argc, argv, "h:c:f:", long_options, nullptr)) != -1) { switch (opt) { case '0': @@ -94,7 +99,7 @@ int main(int argc, char **argv) { return 1; } else { - flagChar = *argv[optind - 1]; + flagChar.insert(0, argv[optind - 1]); // I will keep this at index 0 so it can't even break it for now } break; case 'f':