Compare commits

..

No commits in common. "4667091488da81807b39649fd55c5e45d0c99301" and "735d8394fd809f3e997276bb70a4f99876a5bcd5" have entirely different histories.

9 changed files with 94 additions and 353 deletions

View file

@ -1,14 +1,5 @@
# Pride! for the tty # Pride! for the tty
A utility to display pride flags in 8- or 256- color terminals. A C utility to display flags in 8-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
View file

@ -1,95 +0,0 @@
#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
View file

@ -1,28 +0,0 @@
#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
View file

@ -1,10 +0,0 @@
#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
View file

@ -1,10 +0,0 @@
#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
View file

@ -1,94 +0,0 @@
#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
View file

@ -1,13 +0,0 @@
#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 -s main.c draw.c basic.c full.c -o pride-c gcc main.c basic.c full.c -o pride-c

166
main.c
View file

@ -1,15 +1,39 @@
#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");
} }
@ -23,37 +47,21 @@ void help() {
"usage: pride [name]\n\n" "usage: pride [name]\n\n"
"flag names:\n" "flag names:\n"
" aroace\n" INDENT AROACE "\n"
" bisexual\n" INDENT BISEXUAL "\n"
" gay\n" INDENT LESBIAN "\n"
" lesbian\n" INDENT NONBINARY "\n"
" nonbinary\n" INDENT PANSEXUAL "\n"
" pansexual\n" INDENT RAINBOW "\n"
" rainbow\n" INDENT TRANSGENDER "\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 = ""; } else { flag = RAINBOW; }
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) {
@ -64,71 +72,63 @@ int main(int argc, char **argv) {
return 0; return 0;
} }
unsigned long flag_hash = djb_hash(flag); 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);
}
char *output; else if(strcmp(flag, AROACE) == 0) { // - ARO/ACE -
switch(flag_hash) { printf(YELLOW STRIPE);
// - RAINBOW - printf(L_YELLOW STRIPE);
case 229480993726103lu: // 'rainbow' printf(WHITE STRIPE);
case 5381lu: // (empty) printf(L_CYAN STRIPE);
if(color_mode) rainbow_256(); printf(BLUE STRIPE);
else rainbow_8(); }
break;
// - ARO/ACE - else if(strcmp(flag, BISEXUAL) == 0) { // - BISEXUAL -
case 6953324567312lu: // 'aroace' printf(RED STRIPE STRIPE);
case 22945708850429lu: // 'aro-ace' printf(MAGENTA STRIPE);
if(color_mode) aroace_256(); printf(BLUE STRIPE STRIPE);
else aroace_8(); }
break;
// - BISEXUAL - else if(strcmp(flag, LESBIAN) == 0) { // - LESBIAN -
case 7572201611094690lu: // 'bisexual' printf(RED STRIPE); // orange
case 5863248lu: // 'bi' printf(L_RED STRIPE); // tangerine
if(color_mode) bisexual_256(); printf(WHITE STRIPE); // white
else bisexual_8(); printf(L_MAGENTA STRIPE); // pink
break; printf(MAGENTA STRIPE); // magenta
}
// - GAY - else if(strcmp(flag, NONBINARY) == 0) { // - NONBINARY -
case 193492486lu: // 'gay' printf(L_YELLOW STRIPE); // yellow
case 193499371lu: // 'mlm' printf(WHITE STRIPE); // white
if(color_mode) gay_256(); printf(MAGENTA STRIPE); // purple
else gay_8(); printf(BLACK STRIPE); // black
break; }
// - LESBIAN - else if(strcmp(flag, PANSEXUAL) == 0) { // - PANSEXUAL -
case 229473412894979lu: // 'lesbian' printf(MAGENTA STRIPE STRIPE);
case 193510271lu: // 'wlw' printf(L_YELLOW STRIPE STRIPE);
if(color_mode) lesbian_256(); printf(CYAN STRIPE STRIPE);
else lesbian_8(); }
break;
// - NONBINARY - else if(strcmp(flag, TRANSGENDER) == 0) { // - TRANSGENDER -
case 249899779187415445lu: // 'nonbinary' printf(L_CYAN STRIPE);
case 5863637lu: // 'nb' printf(L_MAGENTA STRIPE);
if(color_mode) nonbinary_256(); printf(WHITE STRIPE);
else nonbinary_8(); printf(L_MAGENTA STRIPE);
break; printf(L_CYAN STRIPE);
}
// - PANSEXUAL -
case 249901996007388822lu: // 'pansexual'
case 193502276lu: // 'pan'
if(color_mode) pansexual_256();
else pansexual_8();
break;
// - TRANSGENDER - else {
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;
} }