diff --git a/src/cli.rs b/src/cli.rs index a9c7438..829aef7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -42,4 +42,14 @@ pub fn new() -> Command { .value_parser(value_parser!(f64)) .default_value("2.3"), ) + .arg( + Arg::new("charset") + .short('c') + .long("charset") + .help("Character set to use in ascending order of pixel value") + .action(ArgAction::Set) + .value_name("STRING") + .value_parser(value_parser!(String)) + .default_value(" .:-=+*%#@"), + ) } diff --git a/src/main.rs b/src/main.rs index c288286..d0c6a44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,14 +3,17 @@ use std::{fmt, fs::File, io, path::PathBuf}; mod cli; -const SYMBOLS: &[char] = &[' ', '.', ':', '-', '=', '+', '*', '#', '%', '@']; - fn main() -> Result<(), &'static str> { let matches = cli::new().get_matches(); let input_file: &PathBuf = matches.get_one("input").unwrap(); let x_stretch: f64 = *matches.get_one("x-stretch").unwrap(); let size: u32 = *matches.get_one("size").unwrap(); + let symbols = matches + .get_one::("charset") + .unwrap() + .chars() + .collect::>(); let img = image::open(input_file).unwrap(); let (w, h) = img.dimensions(); @@ -26,9 +29,9 @@ fn main() -> Result<(), &'static str> { .map(|(_, _, color)| { let sum: u16 = color.0.iter().take(3).map(|&v| v as u16).sum::(); let normalized = sum as f64 / (3.0 * 255.0); - let idx = (normalized * SYMBOLS.len() as f64).round() as usize; + let idx = (normalized * symbols.len() as f64) as usize; - SYMBOLS[idx] + symbols[idx] }) .collect::>() .chunks(w as usize)