Compare commits

..

21 commits

Author SHA1 Message Date
2960c47176 minor cleanup and usability improvement 2024-07-09 14:00:38 -04:00
bcc61365e1 version bump 2024-07-08 13:49:02 -04:00
01573867eb covered null case for COLORTERM variable 2024-07-08 13:48:40 -04:00
3c9623040f created manual 2024-07-02 09:59:13 -04:00
8d80b1bedc version bump 2024-07-02 09:52:36 -04:00
4667091488 color mode is now decided by whether or not COLORTERM var is set 2024-07-02 09:42:57 -04:00
ec6b291135 fixed build recipe not using -s flag 2024-03-23 12:35:07 -04:00
0211e2df20 adjust lesbian flag colors 2024-03-23 11:48:09 -04:00
67a1f48f2f fixed 8-color pansexual flag invoking the wrong flag function 2024-03-23 00:35:28 -04:00
691235d9b2 Merge branch 'hash-flag' into 256-color 2024-03-23 00:31:12 -04:00
34c5be0b41 fixed missing include 2024-03-23 00:30:43 -04:00
72e08f305b removed unused file 2024-03-23 00:30:02 -04:00
4f987d69c0 merged changes from space-optimize 2024-03-23 00:28:54 -04:00
9a1473a455 fixed trans flag colors and added rudimentary color mode check 2024-03-23 00:23:42 -04:00
5e69b344f8 created draw function to reduce string section size 2024-03-22 23:52:46 -04:00
7157c681ea merged in changes from main 2024-03-22 22:28:00 -04:00
913f96d075 removed some unused definitions 2024-03-22 20:15:14 -04:00
127cbc8274 implemented djb hash matching and multiple flag name matches 2024-03-22 20:09:30 -04:00
efbb098ed9 updated README 2024-03-21 18:18:25 -04:00
d59a25a096 added gay (mlm) flag 2024-03-21 18:18:14 -04:00
da8e51f661 major project restructure; new 256-color implementation 2024-03-21 17:01:59 -04:00
10 changed files with 406 additions and 104 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.

93
basic.c Normal file
View file

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

92
full.c Normal file
View file

@ -0,0 +1,92 @@
#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 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

199
main.c
View file

@ -1,39 +1,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#define VERSION "0.0.1" #include "basic.h"
#define INDENT " " #include "full.h"
#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");
} }
@ -47,88 +22,114 @@ 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(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 = ""; }
// handle flags int color_mode = 0;
if(strcmp(flag, "--version") == 0) { char * colorterm = getenv("COLORTERM");
version(); if(colorterm != NULL && strcmp(colorterm, ""))
return 0; color_mode = 1;
} else if(strcmp(flag, "--help") == 0) {
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(); help();
return 0; break;
} case 249805560270004805lu: // --version
case 5861512lu: // -v
version();
break;
if(strcmp(flag, RAINBOW) == 0) { // - RAINBOW - default:
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;
} }

46
man/pride-c.6 Normal file
View file

@ -0,0 +1,46 @@
.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