use console::style;
use libpt_cli::printing;
use libpt_cli::repl::{DefaultRepl, Repl};
use libpt_log::{debug, Logger};
use clap::Subcommand;
use strum::EnumIter;
#[derive(Subcommand, Debug, EnumIter, Clone)]
enum ReplCommand {
Wait {
len: u64,
},
Echo {
text: Vec<String>,
#[arg(short, long)]
fancy: bool,
},
Hello,
Exit,
}
fn main() -> anyhow::Result<()> {
let _logger = Logger::builder().display_time(false).build();
let mut repl = DefaultRepl::<ReplCommand>::default();
debug!("entering the repl");
loop {
match repl.step() {
Ok(c) => c,
Err(e) => {
if let libpt_cli::repl::error::Error::Parsing(e) = &e {
if e.kind() == clap::error::ErrorKind::DisplayHelp {
println!("{}", style(e).cyan());
continue;
}
}
println!("{}", style(e).red().bold());
continue;
}
};
match repl.command().to_owned().unwrap() {
ReplCommand::Exit => break,
ReplCommand::Wait { len } => {
debug!("len: {len}");
let spinner = indicatif::ProgressBar::new_spinner();
spinner.enable_steady_tick(std::time::Duration::from_millis(100));
std::thread::sleep(std::time::Duration::from_secs(len));
spinner.finish();
}
ReplCommand::Hello => println!("Hello!"),
ReplCommand::Echo { text, fancy } => {
if !fancy {
println!("{}", text.join(" "))
} else {
printing::blockprint(text.join(" "), console::Color::Cyan)
}
}
}
}
Ok(())
}