From f8e02e06fb8a5c059ea2eccd0fad9a6c2c3146d5 Mon Sep 17 00:00:00 2001 From: Valerie Date: Thu, 22 Jun 2023 20:20:45 -0400 Subject: [PATCH 01/10] groundwork for complex flags --- src/complex.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/draw.rs | 4 +++- src/flag.rs | 2 -- src/main.rs | 24 ++++++++++++++++++- 4 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 src/complex.rs diff --git a/src/complex.rs b/src/complex.rs new file mode 100644 index 0000000..9a8cfc2 --- /dev/null +++ b/src/complex.rs @@ -0,0 +1,63 @@ +use std::process::exit; + +use crate::color::*; +use crate::draw; +use crate::flag; +use crate::variant; + +pub fn progress() { + let philadelphia = variant::philadelphia(); + let trans = flag::transgender(); + + +} + +// everything below this point is in alphabetical order + +pub fn aroace() { + let aro = flag::aromantic(); + let ace = flag::asexual(); + +} + +pub fn demiromantic() { + let green = rgb(0x3DA542); + let gray = rgb(0xD2D2D2); + + // WHITE×2 / green / gray×2 vert + // BLACK triangle cutin +} + +pub fn demisexual() { + let purple = rgb(0x832FA8); + let grey = rgb(0x7B868C); + + // WHITE×2 / green / grey×2 vert + // BLACK triangle cutin +} + +pub fn intersex() -> Colors { + let yellow = rgb(0xFFDA00); + let purple = rgb(0x7A00AC); + + let stripe = draw::BLOCK.repeat(9); + let part = draw::BLOCK.repeat(4); + + println!( + "{yellow}{stripe}\n{part}{purple}{}O{}{yellow}{part}\n{stripe}{RESET}", + yellow.0.bg_string(), + RESET.0.bg_str() + ); + exit(0); +} + +pub fn polyamorous() { + let blue = rgb(0x019FE3); + let magenta = rgb(0xE50051); + let purple = rgb(0x340C46); + let yellow = rgb(0x00FCBF); + + // blue / magenta / purple vert + // WHITE isosceles cutin with yellow heart pointed right +} + diff --git a/src/draw.rs b/src/draw.rs index c60a747..5f24472 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -10,7 +10,9 @@ use termion::{ }; use crate::color::{ RESET, Colors }; -use crate::flag::BLOCK; + +pub static BLOCK: &str = "█"; +pub static UHALF: &str = "▀"; pub fn full(colors: Colors) { let mut stdout = io::stdout().into_raw_mode().unwrap(); diff --git a/src/flag.rs b/src/flag.rs index 2da1984..943ee83 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -1,8 +1,6 @@ use crate::color::*; -pub static BLOCK: &str = "█"; - pub fn pride() -> Colors { let red = rgb(0xE50000); let orange = rgb(0xFF8D00); diff --git a/src/main.rs b/src/main.rs index 439b0ad..d9de377 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::process::exit; use pico_args::Arguments; mod color; +mod complex; mod draw; mod flag; mod variant; @@ -46,6 +47,8 @@ fn main() { => variant::gilbert_baker(), Some("philadelphia") => variant::philadelphia(), +// Some("progress") +// => complex::progress(), _ => flag::pride() } @@ -64,12 +67,21 @@ fn main() { Some("asexual" | "ace") => flag::asexual(), +// Some("aroace" | "aromantic-asexual") +// => complex::aroace(), + Some("bigender") => flag::bigender(), Some("bisexual" | "bi") => flag::bisexual(), +// Some("demiromantic") +// => flag::demiromantic(), + +// Some("demisexual") +// => flag::demisexual(), + Some("genderfluid") => flag::genderfluid(), @@ -79,6 +91,9 @@ fn main() { Some("gendervoid") => flag::gendervoid(), + Some("intersex") + => complex::intersex(), + Some("lesbian") => flag::lesbian(), @@ -91,6 +106,9 @@ fn main() { Some("pansexual" | "pan") => flag::pansexual(), +// Some("poly" | "polyamorous" | "polyamory") +// => complex::polyamorous(), + _ => { help_text(); exit(1) } }; @@ -125,17 +143,21 @@ fn list_text() { println!(" agender agender pride flag"); println!(" aro, aromantic aromantic pride flag"); println!(" ace, asexual asexual pride flag"); +// println!(" aroace aromantic/asexual pride flag"); println!(" bigender bigender pride flag"); println!(" bi, bisexual bisexual pride flag"); +// println!(" demiromantic demiromantic pride flag"); +// println!(" demisexual demisexual pride flag"); println!(" gay, pride six-color rainbow flag"); println!(" genderfluid genderfluid pride flag"); println!(" genderqueer genderqueer pride 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, polyamorous polyamorous pride flag"); println!(" trans, transgender transgender pride flag"); } From 1332a306bc436725858e244c13b9486a9842f0aa Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 3 Jul 2023 11:14:44 -0400 Subject: [PATCH 02/10] updated README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b3ab496..9917b4f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ to make major changes and refactors until the main roadmap is complete.** Currently supports a variety of stripe flags. Under Construction features: -- ["Complex" Flags](https://git.vwolfe.io/valerie/pride/src/branch/complex) +- [Complex Drawing](https://git.vwolfe.io/valerie/pride/src/branch/complex) ## Libraries From 07ee54024d9f2007070bd85372293b6750bdf8d8 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 3 Jul 2023 13:11:45 -0400 Subject: [PATCH 03/10] shifted complex rendering architecture, created by-line draw method --- src/color.rs | 11 ++++++++- src/complex.rs | 62 ++++++++++++++++++++++++++++++++++++++++---------- src/draw.rs | 28 ++++++++++++++++++++++- src/main.rs | 8 +++++-- 4 files changed, 93 insertions(+), 16 deletions(-) diff --git a/src/color.rs b/src/color.rs index 5a3a0b5..d2cadd1 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,5 +1,5 @@ -use termion::color::{ Fg, Rgb, Reset }; +use termion::color::{ Bg, Fg, Rgb, Reset }; pub type Color = Fg; pub type Colors = Vec>; @@ -8,10 +8,19 @@ pub static BLACK: Color = Fg(Rgb(0x00, 0x00, 0x00)); pub static WHITE: Color = Fg(Rgb(0xFF, 0xFF, 0xFF)); pub static RESET: Fg = Fg(Reset); +pub static RESET_BG: Bg = Bg(Reset); +/// produces a termion foreground color from the provided integer pub fn rgb(hex: u32) -> Color { let [_, r, g, b] = hex.to_be_bytes(); Fg(Rgb(r, g, b)) } +/// produces a termion background color from the provided integer +pub fn bg(hex: u32) -> Bg { + let [_, r, g, b] = hex.to_be_bytes(); + + Bg(Rgb(r, g, b)) +} + diff --git a/src/complex.rs b/src/complex.rs index 9a8cfc2..961a959 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -5,11 +5,32 @@ use crate::draw; use crate::flag; use crate::variant; -pub fn progress() { - let philadelphia = variant::philadelphia(); - let trans = flag::transgender(); +/// vertically stacking eighths +pub static V_EIGHTH: [char; 7] = ['▁', '▂', '▃', '▄', '▅', '▆', '▇']; +/// horizontally stacking eighths +pub static H_EIGHTH: [char; 7] = ['▏', '▎', '▍', '▌', '▋', '▊', '▉']; - +/// shading by intensity +pub static SHADING: [char; 3] = ['░', '▒', '▓']; + +/// 2/3 slope slant +pub static SLANT_23: [char; 2] = ['🭒', '🭏']; + +pub fn progress() -> Colors { + let red = bg(0xE50000); + let orange = bg(0xFF8D00); + let yellow = bg(0xFFEE00); + let green = bg(0x028121); + let blue = bg(0x004CFF); + let purple = bg(0x770088); + + // we need these colors in both fg & bg; just hold the integers for now + let black: u16 = 0; + let brown: u16 = 0x784F17; + let pink: u16 = 0xEAACB8; + let white: u16 = 0xFFFFFF; + + exit(0); } // everything below this point is in alphabetical order @@ -36,18 +57,35 @@ pub fn demisexual() { // BLACK triangle cutin } +pub fn disability() { + let gray = bg(0x575757); + + let green = rgb(0x3AAD7D); + let blue = rgb(0x79BFE0); + let white = rgb(0xE8E8E8); + let yellow = rgb(0xEDDB76); + let red = rgb(0xCD7281); + + let stripe = [red, yellow, white, blue, green]; + + // 2/3 slant stripes with gray background +} + pub fn intersex() -> Colors { - let yellow = rgb(0xFFDA00); + let yellow = bg(0xFFDA00); let purple = rgb(0x7A00AC); - let stripe = draw::BLOCK.repeat(9); - let part = draw::BLOCK.repeat(4); + let block = " "; + let stripe = block.repeat(9); + let part = block.repeat(4); - println!( - "{yellow}{stripe}\n{part}{purple}{}O{}{yellow}{part}\n{stripe}{RESET}", - yellow.0.bg_string(), - RESET.0.bg_str() - ); + let lines = vec![ + format!("{yellow}{stripe}"), + format!("{part}{purple}O{part}"), + format!("{stripe}") + ]; + + draw::lines(lines, false); exit(0); } diff --git a/src/draw.rs b/src/draw.rs index 5f24472..a160a21 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -9,7 +9,7 @@ use termion::{ raw::IntoRawMode }; -use crate::color::{ RESET, Colors }; +use crate::color::{ RESET, RESET_BG, Colors }; pub static BLOCK: &str = "█"; pub static UHALF: &str = "▀"; @@ -61,3 +61,29 @@ pub fn small(colors: Colors) { stdout.flush().ok(); } +pub fn lines(lines: Vec, hold: bool) { + let mut stdout = io::stdout().into_raw_mode().unwrap(); + + let count = lines.len() as u16; + for _ in 0..count { write!(stdout, "\n").ok(); } + write!(stdout, "{}", cursor::Up(count)).ok(); + + if hold { write!(stdout, "{}{}", cursor::Hide, clear::All).ok(); } + + let down = cursor::Down(1); + for line in lines { + let left = cursor::Left(line.len() as u16); + write!(stdout, "{line}{left}{down}").ok(); + } + + write!(stdout, "{RESET}{RESET_BG}").ok(); + stdout.flush().ok(); + if hold { + let stdin = io::stdin(); + for _ in stdin.keys() { break; } + write!(stdout, "{}", clear::All).ok(); + } + write!(stdout, "{}", cursor::Show).ok(); + stdout.flush().ok(); +} + diff --git a/src/main.rs b/src/main.rs index d9de377..7167852 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,10 +77,13 @@ fn main() { => flag::bisexual(), // Some("demiromantic") -// => flag::demiromantic(), +// => complex::demiromantic(), // Some("demisexual") -// => flag::demisexual(), +// => complex::demisexual(), + +// Some("disability") +// => complex::disability(); Some("genderfluid") => flag::genderfluid(), @@ -148,6 +151,7 @@ fn list_text() { println!(" bi, bisexual bisexual pride flag"); // println!(" demiromantic demiromantic pride flag"); // println!(" demisexual demisexual pride flag"); +// println!(" disability disability pride flag"); println!(" gay, pride six-color rainbow flag"); println!(" genderfluid genderfluid pride flag"); println!(" genderqueer genderqueer pride flag"); From f7afc30f2eafc6e1cc5825a5c5409183e17015e6 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 3 Jul 2023 13:11:58 -0400 Subject: [PATCH 04/10] added to README --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2c41b3d..8a1a032 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,13 @@ to make major changes and refactors until the main roadmap is complete.** Currently supports a variety of stripe flags. -Under Construction features: -- ["Complex" Flags](https://git.vwolfe.io/valerie/pride/src/branch/complex) +## Dependencies + +Complex renderers often use [Powerline's slant](https://github.com/ryanoasis/powerline-extra-symbols) +symbols, and therefore require use of a Powerline font, such as [Fira Code](https://github.com/tonsky/FiraCode). + +## Libraries + +- [pico-args](https://crates.io/crates/pico-args) +- [termion](https://crates.io/crates/termion) From bd00a2813fed31b0c557eac25ad51557e3f389f4 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 3 Jul 2023 17:43:54 -0400 Subject: [PATCH 05/10] demiromantic and demisexual flags now have proper, scalable rendering --- src/complex.rs | 100 ++++++++++++++++++++++++++++++++++++++----------- src/draw.rs | 46 +++++++++++++++++++++++ src/main.rs | 16 ++++---- 3 files changed, 132 insertions(+), 30 deletions(-) diff --git a/src/complex.rs b/src/complex.rs index 961a959..c3ae1bd 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -1,9 +1,14 @@ use std::process::exit; +use termion::{ + terminal_size, + + color::{ Bg, Rgb } +}; + use crate::color::*; use crate::draw; use crate::flag; -use crate::variant; /// vertically stacking eighths pub static V_EIGHTH: [char; 7] = ['▁', '▂', '▃', '▄', '▅', '▆', '▇']; @@ -13,10 +18,13 @@ pub static H_EIGHTH: [char; 7] = ['▏', '▎', '▍', '▌', '▋', '▊', '▉ /// shading by intensity pub static SHADING: [char; 3] = ['░', '▒', '▓']; +/// 2/1 slope triangle cut in +pub static TRIANGLE_21: [char; 3] = ['', '🭬', '']; + /// 2/3 slope slant pub static SLANT_23: [char; 2] = ['🭒', '🭏']; -pub fn progress() -> Colors { +pub fn progress(small: bool) -> Colors { let red = bg(0xE50000); let orange = bg(0xFF8D00); let yellow = bg(0xFFEE00); @@ -25,11 +33,17 @@ pub fn progress() -> Colors { let purple = bg(0x770088); // we need these colors in both fg & bg; just hold the integers for now - let black: u16 = 0; - let brown: u16 = 0x784F17; - let pink: u16 = 0xEAACB8; - let white: u16 = 0xFFFFFF; + let black: u32 = 0; + let brown: u32 = 0x784F17; + let pink: u32 = 0xEAACB8; + let white: u32 = 0xFFFFFF; + let (width, height) = if small { (6, 18) } else { terminal_size().unwrap() }; + + let stripes = vec![red, orange, yellow, green, blue, purple]; + let mut lines = draw::bg_stripes(stripes, width, height); + + draw::lines(lines, !small); exit(0); } @@ -41,32 +55,74 @@ pub fn aroace() { } -pub fn demiromantic() { - let green = rgb(0x3DA542); - let gray = rgb(0xD2D2D2); +fn demi_orientation_render(middle: Bg, bottom: Bg, width: u16, height: u16) -> Vec { + let white = bg(0xFFFFFF); - // WHITE×2 / green / gray×2 vert - // BLACK triangle cutin + let stripes = vec![white, white, middle, bottom, bottom]; + + // initial stripe output buffer + let mut lines: Vec = draw::bg_stripes(stripes, width, height); + + // assemble triangle cut-in + let linecount = lines.len(); + let depth = linecount / 2; + let corner = linecount % 2 == 1; + for n in 0..depth { + let line = lines[n].clone(); + + let replacement = format!("{BLACK}{}{}", draw::BLOCK.repeat(n), TRIANGLE_21[0]); + lines[n] = line.replacen(&" ".repeat(n + 1), &replacement, 1); + } + if corner { + let line = lines[depth].clone(); + + let replacement = format!("{BLACK}{}{}", draw::BLOCK.repeat(depth), TRIANGLE_21[1]); + lines[depth] = line.replacen(&" ".repeat(depth + 1), &replacement, 1); + } + let start = depth + (linecount % 2); + for n in 0..depth { + let line = lines[start + n].clone(); + + let size = depth - n - 1; + let replacement = format!("{BLACK}{}{}", draw::BLOCK.repeat(size), TRIANGLE_21[2]); + lines[start + n] = line.replacen(&" ".repeat(size + 1), &replacement, 1); + } + + lines } -pub fn demisexual() { - let purple = rgb(0x832FA8); - let grey = rgb(0x7B868C); +pub fn demiromantic(small: bool) -> Colors { + let green = bg(0x3DA542); + let gray = bg(0xD2D2D2); - // WHITE×2 / green / grey×2 vert - // BLACK triangle cutin + let (width, height) = if small { (15, 5) } else { terminal_size().unwrap() }; + let lines = demi_orientation_render(green, gray, width, height); + + draw::lines(lines, !small); + exit(0); +} + +pub fn demisexual(small: bool) -> Colors { + let purple = bg(0x832FA8); + let grey = bg(0x7B868C); + + let (width, height) = if small { (15, 5) } else { terminal_size().unwrap() }; + let lines = demi_orientation_render(purple, grey, width, height); + + draw::lines(lines, !small); + exit(0); } pub fn disability() { let gray = bg(0x575757); - let green = rgb(0x3AAD7D); - let blue = rgb(0x79BFE0); - let white = rgb(0xE8E8E8); - let yellow = rgb(0xEDDB76); - let red = rgb(0xCD7281); + let green: u32 = 0x3AAD7D; + let blue: u32 = 0x79BFE0; + let white: u32 = 0xE8E8E8; + let yellow: u32 = 0xEDDB76; + let red: u32 = 0xCD7281; - let stripe = [red, yellow, white, blue, green]; + let stripes = [red, yellow, white, blue, green]; // 2/3 slant stripes with gray background } diff --git a/src/draw.rs b/src/draw.rs index a160a21..40f071f 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -4,6 +4,7 @@ use termion::{ terminal_size, clear, + color::{ Bg, Fg, Rgb }, cursor, input::TermRead, raw::IntoRawMode @@ -87,3 +88,48 @@ pub fn lines(lines: Vec, hold: bool) { stdout.flush().ok(); } +pub fn fg_stripes(colors: Vec>, width: u16, height: u16) -> Vec { + let width = width as usize; + let height = height as usize; + let count = colors.len(); + + let thresh = height / count; + + let stripe = BLOCK.repeat(width); + let mut output = Vec::new(); + + let mut index = 0; + for n in 0..height { + if n != 0 && n % thresh == 0 { + index += 1; + if index >= count { break; } + } + let color = colors[index]; + output.push(format!("{color}{stripe}")); + } + + output +} +pub fn bg_stripes(colors: Vec>, width: u16, height: u16) -> Vec { + let width = width as usize; + let height = height as usize; + let count = colors.len(); + + let thresh = height / count; + + let stripe = " ".repeat(width); + let mut output = Vec::new(); + + let mut index = 0; + for n in 0..height { + if n != 0 && n % thresh == 0 { + index += 1; + if index >= count { break; } + } + let color = colors[index]; + output.push(format!("{color}{stripe}")); + } + + output +} + diff --git a/src/main.rs b/src/main.rs index 7167852..8fac60b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,8 +47,8 @@ fn main() { => variant::gilbert_baker(), Some("philadelphia") => variant::philadelphia(), -// Some("progress") -// => complex::progress(), + Some("progress") + => complex::progress(small), _ => flag::pride() } @@ -76,11 +76,11 @@ fn main() { Some("bisexual" | "bi") => flag::bisexual(), -// Some("demiromantic") -// => complex::demiromantic(), + Some("demiromantic") + => complex::demiromantic(small), -// Some("demisexual") -// => complex::demisexual(), + Some("demisexual") + => complex::demisexual(small), // Some("disability") // => complex::disability(); @@ -149,8 +149,8 @@ fn list_text() { // println!(" aroace aromantic/asexual pride flag"); println!(" bigender bigender pride flag"); println!(" bi, bisexual bisexual pride flag"); -// println!(" demiromantic demiromantic pride flag"); -// println!(" demisexual demisexual pride flag"); + println!(" demiromantic demiromantic pride flag"); + println!(" demisexual demisexual pride flag"); // println!(" disability disability pride flag"); println!(" gay, pride six-color rainbow flag"); println!(" genderfluid genderfluid pride flag"); From 2802f6dd42711ad3450c2e9fa640221d6a056ac8 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 3 Jul 2023 23:07:37 -0400 Subject: [PATCH 06/10] groundwork for progress flag --- src/complex.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/complex.rs b/src/complex.rs index c3ae1bd..e21e1b4 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -35,13 +35,26 @@ pub fn progress(small: bool) -> Colors { // we need these colors in both fg & bg; just hold the integers for now let black: u32 = 0; let brown: u32 = 0x784F17; + let ltblue: u32 = 0xEAACB8; let pink: u32 = 0xEAACB8; let white: u32 = 0xFFFFFF; - let (width, height) = if small { (6, 18) } else { terminal_size().unwrap() }; + let (height, width) = if small { (6, 18) } else { terminal_size().unwrap() }; - let stripes = vec![red, orange, yellow, green, blue, purple]; - let mut lines = draw::bg_stripes(stripes, width, height); + let stripes = [red, orange, yellow, green, blue, purple]; + let chevrons = [white, pink, ltblue, brown, black]; + let mut lines: Vec = Vec::new(); + //let mut lines = draw::bg_stripes(stripes, width, height); + + /* i think i'm stuck having to write stripes here too. it'll + * be easier to just generate the stripes on alongside the + * chevrons than to figure out where to move the ansi bg code + */ + + let stripe_index = 0; + let chevron_index = 5; // chevrons are funky :) + + draw::lines(lines, !small); exit(0); From b0678542ef1b6f9560d9d0171025d25ead39672b Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 7 Jul 2023 12:36:31 -0400 Subject: [PATCH 07/10] introduced Flag enum to unify main control flow; no more exits in complex renderers --- src/complex.rs | 86 ++++++++++++++++++++++++++++++++++++++------------ src/draw.rs | 26 ++++++++++++++- src/flag.rs | 57 +++++++++++++++++---------------- src/main.rs | 7 ++-- src/variant.rs | 21 ++++++++---- 5 files changed, 136 insertions(+), 61 deletions(-) diff --git a/src/complex.rs b/src/complex.rs index e21e1b4..901f003 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -1,4 +1,4 @@ -use std::process::exit; +//! flags that require more complex rendering than just scaling colored stripes use termion::{ terminal_size, @@ -7,7 +7,7 @@ use termion::{ }; use crate::color::*; -use crate::draw; +use crate::draw::{ self, Flag }; use crate::flag; /// vertically stacking eighths @@ -24,7 +24,7 @@ pub static TRIANGLE_21: [char; 3] = ['', '🭬', '']; /// 2/3 slope slant pub static SLANT_23: [char; 2] = ['🭒', '🭏']; -pub fn progress(small: bool) -> Colors { +pub fn progress(small: bool) -> Flag { let red = bg(0xE50000); let orange = bg(0xFF8D00); let yellow = bg(0xFFEE00); @@ -41,23 +41,68 @@ pub fn progress(small: bool) -> Colors { let (height, width) = if small { (6, 18) } else { terminal_size().unwrap() }; + // create color slices and line buffer let stripes = [red, orange, yellow, green, blue, purple]; let chevrons = [white, pink, ltblue, brown, black]; let mut lines: Vec = Vec::new(); - //let mut lines = draw::bg_stripes(stripes, width, height); - /* i think i'm stuck having to write stripes here too. it'll - * be easier to just generate the stripes on alongside the - * chevrons than to figure out where to move the ansi bg code + // set up stripe index + let mut stripe_index = 0; + + /* ok, coming up with procedure: + * - can't rely on bg_stripes; line count, threshold, etc., will need to happen here + * - line count will always be the largest multiple of 6 smaller than height; c = h - (h % 6) + * - chevrons may have larger widths: TODO calc + * - depth will be funky; line depth will need to use "full" depth; (Df - Dl) / Wc = Ic (TODO verify?) + * - switch stripe index on *absolute* line number rather than n + * - chevron building will be BLOCK.repeat(width) + TRIANGLE_21[0] (fg Ic, bg Ic + 1) + * - chevrons[len - 1] will need unique handling to draw stripes */ - let stripe_index = 0; - let chevron_index = 5; // chevrons are funky :) + // set up constraints + let linecount = height - (height % 6); // largest multiple of 6 smaller than height + let full_depth = linecount / 2; + let corner = linecount % 2 == 1; + let chevron_width = 0; // chevron width (TODO) + let thresh = height / linecount; // stripe threshold; no bg_stripes call! + let mut line_no = 0; // absolute line number; n is relative - + // piecewise functions: ascent -> peak -> descent + for n in 0..full_depth { + // advance stripe color at stripe threshold by line number + if line_no != 0 && line_no % thresh == 0 { stripe_index += 1; } - draw::lines(lines, !small); - exit(0); + // init current line + let line = String::new(); + + // get this line's depth? + // get chevron start: (full_depth - line_depth) / chevron_width = chevron_start + + // for chevron_index in chevron_start..5 + // if chevron_index = 4, draw stripe after (stripe width = width - line_depth - 1) + // else, draw BLOCK.repeat(chevron_width) + TRIANGLE_21[0] + + lines.push(line); + line_no += 1; + } + if corner { + if line_no % thresh == 0 { stripe_index += 1; } + + let line = String::new(); + + lines.push(line); + line_no += 1; + } + for n in 0..full_depth { + if line_no % thresh == 0 { stripe_index += 1; } + + let line = String::new(); + + lines.push(line); + line_no += 1; + } + + Flag::Lines(lines) } // everything below this point is in alphabetical order @@ -80,6 +125,7 @@ fn demi_orientation_render(middle: Bg, bottom: Bg, width: u16, height: let linecount = lines.len(); let depth = linecount / 2; let corner = linecount % 2 == 1; + // piecewise functions: ascending -> peak -> descending for n in 0..depth { let line = lines[n].clone(); @@ -104,26 +150,24 @@ fn demi_orientation_render(middle: Bg, bottom: Bg, width: u16, height: lines } -pub fn demiromantic(small: bool) -> Colors { +pub fn demiromantic(small: bool) -> Flag { let green = bg(0x3DA542); let gray = bg(0xD2D2D2); let (width, height) = if small { (15, 5) } else { terminal_size().unwrap() }; let lines = demi_orientation_render(green, gray, width, height); - draw::lines(lines, !small); - exit(0); + Flag::Lines(lines) } -pub fn demisexual(small: bool) -> Colors { +pub fn demisexual(small: bool) -> Flag { let purple = bg(0x832FA8); let grey = bg(0x7B868C); let (width, height) = if small { (15, 5) } else { terminal_size().unwrap() }; let lines = demi_orientation_render(purple, grey, width, height); - draw::lines(lines, !small); - exit(0); + Flag::Lines(lines) } pub fn disability() { @@ -138,9 +182,10 @@ pub fn disability() { let stripes = [red, yellow, white, blue, green]; // 2/3 slant stripes with gray background + } -pub fn intersex() -> Colors { +pub fn intersex() -> Flag { let yellow = bg(0xFFDA00); let purple = rgb(0x7A00AC); @@ -154,8 +199,7 @@ pub fn intersex() -> Colors { format!("{stripe}") ]; - draw::lines(lines, false); - exit(0); + Flag::Lines(lines) } pub fn polyamorous() { diff --git a/src/draw.rs b/src/draw.rs index 40f071f..6e6de37 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -62,7 +62,7 @@ pub fn small(colors: Colors) { stdout.flush().ok(); } -pub fn lines(lines: Vec, hold: bool) { +pub fn draw_lines(lines: Vec, hold: bool) { let mut stdout = io::stdout().into_raw_mode().unwrap(); let count = lines.len() as u16; @@ -133,3 +133,27 @@ pub fn bg_stripes(colors: Vec>, width: u16, height: u16) -> Vec output } +pub enum Flag { + Stripes(Colors), + Lines(Vec) +} +impl Flag { + pub fn draw(self, hold: bool) { + let lines = match self { + Flag::Stripes(colors) + => { + let (width, height); + if hold { (width, height) = terminal_size().unwrap(); } + else { + height = colors.len() as u16; + width = height * 3; + } + fg_stripes(colors, width, height) + }, + Flag::Lines(lines) + => lines + }; + draw_lines(lines, hold); + } +} + diff --git a/src/flag.rs b/src/flag.rs index 943ee83..ca1e62c 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -1,7 +1,8 @@ use crate::color::*; +use crate::draw::Flag; -pub fn pride() -> Colors { +pub fn pride() -> Flag { let red = rgb(0xE50000); let orange = rgb(0xFF8D00); let yellow = rgb(0xFFEE00); @@ -9,108 +10,108 @@ pub fn pride() -> Colors { let blue = rgb(0x004CFF); let purple = rgb(0x770088); - vec![red, orange, yellow, green, blue, purple] + Flag::Stripes(vec![red, orange, yellow, green, blue, purple]) } -pub fn transgender() -> Colors { +pub fn transgender() -> Flag { let pink = rgb(0x7ACBF5); let blue = rgb(0xEAACB8); - vec![pink, blue, WHITE, blue, pink] + Flag::Stripes(vec![pink, blue, WHITE, blue, pink]) } // everything below here is alphabetical -pub fn agender() -> Colors { +pub fn agender() -> Flag { let gray = rgb(0xB9B9B9); let green = rgb(0xB8F483); - vec![BLACK, gray, WHITE, green, WHITE, gray, BLACK] + Flag::Stripes(vec![BLACK, gray, WHITE, green, WHITE, gray, BLACK]) } -pub fn aromantic() -> Colors { +pub fn aromantic() -> Flag { let green = rgb(0x3BA740); let lime = rgb(0xA8D47A); let grey = rgb(0xABABAB); - vec![green, lime, WHITE, grey, BLACK] + Flag::Stripes(vec![green, lime, WHITE, grey, BLACK]) } -pub fn asexual() -> Colors { +pub fn asexual() -> Flag { let grey = rgb(0xA4A4A4); let purple = rgb(0x810081); - vec![BLACK, grey, WHITE, purple] + Flag::Stripes(vec![BLACK, grey, WHITE, purple]) } -pub fn bigender() -> Colors { +pub fn bigender() -> Flag { let pink = rgb(0xE676A6); let yellow = rgb(0xF9F04C); let purple = rgb(0xAB6BBB); let blue = rgb(0x6D96DC); - vec![pink, yellow, WHITE, purple, blue] + Flag::Stripes(vec![pink, yellow, WHITE, purple, blue]) } -pub fn bisexual() -> Colors { +pub fn bisexual() -> Flag { let magenta = rgb(0xC42A6F); let purple = rgb(0x915392); let blue = rgb(0x1437A2); - vec![magenta, magenta, purple, blue, blue] + Flag::Stripes(vec![magenta, magenta, purple, blue, blue]) } -pub fn genderfluid() -> Colors { +pub fn genderfluid() -> Flag { let pink = rgb(0xFF75A2); let violet = rgb(0xBE18D6); let blue = rgb(0x333EBD); - vec![pink, WHITE, violet, BLACK, blue] + Flag::Stripes(vec![pink, WHITE, violet, BLACK, blue]) } -pub fn genderqueer() -> Colors { +pub fn genderqueer() -> Flag { let purple = rgb(0xB899DF); let green = rgb(0x6B8E3B); - vec![purple, WHITE, green] + Flag::Stripes(vec![purple, WHITE, green]) } -pub fn gendervoid() -> Colors { +pub fn gendervoid() -> Flag { let navy = rgb(0x08114A); let gray = rgb(0x4A484B); - vec![navy, gray, BLACK, gray, navy] + Flag::Stripes(vec![navy, gray, BLACK, gray, navy]) } -pub fn lesbian() -> Colors { +pub fn lesbian() -> Flag { let red = rgb(0xD62800); let orange = rgb(0xFF9B56); let pink = rgb(0xD462A6); let magenta = rgb(0xA40062); - vec![red, orange, WHITE, pink, magenta] + Flag::Stripes(vec![red, orange, WHITE, pink, magenta]) } -pub fn multigender() -> Colors { +pub fn multigender() -> Flag { let blue = rgb(0x3F47CC); let ltblue = rgb(0x01A4E9); let orange = rgb(0xFB7F27); - vec![blue, ltblue, orange, ltblue, blue] + Flag::Stripes(vec![blue, ltblue, orange, ltblue, blue]) } -pub fn nonbinary() -> Colors { +pub fn nonbinary() -> Flag { let yellow = rgb(0xFFF433); let purple = rgb(0x9B59D0); - vec![yellow, WHITE, purple, BLACK] + Flag::Stripes(vec![yellow, WHITE, purple, BLACK]) } -pub fn pansexual() -> Colors { +pub fn pansexual() -> Flag { let magenta = rgb(0xFF1B8D); let yellow = rgb(0xFFDA00); let cyan = rgb(0x1BB3FF); - vec![magenta, yellow, cyan] + Flag::Stripes(vec![magenta, yellow, cyan]) } diff --git a/src/main.rs b/src/main.rs index 8fac60b..9d1c208 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ mod draw; mod flag; mod variant; -use crate::color::Colors; +use crate::draw::Flag; static VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -38,7 +38,7 @@ fn main() { let subcommand = args.subcommand().unwrap(); - let colors: Colors = match subcommand.as_deref() { + let flag: Flag = match subcommand.as_deref() { Some("pride" | "gay") => { let variant = args.subcommand().unwrap_or(None); @@ -115,8 +115,7 @@ fn main() { _ => { help_text(); exit(1) } }; - if small { draw::small(colors); } - else { draw::full(colors); } + flag.draw(!small); } diff --git a/src/variant.rs b/src/variant.rs index 127d71d..daa2076 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -1,10 +1,11 @@ use crate::{ color::*, + draw::Flag, flag }; -pub fn gilbert_baker() -> Colors { +pub fn gilbert_baker() -> Flag { let pink = rgb(0xFF69B4); // sex let red = rgb(0xFF0000); // life let orange = rgb(0xFF8F00); // healing @@ -14,16 +15,22 @@ pub fn gilbert_baker() -> Colors { let indigo = rgb(0x3E0099); // serenity let purple = rgb(0x8F008F); // spirit - vec![pink, red, orange, yellow, green, cyan, indigo, purple] + Flag::Stripes(vec![pink, red, orange, yellow, green, cyan, indigo, purple]) } -pub fn philadelphia() -> Colors { +pub fn philadelphia() -> Flag { let brown = rgb(0x784F17); - let mut output = flag::pride(); - output.insert(0, BLACK); - output.insert(1, brown); + let base = flag::pride(); + let mut colors = match base { + Flag::Stripes(inner) + => inner, + _ + => { panic!("impossible enum variant"); } + }; + colors.insert(0, BLACK); + colors.insert(1, brown); - output + Flag::Stripes(colors) } From b318c96734fce3bd533f86632cdf007417576fa8 Mon Sep 17 00:00:00 2001 From: Valerie Date: Fri, 7 Jul 2023 13:36:03 -0400 Subject: [PATCH 08/10] moved Flag enum to flag module, added first iteration of aroace flag --- src/complex.rs | 41 +++++++++++++++++++++++++++++------- src/draw.rs | 56 ++++---------------------------------------------- src/flag.rs | 7 ++++++- src/main.rs | 8 ++++---- src/variant.rs | 3 +-- 5 files changed, 49 insertions(+), 66 deletions(-) diff --git a/src/complex.rs b/src/complex.rs index 901f003..96d18bb 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -6,9 +6,11 @@ use termion::{ color::{ Bg, Rgb } }; -use crate::color::*; -use crate::draw::{ self, Flag }; -use crate::flag; +use crate::{ + color::*, + draw, + flag::{ self, Flag } +}; /// vertically stacking eighths pub static V_EIGHTH: [char; 7] = ['▁', '▂', '▃', '▄', '▅', '▆', '▇']; @@ -39,7 +41,7 @@ pub fn progress(small: bool) -> Flag { let pink: u32 = 0xEAACB8; let white: u32 = 0xFFFFFF; - let (height, width) = if small { (6, 18) } else { terminal_size().unwrap() }; + let (width, height) = if small { (18, 6) } else { terminal_size().unwrap() }; // create color slices and line buffer let stripes = [red, orange, yellow, green, blue, purple]; @@ -77,6 +79,7 @@ pub fn progress(small: bool) -> Flag { // get this line's depth? // get chevron start: (full_depth - line_depth) / chevron_width = chevron_start + let start: i16 = 2 - (n as i16); // for chevron_index in chevron_start..5 // if chevron_index = 4, draw stripe after (stripe width = width - line_depth - 1) @@ -107,10 +110,34 @@ pub fn progress(small: bool) -> Flag { // everything below this point is in alphabetical order -pub fn aroace() { - let aro = flag::aromantic(); - let ace = flag::asexual(); +pub fn aroace(small: bool) -> Flag { + // pull colors from aro & ace stripe flags + let Flag::Stripes(aro) = flag::aromantic() else { panic!() }; + let Flag::Stripes(ace) = flag::asexual() else { panic!() }; + let (width, height) = if small { (60, 20) } else { terminal_size().unwrap() }; + + let mut lines: Vec = Vec::new(); + + // set up constraints + let linecount = height - (height % 20); + let aro_thresh = linecount / 5; // threshold for aromantic colors + let ace_thresh = linecount / 4; // threshold for asexual colors + let stripe = draw::BLOCK.repeat((width / 2) as usize); + + let mut aro_index = 0; + let mut ace_index = 0; + for n in 0..linecount { + // switch colors on thresholds + if n != 0 { + if n % aro_thresh == 0 { aro_index += 1; } + if n % ace_thresh == 0 { ace_index += 1; } + } + let line = format!("{}{stripe}{}{stripe}", aro[aro_index], ace[ace_index]); + lines.push(line); + } + + Flag::Lines(lines) } fn demi_orientation_render(middle: Bg, bottom: Bg, width: u16, height: u16) -> Vec { diff --git a/src/draw.rs b/src/draw.rs index 6e6de37..edfc164 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -10,58 +10,14 @@ use termion::{ raw::IntoRawMode }; -use crate::color::{ RESET, RESET_BG, Colors }; +use crate::{ + color::{ RESET, RESET_BG }, + flag::Flag +}; pub static BLOCK: &str = "█"; pub static UHALF: &str = "▀"; -pub fn full(colors: Colors) { - 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 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(); -} - -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(); -} - pub fn draw_lines(lines: Vec, hold: bool) { let mut stdout = io::stdout().into_raw_mode().unwrap(); @@ -133,10 +89,6 @@ pub fn bg_stripes(colors: Vec>, width: u16, height: u16) -> Vec output } -pub enum Flag { - Stripes(Colors), - Lines(Vec) -} impl Flag { pub fn draw(self, hold: bool) { let lines = match self { diff --git a/src/flag.rs b/src/flag.rs index ca1e62c..e4c28c0 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -1,6 +1,11 @@ use crate::color::*; -use crate::draw::Flag; + +pub enum Flag { + Stripes(Colors), + Lines(Vec) +} + pub fn pride() -> Flag { let red = rgb(0xE50000); diff --git a/src/main.rs b/src/main.rs index 9d1c208..6fd10ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ mod draw; mod flag; mod variant; -use crate::draw::Flag; +use crate::flag::Flag; static VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -67,8 +67,8 @@ fn main() { Some("asexual" | "ace") => flag::asexual(), -// Some("aroace" | "aromantic-asexual") -// => complex::aroace(), + Some("aroace" | "aromantic-asexual") + => complex::aroace(small), Some("bigender") => flag::bigender(), @@ -145,7 +145,7 @@ fn list_text() { println!(" agender agender pride flag"); println!(" aro, aromantic aromantic pride flag"); println!(" ace, asexual asexual pride flag"); -// println!(" aroace aromantic/asexual pride flag"); + println!(" aroace aromantic/asexual pride flag"); println!(" bigender bigender pride flag"); println!(" bi, bisexual bisexual pride flag"); println!(" demiromantic demiromantic pride flag"); diff --git a/src/variant.rs b/src/variant.rs index daa2076..2dbd8fb 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -1,8 +1,7 @@ use crate::{ color::*, - draw::Flag, - flag + flag::{ self, Flag } }; pub fn gilbert_baker() -> Flag { From b238dbeecb72130cd193868028b84087ec09bc11 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 10 Jul 2023 12:39:40 -0400 Subject: [PATCH 09/10] finished progress flag --- src/complex.rs | 97 ++++++++++++++++++++++++++++++++++++++------------ src/main.rs | 1 + src/util.rs | 52 +++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 23 deletions(-) create mode 100644 src/util.rs diff --git a/src/complex.rs b/src/complex.rs index 96d18bb..c3355cd 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -9,7 +9,8 @@ use termion::{ use crate::{ color::*, draw, - flag::{ self, Flag } + flag::{ self, Flag }, + util::{ ansi_len, ansi_substr } }; /// vertically stacking eighths @@ -38,18 +39,18 @@ pub fn progress(small: bool) -> Flag { let black: u32 = 0; let brown: u32 = 0x784F17; let ltblue: u32 = 0xEAACB8; - let pink: u32 = 0xEAACB8; + let pink: u32 = 0x7ACBF5; let white: u32 = 0xFFFFFF; let (width, height) = if small { (18, 6) } else { terminal_size().unwrap() }; // create color slices and line buffer let stripes = [red, orange, yellow, green, blue, purple]; - let chevrons = [white, pink, ltblue, brown, black]; + let chevrons = [white, ltblue, pink, brown, black]; let mut lines: Vec = Vec::new(); // set up stripe index - let mut stripe_index = 0; + let mut index = 0; /* ok, coming up with procedure: * - can't rely on bg_stripes; line count, threshold, etc., will need to happen here @@ -63,43 +64,93 @@ pub fn progress(small: bool) -> Flag { // set up constraints let linecount = height - (height % 6); // largest multiple of 6 smaller than height - let full_depth = linecount / 2; + let full_depth = width / 3; + let chevron_width = (full_depth / 6) - 1; + let direction_thresh = linecount / 2; let corner = linecount % 2 == 1; - let chevron_width = 0; // chevron width (TODO) - let thresh = height / linecount; // stripe threshold; no bg_stripes call! + + let thresh = linecount / 6; // stripe threshold; no bg_stripes call! let mut line_no = 0; // absolute line number; n is relative + // chevron helper + let build_chevron = | separator: char | -> String { + let mut output = format!( + "{fg}{bg}{stripe}{separator}", + fg = rgb(chevrons[0]), + bg = bg(chevrons[1]), + stripe = draw::BLOCK.repeat( usize::max(chevron_width as usize * 2, 1) ) + ); + let stripe = draw::BLOCK.repeat(chevron_width as usize); + for i in 1..4 { + output += &format!( + "{fg}{bg}{stripe}{separator}", + fg = rgb(chevrons[i]), + bg = bg(chevrons[i + 1]) + ); + } + output += &format!( + "{fg}{stripe}", + fg = rgb(chevrons[4]) + ); + + output + }; + // piecewise functions: ascent -> peak -> descent - for n in 0..full_depth { + let mut base = build_chevron(TRIANGLE_21[0]); + let base_length = base.len(); + let display_length = ansi_len(&base) + 1; // chevron width will always stay the same; add 1 for the last separator + for n in 0..direction_thresh { // advance stripe color at stripe threshold by line number - if line_no != 0 && line_no % thresh == 0 { stripe_index += 1; } + if line_no != 0 && line_no % thresh == 0 { index += 1; } - // init current line - let line = String::new(); + // grab our substring constraints + let start = (direction_thresh - n) as usize - 1; + let diff = display_length - start; - // get this line's depth? - // get chevron start: (full_depth - line_depth) / chevron_width = chevron_start - let start: i16 = 2 - (n as i16); - - // for chevron_index in chevron_start..5 - // if chevron_index = 4, draw stripe after (stripe width = width - line_depth - 1) - // else, draw BLOCK.repeat(chevron_width) + TRIANGLE_21[0] + // take substring of chevron line... + let mut line = ansi_substr(&base, start as usize, base_length); + // ... and add the colored stripe + line += &format!( + "{stripe}{separator}{line}", + stripe = stripes[index], + separator = TRIANGLE_21[0], + line = " ".repeat(width as usize - diff) + ); lines.push(line); line_no += 1; } if corner { - if line_no % thresh == 0 { stripe_index += 1; } + if line_no % thresh == 0 { index += 1; } - let line = String::new(); + let base = build_chevron(TRIANGLE_21[1]); + let mut line = ansi_substr(&base, 0, base_length); + line += &format!( + "{stripe}{separator}{line}", + stripe = stripes[index], + separator = TRIANGLE_21[1], + line = " ".repeat(width as usize - display_length) + ); lines.push(line); line_no += 1; } - for n in 0..full_depth { - if line_no % thresh == 0 { stripe_index += 1; } + base = build_chevron(TRIANGLE_21[2]); + for n in 0..direction_thresh { + if line_no % thresh == 0 { index += 1; } + if index > 5 { break; } - let line = String::new(); + let start = n as usize; + let diff = display_length - start; + + let mut line = ansi_substr(&base, start, base_length); + line += &format!( + "{stripe}{separator}{line}", + stripe = stripes[index], + separator = TRIANGLE_21[2], + line = " ".repeat(width as usize - diff) + ); lines.push(line); line_no += 1; diff --git a/src/main.rs b/src/main.rs index 6fd10ec..1215821 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ mod color; mod complex; mod draw; mod flag; +mod util; mod variant; use crate::flag::Flag; diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..cd198d9 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,52 @@ + +/// gets the substring of displayed characters of an ANSI formatted string +pub fn ansi_substr(source: &str, start: usize, end: usize) -> String { + // init output string + let mut output = String::new(); + + // trackers + let mut escaped = false; + let mut index = 0; + for character in source.chars() { + // escape character delimits start and end of ansi sequences + if character == '\u{1B}' { + escaped = true; + output.push(character); + } + // push ALL escaped characters + if escaped { + output.push(character); + // and unset esc on m + if character == 'm' { escaped = false; } + } + // non-escaped characters must obey bounds + else { + if index < start { + index += 1; + continue; + } + + output.push(character); + index += 1; + + if index > end { break; } + } + } + output +} + +/// gets the number of displayed characters in an ANSI formatted string +pub fn ansi_len(source: &str) -> usize { + let mut output = 0; + let mut escaped = false; + + for character in source.chars() { + if character == '\u{1B}' { escaped = true; } + + if !escaped { output += 1; } + else if character == 'm' { escaped = false; } + } + + output +} + From b303f3197a0897d902c72230f4f3553496fb8124 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 10 Jul 2023 13:36:07 -0400 Subject: [PATCH 10/10] fixed progress not being a top-level flag --- Cargo.toml | 2 +- src/main.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a3b5089..83d9966 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pride" -version = "0.2.0" +version = "0.2.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 47cfb7e..f453cb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,6 +122,9 @@ fn main() { // Some("poly" | "polyamorous" | "polyamory") // => complex::polyamorous(), + Some("progress") + => flag::progress(), + _ => { help_text(); exit(1) } };