initial minimal branch implementation

This commit is contained in:
Valerie Wolfe 2024-03-23 12:18:01 -04:00
parent 735d8394fd
commit 8c592ab83e
3 changed files with 103 additions and 110 deletions

View file

@ -1,5 +1,7 @@
# Pride! for the tty
# Pride! for the tty (minimal)
A C utility to display flags in 8-color terminals.
The goal of the minimal branch is to be as small as possible.

View file

@ -1,4 +1,4 @@
build:
gcc main.c basic.c full.c -o pride-c
gcc -s main.c -o pride-c

207
main.c
View file

@ -1,134 +1,125 @@
#include <stdio.h>
#include <string.h>
#define VERSION "0.0.1"
#define INDENT " "
#define ANSI "\x1b[38;5;"
#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define GRAY 7
#define L_BLACK 8
#define L_RED 9
#define L_GREEN 10
#define L_YELLOW 11
#define L_BLUE 12
#define L_MAGENTA 13
#define L_CYAN 14
#define WHITE 15
#define RESET "\x1b[0m"
#define COLOR(n) "\x1b[38;5;" #n "m"
#define BLACK COLOR(0)
#define RED COLOR(1)
#define GREEN COLOR(2)
#define YELLOW COLOR(3)
#define BLUE COLOR(4)
#define MAGENTA COLOR(5)
#define CYAN COLOR(6)
#define GRAY COLOR(7)
#define L_BLACK COLOR(8)
#define L_RED COLOR(9)
#define L_GREEN COLOR(10)
#define L_YELLOW COLOR(11)
#define L_BLUE COLOR(12)
#define L_MAGENTA COLOR(13)
#define L_CYAN COLOR(14)
#define WHITE COLOR(15)
#define STRIPE "██████████████████\n"
#define RAINBOW "rainbow"
#define AROACE "aroace"
#define BISEXUAL "bisexual"
#define LESBIAN "lesbian"
#define NONBINARY "nonbinary"
#define PANSEXUAL "pansexual"
#define TRANSGENDER "transgender"
#define STRIPE "█████████████████\n"
void version() {
printf("pride-c v" VERSION "\n");
printf("pride-c min v" VERSION "\n");
}
void help() {
version();
printf(
"Valerie Wolfe <sleeplessval@gmail.com>\n"
"Display 256-color pride flags in the terminal.\n\n"
"Display 8-color pride flags in the terminal.\n\n"
"usage: pride [name]\n\n"
"usage: pride [symbol]\n\n"
"flag names:\n"
INDENT AROACE "\n"
INDENT BISEXUAL "\n"
INDENT LESBIAN "\n"
INDENT NONBINARY "\n"
INDENT PANSEXUAL "\n"
INDENT RAINBOW "\n"
INDENT TRANSGENDER "\n"
"symbols:\n"
" l lesbian flag\n"
" g gay flag\n"
" b bisexual flag\n"
" t transgender flag\n"
" n nonbinary flag\n"
" p pansexual flag\n"
" r rainbow flag\n"
" h help text\n"
" v version text\n"
);
}
void stripe(const unsigned short int color) {
printf(ANSI "%dum" STRIPE, color);
}
int main(int argc, char **argv) {
// get argv[1] or fall back to RAINBOW
char *flag;
if(argc > 1) { flag = argv[1]; }
else { flag = RAINBOW; }
char sym;
if(argc > 1) { sym = argv[1][0]; }
else { sym = 'r'; }
// handle flags
if(strcmp(flag, "--version") == 0) {
version();
return 0;
} else if(strcmp(flag, "--help") == 0) {
help();
return 0;
switch(sym) {
case 'b': // - BISEXUAL -
stripe(RED);
stripe(MAGENTA);
stripe(BLUE);
break;
case 'h': // - HELP TEXT -
help();
break;
case 'g': // - GAY -
stripe(CYAN);
stripe(L_CYAN);
stripe(WHITE);
stripe(L_BLUE);
stripe(BLUE);
break;
case 'l': // - LESBIAN -
stripe(RED);
stripe(L_RED);
stripe(WHITE);
stripe(L_MAGENTA);
stripe(MAGENTA);
break;
case 'n': // - NON-BINARY -
stripe(L_YELLOW);
stripe(WHITE);
stripe(MAGENTA);
stripe(BLACK);
break;
case 'p': // - PANSEXUAL -
draw(MAGENTA);
draw(L_YELLOW);
draw(CYAN);
break;
case 'r': // - RAINBOW -
draw(RED);
draw(L_RED);
draw(L_YELLOW);
draw(GREEN);
draw(BLUE);
draw(MAGENTA);
break;
case 't': // - TRANSGENDER -
stripe(L_CYAN);
stripe(L_MAGENTA);
stripe(WHITE);
stripe(L_MAGENTA);
stripe(L_CYAN);
break;
default:
printf("pride-c: no flag '%c' found", sym
}
if(strcmp(flag, RAINBOW) == 0) { // - RAINBOW -
printf(RED STRIPE);
printf(L_RED STRIPE);
printf(L_YELLOW STRIPE);
printf(GREEN STRIPE);
printf(BLUE STRIPE);
printf(MAGENTA STRIPE);
}
else if(strcmp(flag, AROACE) == 0) { // - ARO/ACE -
printf(YELLOW STRIPE);
printf(L_YELLOW STRIPE);
printf(WHITE STRIPE);
printf(L_CYAN STRIPE);
printf(BLUE STRIPE);
}
else if(strcmp(flag, BISEXUAL) == 0) { // - BISEXUAL -
printf(RED STRIPE STRIPE);
printf(MAGENTA STRIPE);
printf(BLUE STRIPE STRIPE);
}
else if(strcmp(flag, LESBIAN) == 0) { // - LESBIAN -
printf(RED STRIPE); // orange
printf(L_RED STRIPE); // tangerine
printf(WHITE STRIPE); // white
printf(L_MAGENTA STRIPE); // pink
printf(MAGENTA STRIPE); // magenta
}
else if(strcmp(flag, NONBINARY) == 0) { // - NONBINARY -
printf(L_YELLOW STRIPE); // yellow
printf(WHITE STRIPE); // white
printf(MAGENTA STRIPE); // purple
printf(BLACK STRIPE); // black
}
else if(strcmp(flag, PANSEXUAL) == 0) { // - PANSEXUAL -
printf(MAGENTA STRIPE STRIPE);
printf(L_YELLOW STRIPE STRIPE);
printf(CYAN STRIPE STRIPE);
}
else if(strcmp(flag, TRANSGENDER) == 0) { // - TRANSGENDER -
printf(L_CYAN STRIPE);
printf(L_MAGENTA STRIPE);
printf(WHITE STRIPE);
printf(L_MAGENTA STRIPE);
printf(L_CYAN STRIPE);
}
else {
printf("pride-c: no flag '%s' found.", flag);
return 1;
}
printf(RESET);
return 0;
}