initial commit

This commit is contained in:
Valerie Wolfe 2023-04-13 15:04:05 -04:00
commit 5e56206086
5 changed files with 363 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
Cargo.lock
/target

16
Cargo.toml Normal file
View file

@ -0,0 +1,16 @@
[package]
name = "pride"
version = "0.0.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pico-args = "0.5.0"
termion = "2.0.1"
[profile.release]
opt-level = 'z'
lto = true
codegen-units = 1

52
src/draw.rs Normal file
View file

@ -0,0 +1,52 @@
use std::{
io,
io::Write
};
use termion::{
terminal_size,
clear,
color::{ Fg, Rgb },
cursor,
input::TermRead,
raw::IntoRawMode,
style
};
use crate::flag::BLOCK;
pub fn draw(colors: &[Fg<Rgb>]) {
let mut stdout = io::stdout().into_raw_mode().unwrap();
let stdin = io::stdin();
let count = colors.len();
let (width, height) = terminal_size().unwrap();
let thresh = height as usize / count;
write!(stdout, "{}{}", cursor::Hide, clear::All).ok();
stdout.flush().ok();
let stripe = BLOCK.repeat(width as usize);
let reset = style::Reset;
let mut index = 0;
for n in 0..(height as usize) {
if n != 0 && n % thresh == 0 {
index += 1;
if index >= count { break; }
}
write!(
stdout,
"{color}{stripe}{reset}",
color = colors[index]
).ok();
}
stdout.flush().ok();
for _ in stdin.keys() { break; }
write!(stdout, "{}{}", cursor::Show, clear::All).ok();
stdout.flush().ok();
}

196
src/flag.rs Normal file
View file

@ -0,0 +1,196 @@
use termion::color;
use crate::draw::draw;
pub static BLOCK: &str = "";
pub fn pride(small: bool) {
let red = color::Fg(color::Rgb(0xE5, 0x00, 0x00));
let orange = color::Fg(color::Rgb(0xFF, 0x8D, 0x00));
let yellow = color::Fg(color::Rgb(0xFF, 0xEE, 0x00));
let green = color::Fg(color::Rgb(0x02, 0x81, 0x21));
let blue = color::Fg(color::Rgb(0x00, 0x4C, 0xFF));
let purple = color::Fg(color::Rgb(0x77, 0x00, 0x88));
if small { // small flag: 18x6
let width = 18;
println!(
"{red}{stripe}\n{orange}{stripe}\n{yellow}{stripe}\n{green}{stripe}\n{blue}{stripe}\n{purple}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[red, orange, yellow, green, blue, purple]); }
}
pub fn transgender(small: bool) {
let pink = color::Fg(color::Rgb(0x7A, 0xCB, 0xF5));
let blue = color::Fg(color::Rgb(0xEA, 0xAC, 0xB8));
let white = color::Fg(color::Rgb(0xFF, 0xFF, 0xFF));
if small {
let width = 15;
println!(
"{pink}{stripe}\n{blue}{stripe}\n{white}{stripe}\n{blue}{stripe}\n{pink}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[pink, blue, white, blue, pink]); }
}
// everything below here is alphabetical
pub fn aromantic(small: bool) {
let green = color::Fg(color::Rgb(0x3B, 0xA7, 0x40));
let lime = color::Fg(color::Rgb(0xA8, 0xD4, 0x7A));
let white = color::Fg(color::Rgb(0xFF, 0xFF, 0xFF));
let grey = color::Fg(color::Rgb(0xAB, 0xAB, 0xAB));
let black = color::Fg(color::Rgb(0x00, 0x00, 0x00));
if small {
let width = 15;
println!(
"{green}{stripe}\n{lime}{stripe}\n{white}{stripe}\n{grey}{stripe}\n{black}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[green, lime, white, grey, black]); }
}
pub fn asexual(small: bool) {
let black = color::Fg(color::Rgb(0x00, 0x00, 0x00));
let grey = color::Fg(color::Rgb(0xA4, 0xA4, 0xA4));
let white = color::Fg(color::Rgb(0xFF, 0xFF, 0xFF));
let purple = color::Fg(color::Rgb(0x81, 0x00, 0x81));
if small {
let width = 12;
println!(
"{black}{stripe}\n{grey}{stripe}\n{white}{stripe}\n{purple}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[black, grey, white, purple]); }
}
pub fn bigender(small: bool) {
let pink = color::Fg(color::Rgb(0xE6, 0x76, 0xA6));
let yellow = color::Fg(color::Rgb(0xF9, 0xF0, 0x4C));
let white = color::Fg(color::Rgb(0xFF, 0xFF, 0xFF));
let purple = color::Fg(color::Rgb(0xAB, 0x6B, 0xBB));
let blue = color::Fg(color::Rgb(0x6D, 0x96, 0xDC));
if small {
let width = 15;
println!(
"{pink}{stripe}\n{yellow}{stripe}\n{white}{stripe}\n{purple}{stripe}\n{blue}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[pink, yellow, white, purple, blue]); }
}
pub fn bisexual(small: bool) {
let magenta = color::Fg(color::Rgb(0xC4, 0x2A, 0x6F));
let purple = color::Fg(color::Rgb(0x91, 0x53, 0x92));
let blue = color::Fg(color::Rgb(0x14, 0x37, 0xA2));
if small {
let width = 15;
println!(
"{magenta}{stripe}\n{stripe}\n{purple}{stripe}\n{blue}{stripe}\n{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[magenta, magenta, purple, blue, blue]); }
}
pub fn gendervoid(small: bool) {
let navy = color::Fg(color::Rgb(0x08, 0x11, 0x4A));
let gray = color::Fg(color::Rgb(0x4A, 0x48, 0x4B));
let black = color::Fg(color::Rgb(0x00, 0x00, 0x00));
if small {
let width = 15;
println!(
"{navy}{stripe}\n{gray}{stripe}\n{black}{stripe}\n{gray}{stripe}\n{navy}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[navy, gray, black, gray, navy]); }
}
pub fn lesbian(small: bool) {
let red = color::Fg(color::Rgb(0xD6, 0x28, 0x00));
let orange = color::Fg(color::Rgb(0xFF, 0x9B, 0x56));
let white = color::Fg(color::Rgb(0xFF, 0xFF, 0xFF));
let pink = color::Fg(color::Rgb(0xD4, 0x62, 0xA6));
let magenta = color::Fg(color::Rgb(0xA4, 0x00, 0x62));
if small {
let width = 15;
println!(
"{red}{stripe}\n{orange}{stripe}\n{white}{stripe}\n{pink}{stripe}\n{magenta}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[red, orange, white, pink, magenta]); }
}
pub fn multigender(small: bool) {
let blue = color::Fg(color::Rgb(0x3F, 0x47, 0xCC));
let ltblue = color::Fg(color::Rgb(0x01, 0xA4, 0xE9));
let orange = color::Fg(color::Rgb(0xFB, 0x7F, 0x27));
if small {
let width = 15;
println!(
"{blue}{stripe}\n{ltblue}{stripe}\n{orange}{stripe}\n{ltblue}{stripe}\n{blue}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[blue, ltblue, orange, ltblue, blue]); }
}
pub fn nonbinary(small: bool) {
let yellow = color::Fg(color::Rgb(0xFF, 0xF4, 0x33));
let white = color::Fg(color::Rgb(0xFF, 0xFF, 0xFF));
let purple = color::Fg(color::Rgb(0x9B, 0x59, 0xD0));
let black = color::Fg(color::Rgb(0x00, 0x00, 0x00));
if small {
let width = 12;
println!(
"{yellow}{stripe}\n{white}{stripe}\n{purple}{stripe}\n{black}{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[yellow, white, purple, black]); }
}
pub fn pansexual(small: bool) {
let magenta = color::Fg(color::Rgb(0xFF, 0x1B, 0x8D));
let yellow = color::Fg(color::Rgb(0xFF, 0xDA, 0x00));
let cyan = color::Fg(color::Rgb(0x1B, 0xB3, 0xFF));
if small {
let width = 18;
println!(
"{magenta}{stripe}\n{stripe}\n{yellow}{stripe}\n{stripe}\n{cyan}{stripe}\n{stripe}{reset}",
reset = color::Fg(color::Reset),
stripe = BLOCK.repeat(width)
);
} else { draw(&[magenta, yellow, cyan]); }
}

97
src/main.rs Normal file
View file

@ -0,0 +1,97 @@
use std::process::exit;
use pico_args::Arguments;
mod draw;
mod flag;
fn main() {
let mut args = Arguments::from_env();
let help = args.contains(["-h", "--help"]);
if help {
help_text();
return;
}
let list = args.contains(["-l", "--list"]);
if list {
list_text();
return;
}
let small = args.contains(["-s", "--small"]);
let subcommand = args.subcommand().unwrap();
match subcommand.as_deref() {
Some("pride") |
Some("gay") => flag::pride(small),
Some("trans") |
Some("transgender") => flag::transgender(small),
Some("aro") |
Some("aromantic") => flag::aromantic(small),
Some("ace") |
Some("asexual") => flag::asexual(small),
Some("bigender") => flag::bigender(small),
Some("bi") |
Some("bisexual") => flag::bisexual(small),
Some("gendervoid") => flag::gendervoid(small),
Some("lesbian") => flag::lesbian(small),
Some("multigender") => flag::multigender(small),
Some("nb") |
Some("nonbinary") => flag::nonbinary(small),
Some("pan") |
Some("pansexual") => flag::pansexual(small),
_ => { help_text(); exit(1) }
}
}
fn help_text() {
println!("pride v{}", env!("CARGO_PKG_VERSION"));
println!("Valerie Wolfe <sleeplessval@gmail.com>");
println!("Show pride flags in the terminal.\n");
println!("usage: pride [flags] <name>\n");
println!("args:");
println!(" <name> The pride flag to display\n");
println!("flags:");
println!(" -h, --help Shows this help text");
println!(" -l, --list Prints a list of printable flags");
println!(" -s, --small Prints a small version without holding");
println!("\nUse 'pride --list' to see a list of printable flags");
println!("\n~ You're loved and you matter ♥");
}
fn list_text() {
println!("pride v{}", env!("CARGO_PKG_VERSION"));
println!("\nFlag list:");
println!(" aro, aromantic aromantic pride flag");
println!(" ace, asexual asexual pride flag");
println!(" bigender bigender pride flag");
println!(" bi, bisexual bisexual pride flag");
println!(" gay, pride six-color rainbow flag");
println!(" gendervoid gendervoid pride flag");
println!(" lesbian lesbian pride flag");
println!(" multigender multigender pride flag");
println!(" nb, nonbinary nonbinary pride flag");
println!(" pan, pansexual pansexual pride flag");
// println!(" progress progress arrow flag");
println!(" trans, transgender transgender pride flag");
}