use clap::Parser;
use std::io::{self, Read};
use copyrat::{config::basic, run, ui::Selection};
fn main() {
let opt = basic::Config::parse();
let stdin = io::stdin();
let mut handle = stdin.lock();
let mut buffer = String::new();
handle.read_to_string(&mut buffer).unwrap();
let lines = buffer.split('\n').collect::<Vec<_>>();
let selection: Option<Selection> = run(&lines, &opt);
if selection.is_none() {
std::process::exit(1);
}
let Selection { text, .. } = selection.unwrap();
println!("{text}");
}