Compare commits
No commits in common. "47d63cd7f53d057b7510e3cb12a820a4ea7ae3c1" and "dd7adca3d0253e8b02a6ff042b0091fae71844be" have entirely different histories.
47d63cd7f5
...
dd7adca3d0
5 changed files with 3 additions and 29 deletions
|
@ -9,9 +9,7 @@ pub static WHITE: Color = Fg(Rgb(0xFF, 0xFF, 0xFF));
|
||||||
|
|
||||||
pub static RESET: Fg<Reset> = Fg(Reset);
|
pub static RESET: Fg<Reset> = Fg(Reset);
|
||||||
|
|
||||||
/// converts a hex integer to Fg(Rgb)
|
|
||||||
pub fn rgb(hex: u32) -> Color {
|
pub fn rgb(hex: u32) -> Color {
|
||||||
// colors should be 0xrrggbb = 0x__rrggbb; drop the most significant byte
|
|
||||||
let [_, r, g, b] = hex.to_be_bytes();
|
let [_, r, g, b] = hex.to_be_bytes();
|
||||||
|
|
||||||
Fg(Rgb(r, g, b))
|
Fg(Rgb(r, g, b))
|
||||||
|
|
18
src/draw.rs
18
src/draw.rs
|
@ -12,67 +12,49 @@ use termion::{
|
||||||
use crate::color::{ RESET, Colors };
|
use crate::color::{ RESET, Colors };
|
||||||
use crate::flag::BLOCK;
|
use crate::flag::BLOCK;
|
||||||
|
|
||||||
/// draw a fullscreen stripe flag and hold for keypress
|
|
||||||
pub fn full(colors: Colors) {
|
pub fn full(colors: Colors) {
|
||||||
// prepare stdin and stdout
|
|
||||||
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();
|
||||||
|
|
||||||
// get constraints
|
|
||||||
let count = colors.len();
|
let count = colors.len();
|
||||||
let (width, height) = terminal_size().unwrap();
|
let (width, height) = terminal_size().unwrap();
|
||||||
let thresh = height as usize / count;
|
let thresh = height as usize / count;
|
||||||
|
|
||||||
// clear the terminal
|
|
||||||
write!(stdout, "{}{}", cursor::Hide, clear::All).ok();
|
write!(stdout, "{}{}", cursor::Hide, clear::All).ok();
|
||||||
stdout.flush().ok();
|
stdout.flush().ok();
|
||||||
|
|
||||||
// build terminal width stripe string
|
|
||||||
let stripe = BLOCK.repeat(width as usize);
|
let stripe = BLOCK.repeat(width as usize);
|
||||||
|
|
||||||
// create our color index
|
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
// for every terminal row...
|
|
||||||
for n in 0..(height as usize) {
|
for n in 0..(height as usize) {
|
||||||
// ... increment our index at color change threshold
|
|
||||||
if n != 0 && n % thresh == 0 {
|
if n != 0 && n % thresh == 0 {
|
||||||
index += 1;
|
index += 1;
|
||||||
// and break if out of bounds
|
|
||||||
if index >= count { break; }
|
if index >= count { break; }
|
||||||
}
|
}
|
||||||
// ... draw the stripe with color at index
|
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout,
|
||||||
"{color}{stripe}{RESET}",
|
"{color}{stripe}{RESET}",
|
||||||
color = colors[index]
|
color = colors[index]
|
||||||
).ok();
|
).ok();
|
||||||
}
|
}
|
||||||
// flush stdout
|
|
||||||
stdout.flush().ok();
|
stdout.flush().ok();
|
||||||
|
|
||||||
// wait for keypress
|
|
||||||
for _ in stdin.keys() { break; }
|
for _ in stdin.keys() { break; }
|
||||||
write!(stdout, "{}{}", cursor::Show, clear::All).ok();
|
write!(stdout, "{}{}", cursor::Show, clear::All).ok();
|
||||||
stdout.flush().ok();
|
stdout.flush().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// draws a small stripe flag
|
|
||||||
pub fn small(colors: Colors) {
|
pub fn small(colors: Colors) {
|
||||||
// prepare stdout
|
|
||||||
let mut stdout = io::stdout();
|
let mut stdout = io::stdout();
|
||||||
|
|
||||||
// get constraints
|
|
||||||
let count = colors.len();
|
let count = colors.len();
|
||||||
let width = count * 3;
|
let width = count * 3;
|
||||||
|
|
||||||
// build small stripe string
|
|
||||||
let stripe = BLOCK.repeat(width);
|
let stripe = BLOCK.repeat(width);
|
||||||
|
|
||||||
// print a stripe for all colors
|
|
||||||
for color in colors {
|
for color in colors {
|
||||||
println!("{color}{stripe}");
|
println!("{color}{stripe}");
|
||||||
}
|
}
|
||||||
// reset our foreground color to play nice and flush stdout
|
|
||||||
print!("{RESET}");
|
print!("{RESET}");
|
||||||
stdout.flush().ok();
|
stdout.flush().ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
//! stripe pride flag color functions.
|
|
||||||
//! all of these return a Vec of colors to be drawn from first to last.
|
|
||||||
|
|
||||||
use crate::color::*;
|
use crate::color::*;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ use crate::color::Colors;
|
||||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// collect args
|
|
||||||
let mut args = Arguments::from_env();
|
let mut args = Arguments::from_env();
|
||||||
|
|
||||||
// handle help flag
|
// handle help flag
|
||||||
|
@ -38,9 +37,8 @@ fn main() {
|
||||||
|
|
||||||
let subcommand = args.subcommand().unwrap();
|
let subcommand = args.subcommand().unwrap();
|
||||||
|
|
||||||
// get color vec from matched flag
|
|
||||||
let colors: Colors = match subcommand.as_deref() {
|
let colors: Colors = match subcommand.as_deref() {
|
||||||
Some("pride" | "rainbow")
|
Some("pride")
|
||||||
| None
|
| None
|
||||||
=> {
|
=> {
|
||||||
let variant = args.subcommand().unwrap_or(None);
|
let variant = args.subcommand().unwrap_or(None);
|
||||||
|
@ -97,7 +95,7 @@ fn main() {
|
||||||
Some("pansexual" | "pan")
|
Some("pansexual" | "pan")
|
||||||
=> flag::pansexual(),
|
=> flag::pansexual(),
|
||||||
|
|
||||||
_ => { help_text(); exit(1) } // (or die)
|
_ => { help_text(); exit(1) }
|
||||||
};
|
};
|
||||||
|
|
||||||
if small { draw::small(colors); }
|
if small { draw::small(colors); }
|
||||||
|
@ -141,7 +139,7 @@ fn list_text() {
|
||||||
println!(" multigender multigender pride flag");
|
println!(" multigender multigender pride flag");
|
||||||
println!(" nb, nonbinary nonbinary pride flag");
|
println!(" nb, nonbinary nonbinary pride flag");
|
||||||
println!(" pan, pansexual pansexual pride flag");
|
println!(" pan, pansexual pansexual pride flag");
|
||||||
println!(" pride, rainbow six-color rainbow flag");
|
println!(" pride six-color rainbow flag");
|
||||||
// println!(" progress progress arrow flag");
|
// println!(" progress progress arrow flag");
|
||||||
println!(" trans, transgender transgender pride flag");
|
println!(" trans, transgender transgender pride flag");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
//! variant pride flags
|
|
||||||
//! these aren't in the flag module for organizational reasons.
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
color::*,
|
color::*,
|
||||||
|
|
Loading…
Reference in a new issue