Compare commits
No commits in common. "a161aab0ca1045be9b337e566a532d00efccce0b" and "a62316c9f54c6f155cb346041d25f3d52bc76461" have entirely different histories.
a161aab0ca
...
a62316c9f5
3 changed files with 14 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pride"
|
name = "pride"
|
||||||
version = "0.4.3"
|
version = "0.4.2"
|
||||||
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."
|
||||||
|
@ -19,7 +19,6 @@ 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 = "4.0.3"
|
||||||
|
|
||||||
|
|
|
@ -85,13 +85,9 @@ The transgender pride flag designed by Monica Helms in 1999.
|
||||||
.Sh ENVIRONMENT
|
.Sh ENVIRONMENT
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It PRIDE_DEFAULT
|
.It PRIDE_DEFAULT
|
||||||
A string containing the name of one or more flags to use as the default when no
|
A string containing the name of a flag to use as the default when no
|
||||||
.Ar flag
|
.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
|
argument is provided.
|
||||||
.Ar flag
|
|
||||||
and
|
|
||||||
.Ar variant
|
|
||||||
arguments.
|
|
||||||
.El
|
.El
|
||||||
.Sh EXIT STATUS
|
.Sh EXIT STATUS
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -1,8 +1,5 @@
|
||||||
//! main method module
|
//! main method module
|
||||||
use std::{
|
use std::env::var;
|
||||||
env::var,
|
|
||||||
time::UNIX_EPOCH
|
|
||||||
};
|
|
||||||
|
|
||||||
use pico_args::Arguments;
|
use pico_args::Arguments;
|
||||||
|
|
||||||
|
@ -25,7 +22,7 @@ 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() {
|
||||||
|
@ -54,25 +51,13 @@ fn main() {
|
||||||
|
|
||||||
let state = State::new(&mut args);
|
let state = State::new(&mut args);
|
||||||
|
|
||||||
let ( subcommand, variant ) =
|
let subcommand =
|
||||||
if let Ok(Some(subcommand)) = args.subcommand() { ( Some(subcommand), args.subcommand().unwrap()) }
|
if let Ok(Some(subcommand)) = args.subcommand() { Some(subcommand) }
|
||||||
else if let Ok(default) = var("PRIDE_DEFAULT") {
|
else if let Ok(default) = var("PRIDE_DEFAULT") {
|
||||||
if default.is_empty() { ( None, None ) }
|
if default.is_empty() { None }
|
||||||
else if default.contains(';') {
|
else { Some(default) }
|
||||||
let split: Vec<&str> = default.split(';').collect();
|
} else { None };
|
||||||
if let Ok(time) = UNIX_EPOCH.elapsed() {
|
let variant = args.subcommand().unwrap();
|
||||||
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() {
|
||||||
|
|
Loading…
Reference in a new issue