major refactor: flag methods now return their stripe colors as vectors

This commit is contained in:
Valerie Wolfe 2023-06-19 20:08:05 -04:00
parent 31d0acd1de
commit 4f051170ac
5 changed files with 86 additions and 156 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "pride" name = "pride"
version = "0.0.2" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,8 +1,11 @@
use termion::color::{ Fg, Rgb, Reset }; use termion::color::{ Fg, Rgb, Reset };
pub static BLACK: Fg<Rgb> = Fg(Rgb(0x00, 0x00, 0x00)); pub type Color = Fg<Rgb>;
pub static WHITE: Fg<Rgb> = Fg(Rgb(0xFF, 0xFF, 0xFF)); pub type Colors = Vec<Fg<Rgb>>;
pub static BLACK: Color = Fg(Rgb(0x00, 0x00, 0x00));
pub static WHITE: Color = Fg(Rgb(0xFF, 0xFF, 0xFF));
pub static RESET: Fg<Reset> = Fg(Reset); pub static RESET: Fg<Reset> = Fg(Reset);

View file

@ -4,16 +4,15 @@ use termion::{
terminal_size, terminal_size,
clear, clear,
color::{ Fg, Rgb },
cursor, cursor,
input::TermRead, input::TermRead,
raw::IntoRawMode raw::IntoRawMode
}; };
use crate::color::RESET; use crate::color::{ RESET, Colors };
use crate::flag::BLOCK; use crate::flag::BLOCK;
pub fn draw(colors: &[Fg<Rgb>]) { pub fn full(colors: Colors) {
let mut stdout = io::stdout().into_raw_mode().unwrap(); let mut stdout = io::stdout().into_raw_mode().unwrap();
let stdin = io::stdin(); let stdin = io::stdin();
@ -45,4 +44,18 @@ pub fn draw(colors: &[Fg<Rgb>]) {
stdout.flush().ok(); stdout.flush().ok();
} }
pub fn small(colors: Colors) {
let mut stdout = io::stdout();
let count = colors.len();
let width = count * 3;
let stripe = BLOCK.repeat(width);
for color in colors {
println!("{color}{stripe}");
}
print!("{RESET}");
stdout.flush().ok();
}

View file

@ -2,11 +2,10 @@
use termion::color; use termion::color;
use crate::color::*; use crate::color::*;
use crate::draw::draw;
pub static BLOCK: &str = ""; pub static BLOCK: &str = "";
pub fn pride(small: bool) { pub fn pride() -> Colors {
let red = color::Fg(color::Rgb(0xE5, 0x00, 0x00)); let red = color::Fg(color::Rgb(0xE5, 0x00, 0x00));
let orange = color::Fg(color::Rgb(0xFF, 0x8D, 0x00)); let orange = color::Fg(color::Rgb(0xFF, 0x8D, 0x00));
let yellow = color::Fg(color::Rgb(0xFF, 0xEE, 0x00)); let yellow = color::Fg(color::Rgb(0xFF, 0xEE, 0x00));
@ -14,206 +13,108 @@ pub fn pride(small: bool) {
let blue = color::Fg(color::Rgb(0x00, 0x4C, 0xFF)); let blue = color::Fg(color::Rgb(0x00, 0x4C, 0xFF));
let purple = color::Fg(color::Rgb(0x77, 0x00, 0x88)); let purple = color::Fg(color::Rgb(0x77, 0x00, 0x88));
if small { // small flag: 18x6 vec![red, orange, yellow, green, blue, purple]
let width = 18;
println!(
"{red}{stripe}\n{orange}{stripe}\n{yellow}{stripe}\n{green}{stripe}\n{blue}{stripe}\n{purple}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[red, orange, yellow, green, blue, purple]); }
} }
pub fn transgender(small: bool) { pub fn transgender() -> Colors {
let pink = color::Fg(color::Rgb(0x7A, 0xCB, 0xF5)); let pink = color::Fg(color::Rgb(0x7A, 0xCB, 0xF5));
let blue = color::Fg(color::Rgb(0xEA, 0xAC, 0xB8)); let blue = color::Fg(color::Rgb(0xEA, 0xAC, 0xB8));
if small { vec![pink, blue, WHITE, blue, pink]
let width = 15;
println!(
"{pink}{stripe}\n{blue}{stripe}\n{WHITE}{stripe}\n{blue}{stripe}\n{pink}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[pink, blue, WHITE, blue, pink]); }
} }
// everything below here is alphabetical // everything below here is alphabetical
pub fn agender(small: bool) { pub fn agender() -> Colors {
let gray = color::Fg(color::Rgb(0xB9, 0xB9, 0xB9)); let gray = color::Fg(color::Rgb(0xB9, 0xB9, 0xB9));
let green = color::Fg(color::Rgb(0xB8, 0xF4, 0x83)); let green = color::Fg(color::Rgb(0xB8, 0xF4, 0x83));
if small { vec![BLACK, gray, WHITE, green, WHITE, gray, BLACK]
let width = 21;
println!(
"{BLACK}{stripe}\n{gray}{stripe}\n{WHITE}{stripe}\n{green}{stripe}\n{WHITE}{stripe}\n{gray}{stripe}\n{BLACK}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[BLACK, gray, WHITE, green, WHITE, gray, BLACK]); }
} }
pub fn aromantic(small: bool) { pub fn aromantic() -> Colors {
let green = color::Fg(color::Rgb(0x3B, 0xA7, 0x40)); let green = color::Fg(color::Rgb(0x3B, 0xA7, 0x40));
let lime = color::Fg(color::Rgb(0xA8, 0xD4, 0x7A)); let lime = color::Fg(color::Rgb(0xA8, 0xD4, 0x7A));
let grey = color::Fg(color::Rgb(0xAB, 0xAB, 0xAB)); let grey = color::Fg(color::Rgb(0xAB, 0xAB, 0xAB));
if small { vec![green, lime, WHITE, grey, BLACK]
let width = 15;
println!(
"{green}{stripe}\n{lime}{stripe}\n{WHITE}{stripe}\n{grey}{stripe}\n{BLACK}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[green, lime, WHITE, grey, BLACK]); }
} }
pub fn asexual(small: bool) { pub fn asexual() -> Colors {
let grey = color::Fg(color::Rgb(0xA4, 0xA4, 0xA4)); let grey = color::Fg(color::Rgb(0xA4, 0xA4, 0xA4));
let purple = color::Fg(color::Rgb(0x81, 0x00, 0x81)); let purple = color::Fg(color::Rgb(0x81, 0x00, 0x81));
if small { vec![BLACK, grey, WHITE, purple]
let width = 12;
println!(
"{BLACK}{stripe}\n{grey}{stripe}\n{WHITE}{stripe}\n{purple}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[BLACK, grey, WHITE, purple]); }
} }
pub fn bigender(small: bool) { pub fn bigender() -> Colors {
let pink = color::Fg(color::Rgb(0xE6, 0x76, 0xA6)); let pink = color::Fg(color::Rgb(0xE6, 0x76, 0xA6));
let yellow = color::Fg(color::Rgb(0xF9, 0xF0, 0x4C)); let yellow = color::Fg(color::Rgb(0xF9, 0xF0, 0x4C));
let purple = color::Fg(color::Rgb(0xAB, 0x6B, 0xBB)); let purple = color::Fg(color::Rgb(0xAB, 0x6B, 0xBB));
let blue = color::Fg(color::Rgb(0x6D, 0x96, 0xDC)); let blue = color::Fg(color::Rgb(0x6D, 0x96, 0xDC));
if small { vec![pink, yellow, WHITE, purple, blue]
let width = 15;
println!(
"{pink}{stripe}\n{yellow}{stripe}\n{WHITE}{stripe}\n{purple}{stripe}\n{blue}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[pink, yellow, WHITE, purple, blue]); }
} }
pub fn bisexual(small: bool) { pub fn bisexual() -> Colors {
let magenta = color::Fg(color::Rgb(0xC4, 0x2A, 0x6F)); let magenta = color::Fg(color::Rgb(0xC4, 0x2A, 0x6F));
let purple = color::Fg(color::Rgb(0x91, 0x53, 0x92)); let purple = color::Fg(color::Rgb(0x91, 0x53, 0x92));
let blue = color::Fg(color::Rgb(0x14, 0x37, 0xA2)); let blue = color::Fg(color::Rgb(0x14, 0x37, 0xA2));
if small { vec![magenta, magenta, purple, blue, blue]
let width = 15;
println!(
"{magenta}{stripe}\n{stripe}\n{purple}{stripe}\n{blue}{stripe}\n{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[magenta, magenta, purple, blue, blue]); }
} }
pub fn genderfluid(small: bool) { pub fn genderfluid() -> Colors {
let pink = color::Fg(color::Rgb(0xFF, 0x75, 0xA2)); let pink = color::Fg(color::Rgb(0xFF, 0x75, 0xA2));
let violet = color::Fg(color::Rgb(0xBE, 0x18, 0xD6)); let violet = color::Fg(color::Rgb(0xBE, 0x18, 0xD6));
let blue = color::Fg(color::Rgb(0x33, 0x3E, 0xBD)); let blue = color::Fg(color::Rgb(0x33, 0x3E, 0xBD));
if small { vec![pink, WHITE, violet, BLACK, blue]
let width = 15;
println!(
"{pink}{stripe}\n{WHITE}{stripe}\n{violet}{stripe}\n{BLACK}{stripe}\n{blue}{stripe}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[pink, WHITE, violet, BLACK, blue]); }
} }
pub fn genderqueer(small: bool) { pub fn genderqueer() -> Colors {
let purple = color::Fg(color::Rgb(0xB8, 0x99, 0xDF)); let purple = color::Fg(color::Rgb(0xB8, 0x99, 0xDF));
let green = color::Fg(color::Rgb(0x6B, 0x8E, 0x3B)); let green = color::Fg(color::Rgb(0x6B, 0x8E, 0x3B));
if small { vec![purple, WHITE, green]
let width = 18;
println!(
"{purple}{stripe}\n{stripe}\n{WHITE}{stripe}\n{stripe}\n{green}{stripe}\n{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[purple, WHITE, green]); }
} }
pub fn gendervoid(small: bool) { pub fn gendervoid() -> Colors {
let navy = color::Fg(color::Rgb(0x08, 0x11, 0x4A)); let navy = color::Fg(color::Rgb(0x08, 0x11, 0x4A));
let gray = color::Fg(color::Rgb(0x4A, 0x48, 0x4B)); let gray = color::Fg(color::Rgb(0x4A, 0x48, 0x4B));
if small { vec![navy, gray, BLACK, gray, navy]
let width = 15;
println!(
"{navy}{stripe}\n{gray}{stripe}\n{BLACK}{stripe}\n{gray}{stripe}\n{navy}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[navy, gray, BLACK, gray, navy]); }
} }
pub fn lesbian(small: bool) { pub fn lesbian() -> Colors {
let red = color::Fg(color::Rgb(0xD6, 0x28, 0x00)); let red = color::Fg(color::Rgb(0xD6, 0x28, 0x00));
let orange = color::Fg(color::Rgb(0xFF, 0x9B, 0x56)); let orange = color::Fg(color::Rgb(0xFF, 0x9B, 0x56));
let pink = color::Fg(color::Rgb(0xD4, 0x62, 0xA6)); let pink = color::Fg(color::Rgb(0xD4, 0x62, 0xA6));
let magenta = color::Fg(color::Rgb(0xA4, 0x00, 0x62)); let magenta = color::Fg(color::Rgb(0xA4, 0x00, 0x62));
if small { vec![red, orange, WHITE, pink, magenta]
let width = 15;
println!(
"{red}{stripe}\n{orange}{stripe}\n{WHITE}{stripe}\n{pink}{stripe}\n{magenta}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[red, orange, WHITE, pink, magenta]); }
} }
pub fn multigender(small: bool) { pub fn multigender() -> Colors {
let blue = color::Fg(color::Rgb(0x3F, 0x47, 0xCC)); let blue = color::Fg(color::Rgb(0x3F, 0x47, 0xCC));
let ltblue = color::Fg(color::Rgb(0x01, 0xA4, 0xE9)); let ltblue = color::Fg(color::Rgb(0x01, 0xA4, 0xE9));
let orange = color::Fg(color::Rgb(0xFB, 0x7F, 0x27)); let orange = color::Fg(color::Rgb(0xFB, 0x7F, 0x27));
if small { vec![blue, ltblue, orange, ltblue, blue]
let width = 15;
println!(
"{blue}{stripe}\n{ltblue}{stripe}\n{orange}{stripe}\n{ltblue}{stripe}\n{blue}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[blue, ltblue, orange, ltblue, blue]); }
} }
pub fn nonbinary(small: bool) { pub fn nonbinary() -> Colors {
let yellow = color::Fg(color::Rgb(0xFF, 0xF4, 0x33)); let yellow = color::Fg(color::Rgb(0xFF, 0xF4, 0x33));
let purple = color::Fg(color::Rgb(0x9B, 0x59, 0xD0)); let purple = color::Fg(color::Rgb(0x9B, 0x59, 0xD0));
if small { vec![yellow, WHITE, purple, BLACK]
let width = 12;
println!(
"{yellow}{stripe}\n{WHITE}{stripe}\n{purple}{stripe}\n{BLACK}{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[yellow, WHITE, purple, BLACK]); }
} }
pub fn pansexual(small: bool) { pub fn pansexual() -> Colors {
let magenta = color::Fg(color::Rgb(0xFF, 0x1B, 0x8D)); let magenta = color::Fg(color::Rgb(0xFF, 0x1B, 0x8D));
let yellow = color::Fg(color::Rgb(0xFF, 0xDA, 0x00)); let yellow = color::Fg(color::Rgb(0xFF, 0xDA, 0x00));
let cyan = color::Fg(color::Rgb(0x1B, 0xB3, 0xFF)); let cyan = color::Fg(color::Rgb(0x1B, 0xB3, 0xFF));
if small { vec![magenta, yellow, cyan]
let width = 18;
println!(
"{magenta}{stripe}\n{stripe}\n{yellow}{stripe}\n{stripe}\n{cyan}{stripe}\n{stripe}{RESET}",
stripe = BLOCK.repeat(width)
);
} else { draw(&[magenta, yellow, cyan]); }
} }

View file

@ -6,6 +6,8 @@ mod color;
mod draw; mod draw;
mod flag; mod flag;
use crate::color::Colors;
fn main() { fn main() {
let mut args = Arguments::from_env(); let mut args = Arguments::from_env();
@ -25,45 +27,56 @@ fn main() {
let subcommand = args.subcommand().unwrap(); let subcommand = args.subcommand().unwrap();
match subcommand.as_deref() { let colors: Colors = match subcommand.as_deref() {
Some("pride") | Some("pride" | "gay")
Some("gay") => flag::pride(small), => flag::pride(),
Some("trans") | Some("transgender" | "trans")
Some("transgender") => flag::transgender(small), => flag::transgender(),
Some("agender") => flag::agender(small), Some("agender")
=> flag::agender(),
Some("aro") | Some("aromantic" | "aro")
Some("aromantic") => flag::aromantic(small), => flag::aromantic(),
Some("ace") | Some("asexual" | "ace")
Some("asexual") => flag::asexual(small), => flag::asexual(),
Some("bigender") => flag::bigender(small), Some("bigender")
=> flag::bigender(),
Some("bi") | Some("bisexual" | "bi")
Some("bisexual") => flag::bisexual(small), => flag::bisexual(),
Some("genderfluid") => flag::genderfluid(small), Some("genderfluid")
=> flag::genderfluid(),
Some("genderqueer") => flag::genderqueer(small), Some("genderqueer")
=> flag::genderqueer(),
Some("gendervoid") => flag::gendervoid(small), Some("gendervoid")
=> flag::gendervoid(),
Some("lesbian") => flag::lesbian(small), Some("lesbian")
=> flag::lesbian(),
Some("multigender") => flag::multigender(small), Some("multigender")
=> flag::multigender(),
Some("nb") | Some("nonbinary" | "nb")
Some("nonbinary") => flag::nonbinary(small), => flag::nonbinary(),
Some("pan") | Some("pansexual" | "pan")
Some("pansexual") => flag::pansexual(small), => flag::pansexual(),
_ => { help_text(); exit(1) } _ => { help_text(); exit(1) }
} };
if small { draw::small(colors); }
else { draw::full(colors); }
} }
fn help_text() { fn help_text() {