use std::io;
use clap::Parser;
use rascii_art::{
charsets,
RenderOptions,
};
use unicode_segmentation::UnicodeSegmentation;
#[derive(Debug, Parser)]
#[command(author, version, about)]
struct Args {
filename: String,
#[arg(short, long)]
width: Option<u32>,
#[arg(short = 'H', long)]
height: Option<u32>,
#[arg(name = "color", short, long)]
colored: bool,
#[arg(short, long)]
invert: bool,
#[arg(short = 'C', long, default_value = "default")]
charset: String,
}
fn main() -> image::ImageResult<()> {
let mut args = Args::parse();
let clusters = UnicodeSegmentation::graphemes(args.charset.as_str(), true).collect::<Vec<_>>();
let charset = charsets::from_str(args.charset.as_str()).unwrap_or(clusters.as_slice());
if args.width.is_none() && args.height.is_none() {
args.width = Some(80);
}
rascii_art::render(
&args.filename,
&mut io::stdout(),
&RenderOptions {
width: args.width,
height: args.height,
colored: args.colored,
invert: args.invert,
charset,
},
)?;
Ok(())
}