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

Compare commits

...
Author SHA1 Message Date
MysteryBirb
d2e9364271 Updated TODO in source file 2026-09-14 13:47:53 +02:00
MysteryBirb
841772a50f Updated README to fit the --help page 2026-09-14 13:46:20 +02:00
MysteryBirb
20624c4564 Unicode is hopefully handled; flag width is not perfectly variable 2026-09-14 13:28:05 +02:00
2 changed files with 26 additions and 17 deletions

View file

@ -56,7 +56,7 @@ Usage: ./cfc-cli [OPTION] [ARGUMENT] -f [FLAG]
All options:
-f, --flag [FLAG] Prints the chosen flag
-h, --height [Integer] Prints the flag with the chosen positive integer
-c, --character '[Char]' Print the chosen flag with the given character (Only supports ASCII for now)
-s, --string '[String]' Print the chosen flag with the given string (Flag width is not yet perfectly variable)
--list List all available flags
--help Prints out the help screen
```

View file

@ -1,4 +1,3 @@
#include <clocale>
#include <cstdlib>
#include <iostream>
#include <string>
@ -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) {
@ -44,8 +55,6 @@ int main(int argc, char **argv) {
* TODO:
* - Bi flag handle
* - add more flags for inclusivity
* - 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");
@ -56,7 +65,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 +88,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 +102,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 +158,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 '?':