Compare commits

...

7 commits

8 changed files with 267 additions and 168 deletions

View file

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

View file

@ -10,7 +10,13 @@ continue to refer to it as pre-release until I am happy with it.**
Currently supports a variety of stripe flags.
Under Construction features:
- [Variant Flags](https://git.vwolfe.io/valerie/pride/src/branch/variant)
- ["Complex" Flags](https://git.vwolfe.io/valerie/pride/src/branch/complex)
## "Complex" Flag Branch
This branch adds "complex" flags that require a little more effort to render than
iterating over an array of colors. Currently, the branch aims to add the following
flags:
- Progress: 2018 rainbow pride flag with black and brown and transgender flag chevrons
- Aro/Ace: side-by-side aromantic and asexual combination flag
- Intersex: a yellow flag with a purple circle
- Polyamorous: three-stripe flag with an isosceles triangle cut-in and a heart

103
src/complex.rs Normal file
View file

@ -0,0 +1,103 @@
use std::io::{
stdin, stdout,
Write
};
use termion::{
terminal_size,
color,
cursor,
color::{ Fg, Bg, Rgb },
raw::IntoRawMode
};
use crate::{ error, util };
use crate::flag::BLOCK;
pub static UHALF: &str = "";
//pub static LHALF: &str = "▄";
pub fn progress(small: bool) {
let red = color::Rgb(0xE5, 0x00, 0x00);
let orange = color::Rgb(0xFF, 0x8D, 0x00);
let yellow = color::Rgb(0xFF, 0xEE, 0x00);
let green = color::Rgb(0x02, 0x81, 0x21);
let blue = color::Rgb(0x00, 0x4C, 0xFF);
let purple = color::Rgb(0x77, 0x00, 0x88);
let white = color::Rgb(0xFF, 0xFF, 0xFF);
let pink = color::Rgb(0x7A, 0xCB, 0xF5);
let ltblue = color::Rgb(0xEA, 0xAC, 0xB8);
let brown = color::Rgb(0x61, 0x39, 0x15);
let black = color::Rgb(0x00, 0x00, 0x00);
}
// everything below here is alphabetical
pub fn aroace(small: bool) {
// set up colors
// shared colors
let black = color::Rgb(0x00, 0x00, 0x00);
let white = color::Rgb(0xFF, 0xFF, 0xFF);
// aro colors
let green = Fg(Rgb(0x3B, 0xA7, 0x40));
let lime = Fg(Rgb(0xA8, 0xD4, 0x7A));
let gray = Fg(Rgb(0xAB, 0xAB, 0xAB));
// ace colors
let grey = color::Rgb(0xA4, 0xA4, 0xA4);
let purple = color::Rgb(0x81, 0x00, 0x81);
// draw small
if small {
let solid = BLOCK.repeat(15);
let split = UHALF.repeat(15);
let reset = Bg(color::Reset);
for _ in 0..2 { println!("{green}{solid}{b}{solid}", b = Fg(black)); }
println!("{lime}{solid}{b}{g}{split}{reset}", b = Fg(black), g = Bg(grey));
println!("{lime}{solid}{g}{solid}", g = Fg(grey));
println!("{w}{solid}{g}{solid}", w = Fg(white), g = Fg(grey));
println!("{w}{solid}{solid}", w = Fg(white));
println!("{gray}{solid}{w}{solid}", w = Fg(white));
println!("{gray}{solid}{w}{p}{split}{reset}", w = Fg(white), p = Bg(purple));
for _ in 0..2 { println!("{b}{solid}{p}{solid}", b = Fg(black), p = Fg(purple)); }
print!("{}", termion::style::Reset);
return;
}
// draw full-size
/* the 4 and 5 stripe flags MUST line up; this means
* there have to be at least 20 steps; if we use half
* block characters, we can work this down to a minimum
* height of 10 by utilizing fg and bg.
*/
let min = 10;
let width: usize;
let height: usize;
let (twidth, theight) = terminal_size().unwrap();
if theight < min { error::too_small(Some("10 rows")); }
}
pub fn intersex(small: bool) {
let yellow = color::Rgb(0xFF, 0xDA, 0x00);
let purple = color::Rgb(0x7A, 0x00, 0xAC);
}
pub fn polyamorous(small: bool) {
let blue = color::Rgb(0x01, 0x9F, 0xE3);
let magenta = color::Rgb(0xE5, 0x00, 0x51);
let purple = color::Rgb(0x34, 0x0C, 0x46);
let white = color::Rgb(0xFF, 0xFF, 0xFF);
let yellow = color::Rgb(0x00, 0xFC, 0xBF);
}

View file

@ -10,43 +10,60 @@ use termion::{
color::{ Fg, Rgb },
cursor,
input::TermRead,
raw::IntoRawMode,
style
raw::IntoRawMode
};
use crate::flag::BLOCK;
pub fn draw(colors: &[Fg<Rgb>]) {
pub fn wait(stdin: io::Stdin) { for _ in stdin.keys() { return; } }
pub fn simple(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 (width, height) = terminal_size().unwrap();
stripes(&mut stdout, colors, (width as usize, height as usize));
wait(stdin);
write!(stdout, "{}{}", cursor::Show, clear::All).ok();
stdout.flush().ok();
}
pub fn small(colors: &[Fg<Rgb>]) {
let mut stdout = io::stdout().into_raw_mode().unwrap();
let height = colors.len();
let width = height * 3;
stripes(&mut stdout, colors, (width, height));
}
pub fn stripes(stdout: &mut io::Stdout, colors: &[Fg<Rgb>], size: (usize, usize)) {
let mut stdout = stdout.into_raw_mode().unwrap();
let count = colors.len();
let (width, height) = size;
let thresh = height / count;
let stripe = BLOCK.repeat(width);
let mut index = 0;
for n in 0..(height as usize) {
for n in 0..height {
if n!= 0 && n % thresh == 0 {
index += 1;
if index >= count { break; }
}
write!(
stdout,
"{color}{stripe}{reset}",
color = colors[index]
"{color}{stripe}\n{repos}",
color = colors[index],
repos = cursor::Left(width as u16)
).ok();
}
stdout.flush().ok();
for _ in stdin.keys() { break; }
write!(stdout, "{}{}", cursor::Show, clear::All).ok();
}
stdout.flush().ok();
}

8
src/error.rs Normal file
View file

@ -0,0 +1,8 @@
use std::process::exit;
pub fn too_small(spec: Option<&str>) {
println!("pride: terminal is too small!");
if spec.is_some() { println!("must be at least {}", spec.unwrap()); }
exit(2);
}

View file

@ -1,196 +1,129 @@
use termion::color;
use termion::color::{ Fg, Rgb };
use crate::draw::draw;
use crate::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));
let red =Fg(Rgb(0xE5, 0x00, 0x00));
let orange = Fg(Rgb(0xFF, 0x8D, 0x00));
let yellow = Fg(Rgb(0xFF, 0xEE, 0x00));
let green = Fg(Rgb(0x02, 0x81, 0x21));
let blue = Fg(Rgb(0x00, 0x4C, 0xFF));
let purple = Fg(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]); }
let stripes = &[red, orange, yellow, green, blue, purple];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
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));
let pink = Fg(Rgb(0x7A, 0xCB, 0xF5));
let blue = Fg(Rgb(0xEA, 0xAC, 0xB8));
let white = Fg(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]); }
let stripes = &[pink, blue, white, blue, pink];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
// 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));
let green = Fg(Rgb(0x3B, 0xA7, 0x40));
let lime = Fg(Rgb(0xA8, 0xD4, 0x7A));
let white = Fg(Rgb(0xFF, 0xFF, 0xFF));
let grey = Fg(Rgb(0xAB, 0xAB, 0xAB));
let black = Fg(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]); }
let stripes = &[green, lime, white, grey, black];
if small { }
else { draw::simple(stripes); }
}
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));
let black = Fg(Rgb(0x00, 0x00, 0x00));
let grey = Fg(Rgb(0xA4, 0xA4, 0xA4));
let white = Fg(Rgb(0xFF, 0xFF, 0xFF));
let purple = Fg(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]); }
let stripes = &[black, grey, white, purple];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
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));
let pink = Fg(Rgb(0xE6, 0x76, 0xA6));
let yellow = Fg(Rgb(0xF9, 0xF0, 0x4C));
let white = Fg(Rgb(0xFF, 0xFF, 0xFF));
let purple = Fg(Rgb(0xAB, 0x6B, 0xBB));
let blue = Fg(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]); }
let stripes = &[pink, yellow, white, purple, blue];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
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));
let magenta = Fg(Rgb(0xC4, 0x2A, 0x6F));
let purple = Fg(Rgb(0x91, 0x53, 0x92));
let blue = Fg(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]); }
let stripes = &[magenta, magenta, purple, blue, blue];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
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));
let navy = Fg(Rgb(0x08, 0x11, 0x4A));
let gray = Fg(Rgb(0x4A, 0x48, 0x4B));
let black = Fg(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]); }
let stripes = &[navy, gray, black, gray, navy];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
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));
let red = Fg(Rgb(0xD6, 0x28, 0x00));
let orange = Fg(Rgb(0xFF, 0x9B, 0x56));
let white = Fg(Rgb(0xFF, 0xFF, 0xFF));
let pink = Fg(Rgb(0xD4, 0x62, 0xA6));
let magenta = Fg(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]); }
let stripes = &[red, orange, white, pink, magenta];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
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));
let blue = Fg(Rgb(0x3F, 0x47, 0xCC));
let ltblue = Fg(Rgb(0x01, 0xA4, 0xE9));
let orange = Fg(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]); }
let stripes = &[blue, ltblue, orange, ltblue, blue];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
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));
let yellow = Fg(Rgb(0xFF, 0xF4, 0x33));
let white = Fg(Rgb(0xFF, 0xFF, 0xFF));
let purple = Fg(Rgb(0x9B, 0x59, 0xD0));
let black = Fg(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]); }
let stripes = &[yellow, white, purple, black];
if small { draw::small(stripes); }
else { draw::simple(stripes); }
}
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));
let magenta = Fg(Rgb(0xFF, 0x1B, 0x8D));
let yellow = Fg(Rgb(0xFF, 0xDA, 0x00));
let cyan = Fg(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]); }
if small { draw::small(&[magenta, magenta, yellow, yellow, cyan, cyan]); }
else { draw::simple(&[magenta, yellow, cyan]); }
}

View file

@ -2,8 +2,11 @@ use std::process::exit;
use pico_args::Arguments;
mod complex;
mod draw;
mod error;
mod flag;
mod util;
fn main() {
let mut args = Arguments::from_env();
@ -25,6 +28,8 @@ fn main() {
let subcommand = args.subcommand().unwrap();
match subcommand.as_deref() {
Some("progress") => complex::progress(small),
Some("pride") |
Some("gay") => flag::pride(small),
@ -32,6 +37,8 @@ fn main() {
Some("transgender") => flag::transgender(small),
Some("aroace") => complex::aroace(small),
Some("aro") |
Some("aromantic") => flag::aromantic(small),
@ -45,6 +52,8 @@ fn main() {
Some("gendervoid") => flag::gendervoid(small),
Some("intersex") => complex::intersex(small),
Some("lesbian") => flag::lesbian(small),
Some("multigender") => flag::multigender(small),
@ -55,6 +64,11 @@ fn main() {
Some("pan") |
Some("pansexual") => flag::pansexual(small),
Some("poly") |
Some("polyam") |
Some("polyamory") |
Some("polyamorous") => complex::polyamorous(small),
_ => { help_text(); exit(1) }
}
}
@ -81,17 +95,20 @@ fn help_text() {
fn list_text() {
println!("pride v{}", env!("CARGO_PKG_VERSION"));
println!("\nFlag list:");
println!(" aroace aromantic asexual pride flag");
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!(" intersex intersex 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!(" poly, polyamory polyamorous pride flag");
println!(" progress progress arrow flag");
println!(" trans, transgender transgender pride flag");
}

15
src/util.rs Normal file
View file

@ -0,0 +1,15 @@
pub fn gcd(a: usize, b: usize) -> usize {
if a == 0 || b == 0 { return 0; }
let min = usize::min(a, b);
let max = usize::max(a, b);
let remainder = max % min;
if remainder == 0 { return min; }
else { return gcd(min, remainder); }
}
pub fn lcm(a: usize, b: usize) -> usize {
return ( a * b ) / gcd(a, b);
}