Compare commits

..

1 commit
main ... state

Author SHA1 Message Date
0311f85f58 fixed errors printing to stdout instead of stderr 2024-07-12 10:48:50 -04:00
8 changed files with 133 additions and 173 deletions

View file

@ -1,11 +1,11 @@
[package] [package]
name = "pride" name = "pride"
version = "0.4.3" version = "0.4.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."
homepage = "https://git.sleeplessval.io/valerie/pride" homepage = "https://git.vwolfe.io/valerie/pride"
repository = "https://git.sleeplessval.io/valerie/pride" repository = "https://git.vwolfe.io/valerie/pride"
license = "MIT" license = "MIT"
categories = [ "command-line-utilities" ] categories = [ "command-line-utilities" ]
keywords = [ "lgbt", "pride", "cli" ] keywords = [ "lgbt", "pride", "cli" ]
@ -19,9 +19,8 @@ name = "pride"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
oorandom = '11.1.4'
pico-args = "0.5.0" pico-args = "0.5.0"
termion = "4.0.3" termion = "3.0.0"
[profile.release] [profile.release]
opt-level = 's' opt-level = 's'

View file

@ -3,7 +3,7 @@
A Rust utility to display pride flags in the terminal. A Rust utility to display pride flags in the terminal.
A list of currently implemented flags is available on the [project wiki](https://git.sleeplessval.io/valerie/pride/wiki/Flags). A list of currently implemented flags is available on the [project wiki](https://git.vwolfe.io/valerie/pride/wiki/Flags).
## Dependencies ## Dependencies
@ -16,7 +16,7 @@ slant symbols, and therefore require use of a Powerline font, such as [Fira Code
<details> <details>
<summary>Release Binary</summary> <summary>Release Binary</summary>
Copy the compiled binary from the <a href="https://git.sleeplessval.io/valerie/pride/releases/">releases page</a> Copy the compiled binary from the <a href="https://git.vwolfe.io/valerie/pride/releases/">releases page</a>
to a directory in <code>$PATH</code>, such as <code>/usr/bin/</code>. to a directory in <code>$PATH</code>, such as <code>/usr/bin/</code>.
</details> </details>
@ -46,13 +46,6 @@ using an AUR package manager such as <a href="https://github.com/Morganamilo/par
Install the package using Cargo with the command <code>cargo install pride-term</code>. Install the package using Cargo with the command <code>cargo install pride-term</code>.
</details> </details>
### Man Page
<details>
<summary>Section 6</summary>
Copy <code>man/pride.6</code> into <code>/usr/share/man/man6/</code>.
</details>
## Libraries ## Libraries
- [pico-args](https://crates.io/crates/pico-args) — argument parsing - [pico-args](https://crates.io/crates/pico-args) — argument parsing

View file

@ -55,7 +55,7 @@ The 5-stripe lesbian pride flag designed by Emily Gwen in 2018.
.Pp .Pp
VARIANTS VARIANTS
.Bl -tag -width Ds -compact .Bl -tag -width Ds -compact
.It Ic 7, 7-color, 7-stripe .It Ic 7-color
The 7-stripe lesbian pride flag designed by Emily Gwen in 2018. The 7-stripe lesbian pride flag designed by Emily Gwen in 2018.
.El .El
.It Ic multisexual, m-spec, mspec .It Ic multisexual, m-spec, mspec
@ -82,17 +82,6 @@ The rainbow flag designed for 2017 Philadelphia Pride.
.It Ic transgender, trans .It Ic transgender, trans
The transgender pride flag designed by Monica Helms in 1999. The transgender pride flag designed by Monica Helms in 1999.
.El .El
.Sh ENVIRONMENT
.Bl -tag -width Ds
.It PRIDE_DEFAULT
A string containing the name of one or more flags to use as the default when no
.Ar flag
argument is provided. If the string contains a semicolon-separated list of flags, a random one will be selected from the list. If a space is found in the chosen substring, it will be used to provide the
.Ar flag
and
.Ar variant
arguments.
.El
.Sh EXIT STATUS .Sh EXIT STATUS
.Bl -tag -width Ds .Bl -tag -width Ds
.It 1 .It 1

220
sbom.xml
View file

@ -1,13 +1,13 @@
{ {
"SPDXID": "SPDXRef-DOCUMENT", "SPDXID": "SPDXRef-DOCUMENT",
"creationInfo": { "creationInfo": {
"created": "2024-12-13T16:02:17.260Z", "created": "2024-07-05T20:16:51.403Z",
"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-93ad73c9-b337-4ad0-bd63-92e9b7d1a2d8", "documentNamespace": "https://spdx.org/spdxdocs/pride-6150510e-b518-43f0-aa53-3e2795909cc2",
"files": [ "files": [
{ {
"SPDXID": "SPDXRef-File-pride", "SPDXID": "SPDXRef-File-pride",
@ -21,62 +21,70 @@
"name": "pride", "name": "pride",
"packages": [ "packages": [
{ {
"SPDXID": "SPDXRef-Package-oorandom-11.1.4", "SPDXID": "SPDXRef-Package-redox_syscall-0.4.1",
"description": "A tiny, robust PRNG implementation.",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index",
"externalRefs": [
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/oorandom@11.1.4",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "oorandom",
"versionInfo": "11.1.4"
},
{
"SPDXID": "SPDXRef-Package-redox_syscall-0.5.7",
"description": "A Rust library to access raw Redox system calls", "description": "A Rust library to access raw Redox system calls",
"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/redox_syscall@0.5.7", "referenceLocator": "pkg:cargo/redox_syscall@0.4.1",
"referenceType": "purl" "referenceType": "purl"
} }
], ],
"licenseConcluded": "MIT", "licenseConcluded": "MIT",
"licenseDeclared": "MIT", "licenseDeclared": "MIT",
"name": "redox_syscall", "name": "redox_syscall",
"versionInfo": "0.5.7" "versionInfo": "0.4.1"
}, },
{ {
"SPDXID": "SPDXRef-Package-pride-0.4.3", "SPDXID": "SPDXRef-Package-libredox-0.0.2",
"description": "Pride flags in the terminal.", "description": "Redox stable ABI",
"downloadLocation": "NONE",
"homepage": "https://git.sleeplessval.io/valerie/pride",
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "pride",
"versionInfo": "0.4.3"
},
{
"SPDXID": "SPDXRef-Package-termion-4.0.3",
"description": "A bindless library for manipulating terminals.",
"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/termion@4.0.3", "referenceLocator": "pkg:cargo/libredox@0.0.2",
"referenceType": "purl" "referenceType": "purl"
} }
], ],
"licenseConcluded": "MIT", "licenseConcluded": "MIT",
"licenseDeclared": "MIT", "licenseDeclared": "MIT",
"name": "termion", "name": "libredox",
"versionInfo": "4.0.3" "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",
"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@1.3.2",
"referenceType": "purl"
}
],
"homepage": "https://github.com/bitflags/bitflags",
"licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT/Apache-2.0",
"name": "bitflags",
"versionInfo": "1.3.2"
}, },
{ {
"SPDXID": "SPDXRef-Package-redox_termios-0.1.3", "SPDXID": "SPDXRef-Package-redox_termios-0.1.3",
@ -95,30 +103,45 @@
"versionInfo": "0.1.3" "versionInfo": "0.1.3"
}, },
{ {
"SPDXID": "SPDXRef-Package-libc-0.2.167", "SPDXID": "SPDXRef-Package-numtoa-0.1.0",
"description": "Raw FFI bindings to platform libraries like libc.\n", "description": "Convert numbers into stack-allocated byte arrays",
"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/libc@0.2.167", "referenceLocator": "pkg:cargo/numtoa@0.1.0",
"referenceType": "purl" "referenceType": "purl"
} }
], ],
"homepage": "https://github.com/rust-lang/libc",
"licenseConcluded": "MIT OR Apache-2.0", "licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0", "licenseDeclared": "MIT OR Apache-2.0",
"name": "libc", "name": "numtoa",
"versionInfo": "0.2.167" "versionInfo": "0.1.0"
}, },
{ {
"SPDXID": "SPDXRef-Package-bitflags-2.6.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"
}
],
"licenseConcluded": "MIT",
"licenseDeclared": "MIT",
"name": "termion",
"versionInfo": "3.0.0"
},
{
"SPDXID": "SPDXRef-Package-bitflags-2.5.0",
"description": "A macro to generate structures which behave like bitflags.\n", "description": "A macro to generate structures which behave like bitflags.\n",
"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/bitflags@2.6.0", "referenceLocator": "pkg:cargo/bitflags@2.5.0",
"referenceType": "purl" "referenceType": "purl"
} }
], ],
@ -126,39 +149,17 @@
"licenseConcluded": "MIT OR Apache-2.0", "licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0", "licenseDeclared": "MIT OR Apache-2.0",
"name": "bitflags", "name": "bitflags",
"versionInfo": "2.6.0" "versionInfo": "2.5.0"
}, },
{ {
"SPDXID": "SPDXRef-Package-libredox-0.1.3", "SPDXID": "SPDXRef-Package-pride-0.4.1",
"description": "Redox stable ABI", "description": "Pride flags in the terminal.",
"downloadLocation": "registry+https://github.com/rust-lang/crates.io-index", "downloadLocation": "NONE",
"externalRefs": [ "homepage": "https://git.vwolfe.io/valerie/pride",
{
"referenceCategory": "PACKAGE-MANAGER",
"referenceLocator": "pkg:cargo/libredox@0.1.3",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT", "licenseConcluded": "MIT",
"licenseDeclared": "MIT", "licenseDeclared": "MIT",
"name": "libredox", "name": "pride",
"versionInfo": "0.1.3" "versionInfo": "0.4.1"
},
{
"SPDXID": "SPDXRef-Package-numtoa-0.2.4",
"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.2.4",
"referenceType": "purl"
}
],
"licenseConcluded": "MIT OR Apache-2.0",
"licenseDeclared": "MIT OR Apache-2.0",
"name": "numtoa",
"versionInfo": "0.2.4"
}, },
{ {
"SPDXID": "SPDXRef-Package-pico-args-0.5.0", "SPDXID": "SPDXRef-Package-pico-args-0.5.0",
@ -179,64 +180,59 @@
], ],
"relationships": [ "relationships": [
{ {
"relatedSpdxElement": "SPDXRef-Package-redox_termios-0.1.3", "relatedSpdxElement": "SPDXRef-Package-numtoa-0.1.0",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-4.0.3" "spdxElementId": "SPDXRef-Package-termion-3.0.0"
},
{
"relatedSpdxElement": "SPDXRef-Package-libc-0.2.167",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-4.0.3"
},
{
"relatedSpdxElement": "SPDXRef-Package-pride-0.4.3",
"relationshipType": "GENERATED_FROM",
"spdxElementId": "SPDXRef-File-pride"
},
{
"relatedSpdxElement": "SPDXRef-Package-bitflags-2.6.0",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-libredox-0.1.3"
},
{
"relatedSpdxElement": "SPDXRef-Package-libc-0.2.167",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-libredox-0.1.3"
},
{
"relatedSpdxElement": "SPDXRef-Package-libredox-0.1.3",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-4.0.3"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-pico-args-0.5.0", "relatedSpdxElement": "SPDXRef-Package-pico-args-0.5.0",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-pride-0.4.3" "spdxElementId": "SPDXRef-Package-pride-0.4.1"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-termion-4.0.3", "relatedSpdxElement": "SPDXRef-Package-libc-0.2.155",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-pride-0.4.3" "spdxElementId": "SPDXRef-Package-termion-3.0.0"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-redox_syscall-0.5.7", "relatedSpdxElement": "SPDXRef-Package-termion-3.0.0",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-libredox-0.1.3" "spdxElementId": "SPDXRef-Package-pride-0.4.1"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-numtoa-0.2.4", "relatedSpdxElement": "SPDXRef-Package-bitflags-1.3.2",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-4.0.3" "spdxElementId": "SPDXRef-Package-redox_syscall-0.4.1"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-oorandom-11.1.4", "relatedSpdxElement": "SPDXRef-Package-pride-0.4.1",
"relationshipType": "DEPENDS_ON", "relationshipType": "GENERATED_FROM",
"spdxElementId": "SPDXRef-Package-pride-0.4.3" "spdxElementId": "SPDXRef-File-pride"
}, },
{ {
"relatedSpdxElement": "SPDXRef-Package-bitflags-2.6.0", "relatedSpdxElement": "SPDXRef-Package-libredox-0.0.2",
"relationshipType": "DEPENDS_ON", "relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-redox_syscall-0.5.7" "spdxElementId": "SPDXRef-Package-termion-3.0.0"
},
{
"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",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-termion-3.0.0"
},
{
"relatedSpdxElement": "SPDXRef-Package-libc-0.2.155",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-libredox-0.0.2"
},
{
"relatedSpdxElement": "SPDXRef-Package-bitflags-2.5.0",
"relationshipType": "DEPENDS_ON",
"spdxElementId": "SPDXRef-Package-libredox-0.0.2"
} }
], ],
"spdxVersion": "SPDX-2.3" "spdxVersion": "SPDX-2.3"

View file

@ -1,6 +1,10 @@
//! flags that require more complex rendering than just scaling colored stripes //! flags that require more complex rendering than just scaling colored stripes
use termion::color::{ Bg, Rgb }; use termion::{
terminal_size,
color::{ Bg, Rgb }
};
use crate::{ use crate::{
color::*, color::*,

View file

@ -6,11 +6,13 @@ use std::io::{
}; };
use termion::{ use termion::{
terminal_size,
clear, clear,
color::{ Bg, Fg, Rgb }, color::{ Bg, Fg, Rgb },
cursor, cursor,
input::TermRead, input::TermRead,
raw::IntoRawMode raw::{ RawTerminal, IntoRawMode }
}; };
use crate::{ use crate::{
@ -118,7 +120,7 @@ impl Flag {
Flag::Stripes(colors) Flag::Stripes(colors)
=> { => {
let count = colors.len() as u16; let count = colors.len() as u16;
let (width, height) = state.size.get((count * 20 + 3) / 6, count); let (width, height) = state.size.get(count * 3, count);
if height < count { error::too_small(width, height); } if height < count { error::too_small(width, height); }
fg_stripes(colors, width, height) fg_stripes(colors, width, height)
}, },

View file

@ -130,7 +130,7 @@ names:
=> { println!("The gender-nonconforming pride flag.\n\nnames:\n 'gender-nonconforming', 'gendernonconforming', 'gnc'"); }, => { println!("The gender-nonconforming pride flag.\n\nnames:\n 'gender-nonconforming', 'gendernonconforming', 'gnc'"); },
"lesbian" | "wlw" "lesbian"
=> { => {
println!("The 5-stripe lesbian flag designed by Emily Gwen in 2018. println!("The 5-stripe lesbian flag designed by Emily Gwen in 2018.
@ -138,9 +138,7 @@ names:
'lesbian', 'wlw' 'lesbian', 'wlw'
variants: variants:
7 7-stripe flag, also designed in 2018 by Emily Gwen 7-color 7-stripe flag, also designed in 2018 by Emily Gwen");
7-color
7-stripe");
}, },

View file

@ -1,8 +1,4 @@
//! main method module //! main method module
use std::{
env::var,
time::UNIX_EPOCH
};
use pico_args::Arguments; use pico_args::Arguments;
@ -23,10 +19,10 @@ use crate::{
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_HELP: [&str;2] = [ "-h", "--help" ];
pub const FLAG_LIST: [&str;2] = [ "-l", "--list" ]; pub const FLAG_LIST: [&str;2] = [ "-l", "--list" ];
pub const FLAG_SIZE: [&str;2] = [ "-s", "--size" ]; pub const FLAG_SIZE: [&str;2] = [ "-s", "--size"];
pub const FLAG_VERSION: [&str;2] = [ "-v", "--version" ]; pub const FLAG_VERSION: [&str;2] = [ "-v", "--version" ];
fn main() { fn main() {
// collect args // collect args
@ -54,25 +50,8 @@ fn main() {
let state = State::new(&mut args); let state = State::new(&mut args);
let ( subcommand, variant ) = let subcommand = args.subcommand().unwrap();
if let Ok(Some(subcommand)) = args.subcommand() { ( Some(subcommand), args.subcommand().unwrap()) } let variant = args.subcommand().unwrap();
else if let Ok(default) = var("PRIDE_DEFAULT") {
if default.is_empty() { ( None, None ) }
else if default.contains(';') {
let split: Vec<&str> = default.split(';').collect();
if let Ok(time) = UNIX_EPOCH.elapsed() {
let index = oorandom::Rand32::new(time.as_secs()).rand_u32();
let chosen = split[index as usize % split.len()].to_owned();
if chosen.contains(' ') {
let split: Vec<&str> = chosen.split(' ').collect();
( Some(split[0].to_owned()), Some(split[1].to_owned()) )
} else { ( Some(chosen), None ) }
} else { ( None, None ) }
} else if default.contains(' ') {
let split: Vec<&str> = default.split(' ').collect();
( Some(split[0].to_owned()), Some(split[1].to_owned()) )
} else { ( Some(default), None ) }
} else { ( None, 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() {
@ -161,7 +140,7 @@ fn main() {
Some("lesbian" | "wlw") Some("lesbian" | "wlw")
=> { => {
match variant.as_deref() { match variant.as_deref() {
Some("7" | "7-color" | "7-stripe") Some("7-color")
=> variant::lesbian_7(), => variant::lesbian_7(),
_ _
=> flag::lesbian() => flag::lesbian()