Watch
1
0
Fork
You've already forked cli-flag-collection
0
mirror of synced 2026-11-03 21:37:17 +00:00

Trying around with strings instead of char for future unicode support

This commit is contained in:
MysteryBirb 2026-09-13 21:10:57 +02:00
commit a89bdd4110

View file

@ -1,3 +1,4 @@
#include <clocale>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -11,7 +12,7 @@
int flagWidth; int flagWidth;
int flagHeight; int flagHeight;
char flagChar = ' '; std::string flagChar(" ");
void drawFlag(const unsigned char flagArray[][3], unsigned char flagStripes) { void drawFlag(const unsigned char flagArray[][3], unsigned char flagStripes) {
short i, y, j; short i, y, j;
@ -22,18 +23,20 @@ void drawFlag(const unsigned char flagArray[][3], unsigned char flagStripes) {
break; break;
} }
for (y = 0; y < flagHeight / flagStripes; y++) { 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]); std::print("\x1b[38;2;{0};{1};{2}m", flagArray[i][0], flagArray[i][1], flagArray[i][2]);
} }
else { else {
std::print("\x1b[48;2;{0};{1};{2}m", flagArray[i][0], flagArray[i][1], flagArray[i][2]); std::print("\x1b[48;2;{0};{1};{2}m", flagArray[i][0], flagArray[i][1], flagArray[i][2]);
} }
for (j = 0; j < flagWidth; j++) { 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("\x1b[0m");
} }
//std::println("Divided length: {0}\nflagWidth: {1}", (flagWidth / flagChar.size()), flagWidth);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -41,9 +44,13 @@ int main(int argc, char **argv) {
* TODO: * TODO:
* - Bi flag handle * - Bi flag handle
* - add more flags for inclusivity * - 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[] { static struct option long_options[] {
{"help", no_argument, nullptr, HELP}, {"help", no_argument, nullptr, HELP},
{"list", no_argument, nullptr, LIST}, {"list", no_argument, nullptr, LIST},
@ -72,8 +79,6 @@ int main(int argc, char **argv) {
short allFlagsSize = sizeof(allFlags) / sizeof(allFlags[0]); short allFlagsSize = sizeof(allFlags) / sizeof(allFlags[0]);
int opt; int opt;
// getopt(argc, argv, "lfh")
while ((opt = getopt_long(argc, argv, "h:c:f:", long_options, nullptr)) != -1) { while ((opt = getopt_long(argc, argv, "h:c:f:", long_options, nullptr)) != -1) {
switch (opt) { switch (opt) {
case '0': case '0':
@ -94,7 +99,7 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
else { 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; break;
case 'f': case 'f':