Compare commits

...

16 commits

9 changed files with 353 additions and 94 deletions

View file

@ -1,5 +1,14 @@
# Pride! for the tty # Pride! for the tty
A C utility to display flags in 8-color terminals. A utility to display pride flags in 8- or 256- color terminals.
This is a C version of my [pride](https://git.vwolfe.io/valerie/pride) utility,
focused on compatibility.
## Goals
- Compatible: Runs, compiles, and correctly displays on almost anything.
- Low-dependency: Only uses the standard library.
- Small: Low compiled binary size.

95
basic.c Normal file
View file

@ -0,0 +1,95 @@
#include "basic.h"
#include <stdio.h>
#include "draw.h"
void rainbow_8() {
const color colors [] = {
RED,
L_RED,
L_YELLOW,
GREEN,
BLUE,
MAGENTA
};
draw(6, colors);
}
void aroace_8() {
const color colors [] = {
YELLOW,
L_YELLOW,
WHITE,
L_CYAN,
BLUE
};
draw(5, colors);
}
void bisexual_8() {
const color colors [] = {
RED,
RED,
MAGENTA,
BLUE,
BLUE
};
draw(5, colors);
}
void gay_8() {
const color colors [] = {
CYAN,
L_CYAN,
WHITE,
L_BLUE,
BLUE
};
draw(5, colors);
}
void lesbian_8() {
const color colors [] = {
RED,
L_RED,
WHITE,
L_MAGENTA,
MAGENTA
};
draw(5, colors);
}
void nonbinary_8() {
const color colors [] = {
L_YELLOW,
WHITE,
MAGENTA,
BLACK
};
draw(4, colors);
}
void pansexual_8() {
const color colors [] = {
MAGENTA,
MAGENTA,
L_YELLOW,
L_YELLOW,
CYAN,
CYAN
};
draw(6, colors);
}
void transgender_8() {
const color colors [] = {
L_CYAN,
L_MAGENTA,
WHITE,
L_MAGENTA,
L_CYAN
};
draw(5, colors);
}

28
basic.h Normal file
View file

@ -0,0 +1,28 @@
#pragma once
#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
void rainbow_8();
void aroace_8();
void bisexual_8();
void gay_8();
void lesbian_8();
void nonbinary_8();
void pansexual_8();
void transgender_8();

10
draw.c Normal file
View file

@ -0,0 +1,10 @@
#include "draw.h"
#include <stdio.h>
void draw(const unsigned short int len, const color colors []) {
for(int i = 0; i < len; i++) {
printf(ANSI "%dm" STRIPE, colors[i]);
}
}

10
draw.h Normal file
View file

@ -0,0 +1,10 @@
#pragma once
#define ANSI "\x1b[38;5;"
#define COLOR(n) ANSI #n "m"
#define STRIPE "██████████████████\n"
typedef unsigned short int color;
void draw(const unsigned short int len, const color colors[]);

94
full.c Normal file
View file

@ -0,0 +1,94 @@
#include "full.h"
#include <stdio.h>
#include "draw.h"
void rainbow_256() {
const color colors [] = {
196, // red
208, // orange
220, // yellow
28, // green
21, // blue
90 // purple
};
draw(6, colors);
}
void aroace_256() {
const color colors [] = {
172, // orange
184, // yellow
255, // white
38, // blue
17 // navy
};
draw(5, colors);
}
void bisexual_256() {
const color colors [] = {
161, // magenta
161,
91, // purple
21,
21 // blue
};
draw(5, colors);
}
void gay_256() {
const color colors [] = {
29,
49, // greens
123,
255, // white
75,
63, // blues
56
};
draw(7, colors);
}
void lesbian_256() {
const color colors [] = {
202, // orange
209, // tangerine
255, // white
205, // pink
161 // magenta
};
draw(5, colors);
}
void nonbinary_256() {
const color colors [] = {
226, // yellow
255, // white
134, // purple
16 // black
};
draw(4, colors);
}
void pansexual_256() {
const color colors [] = {
161, 161, // magenta
220, 220, // yellow
45, 45 // cyan
};
draw(6, colors);
}
void transgender_256() {
const color colors [] = {
45, // blue
213, // pink
255, // white
213, // pink
45 // blue
};
draw(5, colors);
}

13
full.h Normal file
View file

@ -0,0 +1,13 @@
#pragma once
#include "draw.h"
void rainbow_256();
void aroace_256();
void bisexual_256();
void gay_256();
void lesbian_256();
void nonbinary_256();
void pansexual_256();
void transgender_256();

View file

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

166
main.c
View file

@ -1,39 +1,15 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "draw.h"
#include "basic.h"
#include "full.h"
#define VERSION "0.0.1" #define VERSION "0.0.1"
#define INDENT " "
#define RESET "\x1b[0m" #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"
void version() { void version() {
printf("pride-c v" VERSION "\n"); printf("pride-c v" VERSION "\n");
} }
@ -47,21 +23,37 @@ void help() {
"usage: pride [name]\n\n" "usage: pride [name]\n\n"
"flag names:\n" "flag names:\n"
INDENT AROACE "\n" " aroace\n"
INDENT BISEXUAL "\n" " bisexual\n"
INDENT LESBIAN "\n" " gay\n"
INDENT NONBINARY "\n" " lesbian\n"
INDENT PANSEXUAL "\n" " nonbinary\n"
INDENT RAINBOW "\n" " pansexual\n"
INDENT TRANSGENDER "\n" " rainbow\n"
" transgender\n"
); );
} }
unsigned long djb_hash(unsigned char *string) {
unsigned long output = 5381;
int c;
while(c = *string++)
output = ((output << 5) + output) + c;
return output;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
// get argv[1] or fall back to RAINBOW // get argv[1] or fall back to RAINBOW
char *flag; char *flag;
if(argc > 1) { flag = argv[1]; } if(argc > 1) { flag = argv[1]; }
else { flag = RAINBOW; } else { flag = ""; }
int color_mode = 0;
char * colorterm = getenv("COLORTERM");
if(strcmp(colorterm, ""))
color_mode = 1;
// handle flags // handle flags
if(strcmp(flag, "--version") == 0) { if(strcmp(flag, "--version") == 0) {
@ -72,63 +64,71 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
if(strcmp(flag, RAINBOW) == 0) { // - RAINBOW - unsigned long flag_hash = djb_hash(flag);
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 - char *output;
printf(YELLOW STRIPE); switch(flag_hash) {
printf(L_YELLOW STRIPE); // - RAINBOW -
printf(WHITE STRIPE); case 229480993726103lu: // 'rainbow'
printf(L_CYAN STRIPE); case 5381lu: // (empty)
printf(BLUE STRIPE); if(color_mode) rainbow_256();
} else rainbow_8();
break;
else if(strcmp(flag, BISEXUAL) == 0) { // - BISEXUAL - // - ARO/ACE -
printf(RED STRIPE STRIPE); case 6953324567312lu: // 'aroace'
printf(MAGENTA STRIPE); case 22945708850429lu: // 'aro-ace'
printf(BLUE STRIPE STRIPE); if(color_mode) aroace_256();
} else aroace_8();
break;
else if(strcmp(flag, LESBIAN) == 0) { // - LESBIAN - // - BISEXUAL -
printf(RED STRIPE); // orange case 7572201611094690lu: // 'bisexual'
printf(L_RED STRIPE); // tangerine case 5863248lu: // 'bi'
printf(WHITE STRIPE); // white if(color_mode) bisexual_256();
printf(L_MAGENTA STRIPE); // pink else bisexual_8();
printf(MAGENTA STRIPE); // magenta break;
}
else if(strcmp(flag, NONBINARY) == 0) { // - NONBINARY - // - GAY -
printf(L_YELLOW STRIPE); // yellow case 193492486lu: // 'gay'
printf(WHITE STRIPE); // white case 193499371lu: // 'mlm'
printf(MAGENTA STRIPE); // purple if(color_mode) gay_256();
printf(BLACK STRIPE); // black else gay_8();
} break;
else if(strcmp(flag, PANSEXUAL) == 0) { // - PANSEXUAL - // - LESBIAN -
printf(MAGENTA STRIPE STRIPE); case 229473412894979lu: // 'lesbian'
printf(L_YELLOW STRIPE STRIPE); case 193510271lu: // 'wlw'
printf(CYAN STRIPE STRIPE); if(color_mode) lesbian_256();
} else lesbian_8();
break;
else if(strcmp(flag, TRANSGENDER) == 0) { // - TRANSGENDER - // - NONBINARY -
printf(L_CYAN STRIPE); case 249899779187415445lu: // 'nonbinary'
printf(L_MAGENTA STRIPE); case 5863637lu: // 'nb'
printf(WHITE STRIPE); if(color_mode) nonbinary_256();
printf(L_MAGENTA STRIPE); else nonbinary_8();
printf(L_CYAN STRIPE); break;
}
// - PANSEXUAL -
case 249901996007388822lu: // 'pansexual'
case 193502276lu: // 'pan'
if(color_mode) pansexual_256();
else pansexual_8();
break;
else { // - TRANSGENDER -
case 13895753452281080578lu: // 'transgender'
case 210729322765lu: // 'trans'
if(color_mode) transgender_256();
else transgender_8();
break;
default:
printf("pride-c: no flag '%s' found.", flag); printf("pride-c: no flag '%s' found.", flag);
return 1; return 1;
} }
printf(RESET); printf(RESET);
return 0; return 0;
} }