Compare commits

..

No commits in common. "d7fb635a741d47ccf249e1bf1635072a2700b5f6" and "a4027ee4758b15d4715160289786b6d6d9e0f4ea" have entirely different histories.

10 changed files with 210 additions and 325 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "pride" name = "pride"
version = "0.4.1" version = "0.3.1"
edition = "2021" edition = "2021"
authors = [ "Valerie Wolfe <sleeplessval@gmail.com>" ] authors = [ "Valerie Wolfe <sleeplessval@gmail.com>" ]
description = "Pride flags in the terminal." description = "Pride flags in the terminal."

View file

@ -6,8 +6,7 @@
.Nd shows pride flags in the terminal .Nd shows pride flags in the terminal
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl hlv .Op Fl hlvs
.Op Fl s Op Ar size
.Op Ar flag .Op Ar flag
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -18,8 +17,6 @@ displays pride flags in the terminal using ANSI truecolor sequences.
Shows a brief help text. Shows a brief help text.
.It Fl l , Fl -list .It Fl l , Fl -list
Shows a list of available pride flags. Shows a list of available pride flags.
.It Fl s , Fl -size Op Ar size
Scales the flag to the given size: no value or 'small' will produce the minimum size; one number sets the width; and two numbers separated by 'x' sets width and height respectively.
.It Fl v , Fl -version .It Fl v , Fl -version
Shows version information. Shows version information.
.It Ar flag .It Ar flag
@ -50,7 +47,7 @@ The gay men pride flag designed by @gayflagblog@tumblr.com in 2019.
.It Ic gender-nonconforming, gendernonconforming, gnc .It Ic gender-nonconforming, gendernonconforming, gnc
.It Ic genderqueer .It Ic genderqueer
.It Ic gendervoid .It Ic gendervoid
.It Ic lesbian, wlw .It Ic lesbian
The 5-stripe lesbian pride flag designed by Emily Gwen in 2018. The 5-stripe lesbian pride flag designed by Emily Gwen in 2018.
.Pp .Pp
VARIANTS VARIANTS
@ -85,22 +82,10 @@ The transgender pride flag designed by Monica Helms in 1999.
.Sh EXIT STATUS .Sh EXIT STATUS
.Bl -tag -width Ds .Bl -tag -width Ds
.It 1 .It 1
Unmatched Unmatched flag name.
.Ar flag
name.
.It 2 .It 2
Failed to parse Not running in a terminal.
.Ar size .
.It 3
The provided
.Ar size
is too small to render.
.El .El
.Sh EXAMPLES
Create a full-width banner flag using tput:
.Pp
.Dl $ pride -s `tput cols`
.Pp
.Sh AUTHORS .Sh AUTHORS
.An -nosplit .An -nosplit
.An Valerie Wolfe Aq Mt sleeplessval@gmail.com .An Valerie Wolfe Aq Mt sleeplessval@gmail.com

248
sbom.xml
View file

@ -1,13 +1,13 @@
{ {
"SPDXID": "SPDXRef-DOCUMENT", "SPDXID": "SPDXRef-DOCUMENT",
"creationInfo": { "creationInfo": {
"created": "2024-07-05T20:16:51.403Z", "created": "2024-03-14T21:10:21.186Z",
"creators": [ "creators": [
"Tool: cargo-sbom-v0.8.4" "Tool: cargo-sbom-v0.8.4"
] ]
}, },
"dataLicense": "CC0-1.0", "dataLicense": "CC0-1.0",
"documentNamespace": "https://spdx.org/spdxdocs/pride-6150510e-b518-43f0-aa53-3e2795909cc2", "documentNamespace": "https://spdx.org/spdxdocs/pride-4bb3085e-02b0-4995-aab3-241ff2d827ee",
"files": [ "files": [
{ {
"SPDXID": "SPDXRef-File-pride", "SPDXID": "SPDXRef-File-pride",
@ -20,6 +20,88 @@
], ],
"name": "pride", "name": "pride",
"packages": [ "packages": [
{
"SPDXID": "SPDXRef-Package-numtoa-0.1.0",
"description": "Convert numbers into stack-allocated byte arrays",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/numtoa@0.1.0",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0",
"name": "numtoa",
"versionInfo": "0.1.0"
},
{
"SPDXID": "SPDXRef-Package-termion-2.0.3",
"description": "A bindless library for manipulating terminals.",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/termion@2.0.3",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "termion",
"versionInfo": "2.0.3"
},
{
"SPDXID": "SPDXRef-Package-pico-args-0.5.0",
"description": "An ultra simple CLI arguments parser.",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/pico-args@0.5.0",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "pico-args",
"versionInfo": "0.5.0"
},
{
"SPDXID": "SPDXRef-Package-libc-0.2.151",
"description": "Raw FFI bindings to platform libraries like libc.\n",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/libc@0.2.151",
"referenceType": "purl"
}
],
"homepage": "https://github.com/rust-lang/libc",
"licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0",
"name": "libc",
"versionInfo": "0.2.151"
},
{
"SPDXID": "SPDXRef-Package-bitflags-2.4.1",
"description": "A macro to generate structures which behave like bitflags.\n",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/bitflags@2.4.1",
"referenceType": "purl"
}
],
"homepage": "https://github.com/bitflags/bitflags",
"licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0",
"name": "bitflags",
"versionInfo": "2.4.1"
},
{ {
"SPDXID": "SPDXRef-Package-redox_syscall-0.4.1", "SPDXID": "SPDXRef-Package-redox_syscall-0.4.1",
"description": "A Rust library to access raw Redox system calls", "description": "A Rust library to access raw Redox system calls",
@ -36,39 +118,6 @@
"name": "redox_syscall", "name": "redox_syscall",
"versionInfo": "0.4.1" "versionInfo": "0.4.1"
}, },
{
"SPDXID": "SPDXRef-Package-libredox-0.0.2",
"description": "Redox stable ABI",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/libredox@0.0.2",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "libredox",
"versionInfo": "0.0.2"
},
{
"SPDXID": "SPDXRef-Package-libc-0.2.155",
"description": "Raw FFI bindings to platform libraries like libc.\n",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/libc@0.2.155",
"referenceType": "purl"
}
],
"homepage": "https://github.com/rust-lang/libc",
"licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0",
"name": "libc",
"versionInfo": "0.2.155"
},
{ {
"SPDXID": "SPDXRef-Package-bitflags-1.3.2", "SPDXID": "SPDXRef-Package-bitflags-1.3.2",
"description": "A macro to generate structures which behave like bitflags.\n", "description": "A macro to generate structures which behave like bitflags.\n",
@ -86,6 +135,16 @@
"name": "bitflags", "name": "bitflags",
"versionInfo": "1.3.2" "versionInfo": "1.3.2"
}, },
{
"SPDXID": "SPDXRef-Package-pride-0.3.1",
"description": "Pride flags in the terminal.",
"downloadLocation": "NONE",
"homepage": "https://git.vwolfe.io/valerie/pride",
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "pride",
"versionInfo": "0.3.1"
},
{ {
"SPDXID": "SPDXRef-Package-redox_termios-0.1.3", "SPDXID": "SPDXRef-Package-redox_termios-0.1.3",
"description": "A Rust library to access Redox termios functions", "description": "A Rust library to access Redox termios functions",
@ -103,101 +162,42 @@
"versionInfo": "0.1.3" "versionInfo": "0.1.3"
}, },
{ {
"SPDXID": "SPDXRef-Package-numtoa-0.1.0", "SPDXID": "SPDXRef-Package-libredox-0.0.2",
"description": "Convert numbers into stack-allocated byte arrays", "description": "Redox stable ABI",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index", "downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [ "externalRefs": [
{ {
"referenceCategory": "PACKAGE-MANAGER", "referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/numtoa@0.1.0", "referenceLocator": "pkg:cargo/libredox@0.0.2",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0",
"name": "numtoa",
"versionInfo": "0.1.0"
},
{
"SPDXID": "SPDXRef-Package-termion-3.0.0",
"description": "A bindless library for manipulating terminals.",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/termion@3.0.0",
"referenceType": "purl" "referenceType": "purl"
} }
], ],
"licenseConcluded": "MIT", "licenseConcluded": "MIT",
"licenseDeclared": "MIT", "licenseDeclared": "MIT",
"name": "termion", "name": "libredox",
"versionInfo": "3.0.0" "versionInfo": "0.0.2"
},
{
"SPDXID": "SPDXRef-Package-bitflags-2.5.0",
"description": "A macro to generate structures which behave like bitflags.\n",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/bitflags@2.5.0",
"referenceType": "purl"
}
],
"homepage": "https://github.com/bitflags/bitflags",
"licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0",
"name": "bitflags",
"versionInfo": "2.5.0"
},
{
"SPDXID": "SPDXRef-Package-pride-0.4.1",
"description": "Pride flags in the terminal.",
"downloadLocation": "NONE",
"homepage": "https://git.vwolfe.io/valerie/pride",
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "pride",
"versionInfo": "0.4.1"
},
{
"SPDXID": "SPDXRef-Package-pico-args-0.5.0",
"description": "An ultra simple CLI arguments parser.",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/pico-args@0.5.0",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "pico-args",
"versionInfo": "0.5.0"
} }
], ],
"relationships": [ "relationships": [
{ {
"relatedSpdxElement": "SPDXRef-Package-numtoa-0.1.0", "relatedSpdxElement": "SPDXRef-Package-libc-0.2.151",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-3.0.0" "spdxElementId": "SPDXRef-Package-termion-2.0.3"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-pico-args-0.5.0", "relatedSpdxElement": "SPDXRef-Package-libc-0.2.151",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-pride-0.4.1" "spdxElementId": "SPDXRef-Package-libredox-0.0.2"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-libc-0.2.155", "relatedSpdxElement": "SPDXRef-Package-bitflags-2.4.1",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-3.0.0" "spdxElementId": "SPDXRef-Package-libredox-0.0.2"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-termion-3.0.0", "relatedSpdxElement": "SPDXRef-Package-pride-0.3.1",
"relationshipType": "DEPENDS_ON", "relationshipType": "GENERATED_FROM",
"spdxElementId": "SPDXRef-Package-pride-0.4.1" "spdxElementId": "SPDXRef-File-pride"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-bitflags-1.3.2", "relatedSpdxElement": "SPDXRef-Package-bitflags-1.3.2",
@ -205,32 +205,32 @@
"spdxElementId": "SPDXRef-Package-redox_syscall-0.4.1" "spdxElementId": "SPDXRef-Package-redox_syscall-0.4.1"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-pride-0.4.1", "relatedSpdxElement": "SPDXRef-Package-pico-args-0.5.0",
"relationshipType": "GENERATED_FROM",
"spdxElementId": "SPDXRef-File-pride"
},
{
"relatedSpdxElement": "SPDXRef-Package-libredox-0.0.2",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-3.0.0" "spdxElementId": "SPDXRef-Package-pride-0.3.1"
},
{
"relatedSpdxElement": "SPDXRef-Package-redox_syscall-0.4.1",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-libredox-0.0.2"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-redox_termios-0.1.3", "relatedSpdxElement": "SPDXRef-Package-redox_termios-0.1.3",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-3.0.0" "spdxElementId": "SPDXRef-Package-termion-2.0.3"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-libc-0.2.155", "relatedSpdxElement": "SPDXRef-Package-numtoa-0.1.0",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-libredox-0.0.2" "spdxElementId": "SPDXRef-Package-termion-2.0.3"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-bitflags-2.5.0", "relatedSpdxElement": "SPDXRef-Package-termion-2.0.3",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-pride-0.3.1"
},
{
"relatedSpdxElement": "SPDXRef-Package-libredox-0.0.2",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-2.0.3"
},
{
"relatedSpdxElement": "SPDXRef-Package-redox_syscall-0.4.1",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-libredox-0.0.2" "spdxElementId": "SPDXRef-Package-libredox-0.0.2"
} }

View file

@ -9,9 +9,7 @@ use termion::{
use crate::{ use crate::{
color::*, color::*,
draw, draw,
error,
flag::{ self, Flag }, flag::{ self, Flag },
state::State,
util::{ ansi_len, ansi_substr } util::{ ansi_len, ansi_substr }
}; };
@ -29,7 +27,7 @@ pub static TRIANGLE_21: [char; 3] = ['', '🭬', ''];
/// 2/3 slope slant /// 2/3 slope slant
pub static SLANT_23: [char; 2] = ['🭒', '🭏']; pub static SLANT_23: [char; 2] = ['🭒', '🭏'];
pub fn progress(state: &State) -> Flag { pub fn progress(small: bool) -> Flag {
let red = bg(0xE50000); let red = bg(0xE50000);
let orange = bg(0xFF8D00); let orange = bg(0xFF8D00);
let yellow = bg(0xFFEE00); let yellow = bg(0xFFEE00);
@ -44,8 +42,7 @@ pub fn progress(state: &State) -> Flag {
let pink: u32 = 0x7ACBF5; let pink: u32 = 0x7ACBF5;
let white: u32 = 0xFFFFFF; let white: u32 = 0xFFFFFF;
let (width, height) = state.size.get(18, 6); let (width, height) = if small { (18, 6) } else { terminal_size().unwrap() };
if height < 6 || width < 6 { error::too_small(width, height); }
// create color slices and line buffer // create color slices and line buffer
let stripes = [red, orange, yellow, green, blue, purple]; let stripes = [red, orange, yellow, green, blue, purple];
@ -58,7 +55,7 @@ pub fn progress(state: &State) -> Flag {
// set up constraints // set up constraints
let linecount = height - (height % 6); // largest multiple of 6 smaller than height let linecount = height - (height % 6); // largest multiple of 6 smaller than height
let full_depth = width / 3; let full_depth = width / 3;
let chevron_width = if full_depth > 6 { (full_depth / 6) - 1 } else { 0 }; let chevron_width = (full_depth / 6) - 1;
let direction_thresh = linecount / 2; let direction_thresh = linecount / 2;
let corner = linecount % 2 == 1; let corner = linecount % 2 == 1;
@ -99,14 +96,17 @@ pub fn progress(state: &State) -> Flag {
// grab our substring constraints // grab our substring constraints
let start = (direction_thresh - n) as usize - 1; let start = (direction_thresh - n) as usize - 1;
let diff = if display_length >= start { display_length - start } else { 0 }; let diff = display_length - start;
// take substring of chevron line... // take substring of chevron line...
let mut line = ansi_substr(&base, start as usize, base_length); let mut line = ansi_substr(&base, start as usize, base_length);
line += &stripes[index].to_string();
if diff > 0 { line.push(TRIANGLE_21[0]); }
// ... and add the colored stripe // ... and add the colored stripe
line += &" ".repeat(width as usize - diff); line += &format!(
"{stripe}{separator}{line}",
stripe = stripes[index],
separator = TRIANGLE_21[0],
line = " ".repeat(width as usize - diff)
);
lines.push(line); lines.push(line);
line_no += 1; line_no += 1;
@ -132,12 +132,15 @@ pub fn progress(state: &State) -> Flag {
if index > 5 { break; } if index > 5 { break; }
let start = n as usize; let start = n as usize;
let diff = if display_length >= start { display_length - start } else { 0 }; let diff = display_length - start;
let mut line = ansi_substr(&base, start, base_length); let mut line = ansi_substr(&base, start, base_length);
line += &stripes[index].to_string(); line += &format!(
if diff > 0 { line.push(TRIANGLE_21[2]); } "{stripe}{separator}{line}",
line += &" ".repeat(width as usize - diff); stripe = stripes[index],
separator = TRIANGLE_21[2],
line = " ".repeat(width as usize - diff)
);
lines.push(line); lines.push(line);
line_no += 1; line_no += 1;
@ -148,13 +151,12 @@ pub fn progress(state: &State) -> Flag {
// everything below this point is in alphabetical order // everything below this point is in alphabetical order
pub fn aroace_halves(state: &State) -> Flag { pub fn aroace(small: bool) -> Flag {
// pull colors from aro & ace stripe flags // pull colors from aro & ace stripe flags
let Flag::Stripes(aro) = flag::aromantic() else { panic!() }; let Flag::Stripes(aro) = flag::aromantic() else { panic!() };
let Flag::Stripes(ace) = flag::asexual() else { panic!() }; let Flag::Stripes(ace) = flag::asexual() else { panic!() };
let (width, height) = state.size.get(60, 20); let (width, height) = if small { (60, 20) } else { terminal_size().unwrap() };
if height < 20 { error::too_small(width, height); }
let mut lines: Vec<String> = Vec::new(); let mut lines: Vec<String> = Vec::new();
@ -183,8 +185,6 @@ pub fn aroace_halves(state: &State) -> Flag {
fn demi_orientation_render(middle: Bg<Rgb>, bottom: Bg<Rgb>, width: u16, height: u16) -> Vec<String> { fn demi_orientation_render(middle: Bg<Rgb>, bottom: Bg<Rgb>, width: u16, height: u16) -> Vec<String> {
let white = bg(0xFFFFFF); let white = bg(0xFFFFFF);
if height < 5 { error::too_small(width, height); }
let stripes = vec![white, white, middle, bottom, bottom]; let stripes = vec![white, white, middle, bottom, bottom];
// initial stripe output buffer // initial stripe output buffer
@ -219,21 +219,21 @@ fn demi_orientation_render(middle: Bg<Rgb>, bottom: Bg<Rgb>, width: u16, height:
lines lines
} }
pub fn demiromantic(state: &State) -> Flag { pub fn demiromantic(small: bool) -> Flag {
let green = bg(0x3DA542); let green = bg(0x3DA542);
let gray = bg(0xD2D2D2); let gray = bg(0xD2D2D2);
let (width, height) = state.size.get(15, 5); let (width, height) = if small { (15, 5) } else { terminal_size().unwrap() };
let lines = demi_orientation_render(green, gray, width, height); let lines = demi_orientation_render(green, gray, width, height);
Flag::Lines(lines) Flag::Lines(lines)
} }
pub fn demisexual(state: &State) -> Flag { pub fn demisexual(small: bool) -> Flag {
let purple = bg(0x832FA8); let purple = bg(0x832FA8);
let grey = bg(0x7B868C); let grey = bg(0x7B868C);
let (width, height) = state.size.get(15, 5); let (width, height) = if small { (15, 5) } else { terminal_size().unwrap() };
let lines = demi_orientation_render(purple, grey, width, height); let lines = demi_orientation_render(purple, grey, width, height);
Flag::Lines(lines) Flag::Lines(lines)
@ -274,7 +274,7 @@ pub fn intersex() -> Flag {
} }
pub fn polyamory(state: &State) -> Flag { pub fn polyamory(small: bool) -> Flag {
let blue = rgb(0x019FE3); let blue = rgb(0x019FE3);
let magenta = rgb(0xE50051); let magenta = rgb(0xE50051);
let purple = rgb(0x340C46); let purple = rgb(0x340C46);
@ -285,8 +285,7 @@ pub fn polyamory(state: &State) -> Flag {
let semicircle = '\u{E0B6}'; let semicircle = '\u{E0B6}';
let separators = ['\u{E0BE}', '\u{E0BA}']; let separators = ['\u{E0BE}', '\u{E0BA}'];
let (width, height) = state.size.get(18, 6); let (width, height) = if small { (18, 6) } else { terminal_size().unwrap() };
if height < 6 { error::too_small(width, height); }
// create stripe array and line buffer // create stripe array and line buffer
let stripes = [magenta, purple]; // only stripes 2 and 3 need tracked let stripes = [magenta, purple]; // only stripes 2 and 3 need tracked

View file

@ -1,9 +1,6 @@
//! render handling code //! render handling code
use std::io::{ use std::io::{ self, Write };
self,
Write
};
use termion::{ use termion::{
terminal_size, terminal_size,
@ -12,56 +9,42 @@ use termion::{
color::{ Bg, Fg, Rgb }, color::{ Bg, Fg, Rgb },
cursor, cursor,
input::TermRead, input::TermRead,
raw::{ RawTerminal, IntoRawMode } raw::IntoRawMode
}; };
use crate::{ use crate::{
color::{ RESET, RESET_BG }, color::{ RESET, RESET_BG },
error, flag::Flag
flag::Flag,
state::{ Size, State }
}; };
pub static BLOCK: &str = ""; pub static BLOCK: &str = "";
pub static UHALF: &str = ""; pub static UHALF: &str = "";
/// prints a provided vec of lines to stdout /// prints a provided vec of lines to stdout
pub fn draw_full(lines: Vec<String>) { pub fn draw_lines(lines: Vec<String>, hold: bool) {
let mut stdout = io::stdout().into_raw_mode().unwrap(); let mut stdout = io::stdout().into_raw_mode().unwrap();
// get in position for draw
let count = lines.len() as u16; let count = lines.len() as u16;
for _ in 0..count { write!(stdout, "\n").ok(); } for _ in 0..count { write!(stdout, "\n").ok(); }
write!(stdout, "{}", cursor::Up(count)).ok(); write!(stdout, "{}", cursor::Up(count)).ok();
// clear screen and hide cursor if hold { write!(stdout, "{}{}", cursor::Hide, clear::All).ok(); }
write!(stdout, "{}{}", cursor::Hide, clear::All).ok();
// write lines
let down = cursor::Down(1); let down = cursor::Down(1);
for line in lines { for line in lines {
let left = cursor::Left(line.len() as u16); let left = cursor::Left(line.len() as u16);
write!(stdout, "{line}{left}{down}").ok(); write!(stdout, "{line}{left}{down}").ok();
} }
// clear formatting and flush buffer
write!(stdout, "{RESET}{RESET_BG}").ok(); write!(stdout, "{RESET}{RESET_BG}").ok();
stdout.flush().ok(); stdout.flush().ok();
if hold {
// hold for input let stdin = io::stdin();
let stdin = io::stdin(); for _ in stdin.keys() { break; }
for _ in stdin.keys() { break; } write!(stdout, "{}", clear::All).ok();
// clear and show cursor
write!(stdout, "{}{}", clear::All, cursor::Show).ok();
stdout.flush().ok();
}
pub fn draw_lines(lines: Vec<String>, state: &State) {
match state.size {
Size::Full => draw_full(lines),
_ => for line in lines { println!("{line}{RESET}{RESET_BG}") }
} }
write!(stdout, "{}", cursor::Show).ok();
stdout.flush().ok();
} }
/// generates lines for foreground colors provided as a vec of strings for the draw_lines method /// generates lines for foreground colors provided as a vec of strings for the draw_lines method
@ -115,19 +98,22 @@ pub fn bg_stripes(colors: Vec<Bg<Rgb>>, width: u16, height: u16) -> Vec<String>
impl Flag { impl Flag {
/// renders a flag to stdout /// renders a flag to stdout
pub fn draw(self, state: &State) { pub fn draw(self, hold: bool) {
let lines = match self { let lines = match self {
Flag::Stripes(colors) Flag::Stripes(colors)
=> { => {
let count = colors.len() as u16; let (width, height);
let (width, height) = state.size.get(count * 3, count); if hold { (width, height) = terminal_size().unwrap(); }
if height < count { error::too_small(width, height); } else {
height = colors.len() as u16;
width = height * 3;
}
fg_stripes(colors, width, height) fg_stripes(colors, width, height)
}, },
Flag::Lines(lines) Flag::Lines(lines)
=> lines => lines
}; };
draw_lines(lines, &state); draw_lines(lines, hold);
} }
} }

View file

@ -1,24 +0,0 @@
use std::process::exit;
pub fn unmatched_flag(target: String) {
println!("pride: no flag {target}");
exit(1);
}
pub fn size_missing() {
println!("pride: size flag requires a value");
exit(2);
}
pub fn size_error(value: &str) {
println!("pride: size '{value}' is invalid");
exit(2);
}
pub fn too_small(width: u16, height: u16) {
println!("pride: this flag must be bigger than {width}x{height}");
exit(3);
}

View file

@ -13,13 +13,13 @@ Display pride flags in the terminal.
usage: pride [flags] [name] usage: pride [flags] [name]
args: args:
<name> The pride flag to display <name> The pride flag to display
flags: flags:
-h, --help Shows this help text -h, --help Shows this help text
--version Show version information --version Show version information
-l, --list Prints a list of printable flags -l, --list Prints a list of printable flags
-s, --size [size] Sets the size of the output flag. -s, --small Prints a small version without holding
Use 'pride --list' to see a list of printable flags Use 'pride --list' to see a list of printable flags
@ -135,7 +135,7 @@ names:
println!("The 5-stripe lesbian flag designed by Emily Gwen in 2018. println!("The 5-stripe lesbian flag designed by Emily Gwen in 2018.
names: names:
'lesbian', 'wlw' 'lesbian'
variants: variants:
7-color 7-stripe flag, also designed in 2018 by Emily Gwen"); 7-color 7-stripe flag, also designed in 2018 by Emily Gwen");

View file

@ -1,35 +1,30 @@
//! main method module //! main method module
use std::{
io::{ stdout, IsTerminal },
process::exit
};
use pico_args::Arguments; use pico_args::Arguments;
mod color; mod color;
mod complex; mod complex;
mod draw; mod draw;
mod error;
mod flag; mod flag;
mod help; mod help;
mod state;
mod util; mod util;
mod variant; mod variant;
use crate::{ use crate::flag::Flag;
flag::Flag,
state::State
};
static VERSION: &str = env!("CARGO_PKG_VERSION"); static VERSION: &str = env!("CARGO_PKG_VERSION");
pub const FLAG_HELP: [&str;2] = [ "-h", "--help" ];
pub const FLAG_LIST: [&str;2] = [ "-l", "--list" ];
pub const FLAG_SIZE: [&str;2] = [ "-s", "--size"];
pub const FLAG_VERSION: [&str;2] = [ "-v", "--version" ];
fn main() { fn main() {
// collect args // collect args
let mut args = Arguments::from_env(); let mut args = Arguments::from_env();
// handle help flag // handle help flag
if args.contains(FLAG_HELP) { if args.contains(["-h", "--help"]) {
let target = args.subcommand().unwrap(); let target = args.subcommand().unwrap();
if target.is_some() { help::flag_help(&target.unwrap()); } if target.is_some() { help::flag_help(&target.unwrap()); }
else { help::help_text(); } else { help::help_text(); }
@ -37,21 +32,27 @@ fn main() {
} }
// handle list flag // handle list flag
if args.contains(FLAG_LIST) { if args.contains(["-l", "--list"]) {
help::list_text(); help::list_text();
return; return;
} }
// handle version flag // handle version flag
if args.contains(FLAG_VERSION) { if args.contains(["-v", "--version"]) {
println!("pride v{VERSION}"); println!("pride v{VERSION}");
return; return;
} }
let state = State::new(&mut args); if !stdout().is_terminal() {
println!("pride: output must be a terminal");
exit(2);
}
let subcommand = args.subcommand().unwrap(); // get small flag
let variant = args.subcommand().unwrap(); let small = args.contains(["-s", "--small"]);
let subcommand = args.subcommand().unwrap();
let variant = args.subcommand().unwrap_or(None);
// get color vec from matched flag // get color vec from matched flag
let flag: Flag = match subcommand.as_deref() { let flag: Flag = match subcommand.as_deref() {
@ -64,14 +65,14 @@ fn main() {
Some("philadelphia") Some("philadelphia")
=> variant::philadelphia(), => variant::philadelphia(),
Some("progress") Some("progress")
=> complex::progress(&state), => complex::progress(small),
_ _
=> flag::pride() => flag::pride()
} }
}, },
Some("progress") Some("progress")
=> complex::progress(&state), => complex::progress(small),
Some("agender") Some("agender")
@ -87,7 +88,7 @@ fn main() {
=> { => {
match variant.as_deref() { match variant.as_deref() {
Some("halves" | "side-by-side" | "sbs") Some("halves" | "side-by-side" | "sbs")
=> complex::aroace_halves(&state), => complex::aroace(small),
_ _
=> flag::aroace() => flag::aroace()
} }
@ -108,10 +109,10 @@ fn main() {
=> flag::demigirl(), => flag::demigirl(),
Some("demiromantic") Some("demiromantic")
=> complex::demiromantic(&state), => complex::demiromantic(small),
Some("demisexual") Some("demisexual")
=> complex::demisexual(&state), => complex::demisexual(small),
// Some("disability") // Some("disability")
// => complex::disability(); // => complex::disability();
@ -137,7 +138,7 @@ fn main() {
// => complex::intersex(), // => complex::intersex(),
Some("lesbian" | "wlw") Some("lesbian")
=> { => {
match variant.as_deref() { match variant.as_deref() {
Some("7-color") Some("7-color")
@ -177,11 +178,15 @@ fn main() {
_ _
=> { error::unmatched_flag(subcommand.unwrap()); panic!() } => {
println!("pride: no flag '{}'", subcommand.unwrap());
help::help_text();
exit(1)
}
}; };
// draw flag // draw flag
flag.draw(&state); flag.draw(!small);
} }

View file

@ -1,66 +0,0 @@
use std::io::{ stdout, IsTerminal };
use pico_args::{ Arguments, Error };
use termion::terminal_size;
use crate::{ FLAG_SIZE, error };
#[derive(PartialEq)]
pub enum Size {
Full,
Small,
Set(u16, u16),
Wide(u16)
}
impl Size {
pub fn from(value: &str) -> Size {
if value == "small" { return Size::Small; }
let split: Vec<&str> = value.split('x').collect();
let len = split.len();
if len == 2 {
if let (Ok(width), Ok(height)) = (str::parse::<u16>(split.get(0).unwrap()), str::parse::<u16>(split.get(1).unwrap())) {
return Size::Set(width, height);
}
} else if len == 1 {
if let Ok(width) = str::parse::<u16>(split.get(0).unwrap()) {
return Size::Wide(width);
}
}
error::size_error(value);
panic!();
}
pub fn get(&self, width: u16, height: u16) -> (u16, u16) {
match self {
Size::Full => terminal_size().unwrap(),
Size::Set(width, height) => (width.clone(), height.clone()),
Size::Small => (width, height),
Size::Wide(width) => (width.clone(), height)
}
}
}
pub struct State {
pub size: Size,
pub is_terminal: bool,
}
impl State {
pub fn new(args: &mut Arguments) -> State {
let is_terminal = stdout().is_terminal();
let size = match args.value_from_str::<[&str;2], String>(FLAG_SIZE).as_deref() {
Ok(value) => Size::from(value),
Err(Error::MissingOption(_)) |
Err(Error::MissingArgument) => if is_terminal { Size::Full } else { Size::Small },
Err(Error::OptionWithoutAValue(_)) => Size::Small,
_ => { error::size_missing(); panic!() }
};
State { size, is_terminal }
}
}

View file

@ -27,7 +27,7 @@ pub fn philadelphia() -> Flag {
Flag::Stripes(inner) Flag::Stripes(inner)
=> inner, => inner,
_ _
=> panic!("impossible enum variant") => { panic!("impossible enum variant"); }
}; };
colors.insert(0, BLACK); colors.insert(0, BLACK);
colors.insert(1, brown); colors.insert(1, brown);