Compare commits

..

No commits in common. "main" and "minimal" have entirely different histories.

10 changed files with 104 additions and 406 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.

93
basic.c
View file

@ -1,93 +0,0 @@
#include "basic.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[]);

92
full.c
View file

@ -1,92 +0,0 @@
#include "full.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

199
main.c
View file

@ -1,14 +1,39 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "basic.h" #define VERSION "0.0.1"
#include "full.h" #define INDENT " "
#define VERSION "0.0.4"
#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");
} }
@ -22,114 +47,88 @@ 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(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; // handle flags
char * colorterm = getenv("COLORTERM"); if(strcmp(flag, "--version") == 0) {
if(colorterm != NULL && strcmp(colorterm, ""))
color_mode = 1;
unsigned long flag_hash = djb_hash(flag);
char *output;
switch(flag_hash) {
// - RAINBOW -
case 229480993726103lu: // 'rainbow'
case 5381lu: // (empty)
if(color_mode) rainbow_256();
else rainbow_8();
break;
// - ARO/ACE -
case 6953324567312lu: // 'aroace'
case 22945708850429lu: // 'aro-ace'
if(color_mode) aroace_256();
else aroace_8();
break;
// - BISEXUAL -
case 7572201611094690lu: // 'bisexual'
case 5863248lu: // 'bi'
if(color_mode) bisexual_256();
else bisexual_8();
break;
// - GAY -
case 193492486lu: // 'gay'
case 193499371lu: // 'mlm'
if(color_mode) gay_256();
else gay_8();
break;
// - LESBIAN -
case 229473412894979lu: // 'lesbian'
case 193510271lu: // 'wlw'
if(color_mode) lesbian_256();
else lesbian_8();
break;
// - NONBINARY -
case 249899779187415445lu: // 'nonbinary'
case 5863637lu: // 'nb'
if(color_mode) nonbinary_256();
else nonbinary_8();
break;
// - PANSEXUAL -
case 249901996007388822lu: // 'pansexual'
case 193502276lu: // 'pan'
if(color_mode) pansexual_256();
else pansexual_8();
break;
// - TRANSGENDER -
case 13895753452281080578lu: // 'transgender'
case 210729322765lu: // 'trans'
if(color_mode) transgender_256();
else transgender_8();
break;
// handle flags, but in the command-line sense
case 6951207451432lu: // --help
case 5861498lu: // -h
help();
break;
case 249805560270004805lu: // --version
case 5861512lu: // -v
version(); version();
break; return 0;
} else if(strcmp(flag, "--help") == 0) {
help();
return 0;
}
default: 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); printf("pride-c: no flag '%s' found.", flag);
return 1; return 1;
} }
printf(RESET); printf(RESET);
return 0; return 0;
} }

View file

@ -1,46 +0,0 @@
.Dd $Mdocdate$
.Dt PRIDE-C 6
.Os
.Sh NAME
.Nm pride-c
.Nd shows pride flags in the terminal using ANSI color sequences.
.Sh SYNOPSIS
.Nm
.Op Ar flag
.Nm
.Op Fl -help | Fl -version
.Sh DESCRIPTION
.Nm
displays pride flags for reduced color terminals. Outputs 8- or 256-color flags depending on if
.Ev COLORTERM
is set. If no
.Ar flag
is provided,
.Nm
defaults to 'rainbow'. The following flags are implemented:
.Pp
.Bl -tag -compact
.It aroace, aro-ace
.It bisexual, bi
.It gay, mlm
.It lesbian, wlw
.It nonbinary, nb
.It pansexual, pan
.It transgender, trans
.El
.Sh ENVIRONMENT
.Bl -tag -width Ds
.It COLORTERM
Should be set by your terminal if it supports colors. If set,
.Nm
will use 256-color mode.
.Sh SEE ALSO
.Xr pride 6
.Sh HISTORY
.Nm
is a C port of
.Xr pride 6
made for reduced color terminals and embedded systems.
.Sh AUTHORS
.An -nosplit
.An Valerie Wolfe Aq Mt sleeplessval@gmail.com