#[cfg(target_family = "windows")]
use std::{error, fmt, path::PathBuf};
use clap::Parser;
#[cfg(target_family = "windows")]
use glob::glob;
#[cfg(target_family = "windows")]
#[cfg(feature = "rayon")]
use rayon::prelude::*;
use crate::DEFAULT_ASCII_STRING;
#[derive(Parser, Debug, Default, Clone, PartialEq)]
#[clap(author, version, about, long_about = None)]
pub struct Cli {
#[clap(short, long, num_args = 1.., required=true)]
pub input: Vec<String>,
#[clap(short, long)]
pub width: Option<u32>,
#[clap(short = 'H', long)]
pub height: Option<u32>,
#[clap(short, long)]
pub framerate: Option<f64>,
#[clap(short, long, action)]
pub pre_render: bool,
#[clap(short, long = "loop", action)]
pub looped: bool,
#[clap(short, long, action)]
pub colored: bool,
#[clap(short, long, default_value_t = DEFAULT_ASCII_STRING.to_owned())]
pub ascii_string: String,
#[clap(long, action)]
pub pixels: bool,
#[clap(short, long, action)]
pub reverse: bool,
#[clap(long = "ratio")]
pub font_ratio: Option<f64>,
#[clap(short, long)]
pub threshold: Option<u32>,
#[clap(short, long, action)]
pub braille: bool,
#[clap(long)]
pub background_string: Option<String>,
}
#[cfg(target_family = "windows")]
pub fn glob_to_paths(patterns: &[String]) -> Result<Vec<PathBuf>, GlobToPathsError> {
#[cfg(feature = "rayon")]
let iter = patterns.into_par_iter();
#[cfg(not(feature = "rayon"))]
let iter = patterns.iter();
iter.map(|glob_p| {
glob(glob_p)?
.map(|path| Ok(path?))
.collect::<Result<Vec<PathBuf>, GlobToPathsError>>()
})
.flat_map(|result| match result {
Ok(vec) => vec.into_iter().map(Ok).collect(),
Err(e) => vec![Err(e)],
})
.collect()
}
#[cfg(target_family = "windows")]
#[derive(Debug)]
pub enum GlobToPathsError {
PatternError(glob::PatternError),
GlobError(glob::GlobError),
}
#[cfg(target_family = "windows")]
impl error::Error for GlobToPathsError {}
#[cfg(target_family = "windows")]
impl fmt::Display for GlobToPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GlobToPathsError::PatternError(err) => write!(f, "Pattern error: {}", err),
GlobToPathsError::GlobError(err) => write!(f, "Glob error: {}", err),
}
}
}
#[cfg(target_family = "windows")]
impl From<glob::PatternError> for GlobToPathsError {
fn from(err: glob::PatternError) -> GlobToPathsError {
GlobToPathsError::PatternError(err)
}
}
#[cfg(target_family = "windows")]
impl From<glob::GlobError> for GlobToPathsError {
fn from(err: glob::GlobError) -> GlobToPathsError {
GlobToPathsError::GlobError(err)
}
}