1use console::style;
2use libpt_cli::printing;
3use libpt_cli::repl::{DefaultRepl, Repl};
4use libpt_log::{debug, Logger};
5
6use clap::Subcommand;
7use strum::EnumIter;
8
9#[derive(Subcommand, Debug, EnumIter, Clone)]
11enum ReplCommand {
12 Wait {
14 len: u64,
16 },
17 Echo {
19 text: Vec<String>,
21 #[arg(short, long)]
23 fancy: bool,
24 },
25 Hello,
27 Exit,
29}
30
31fn main() -> anyhow::Result<()> {
32 let _logger = Logger::builder().display_time(false).build();
35
36 let mut repl = DefaultRepl::<ReplCommand>::default();
38
39 debug!("entering the repl");
40 loop {
41 match repl.step() {
44 Ok(c) => c,
45 Err(e) => {
46 if let libpt_cli::repl::error::Error::Parsing(e) = &e {
49 if e.kind() == clap::error::ErrorKind::DisplayHelp {
50 println!("{}", style(e).cyan());
51 continue;
52 }
53 }
54 println!("{}", style(e).red().bold());
55 continue;
56 }
57 };
58
59 match repl.command().to_owned().unwrap() {
63 ReplCommand::Exit => break,
64 ReplCommand::Wait { len } => {
65 debug!("len: {len}");
66 let spinner = indicatif::ProgressBar::new_spinner();
67 spinner.enable_steady_tick(std::time::Duration::from_millis(100));
68 std::thread::sleep(std::time::Duration::from_secs(len));
69 spinner.finish();
70 }
71 ReplCommand::Hello => println!("Hello!"),
72 ReplCommand::Echo { text, fancy } => {
73 if !fancy {
74 println!("{}", text.join(" "))
75 } else {
76 printing::blockprint(text.join(" "), console::Color::Cyan)
77 }
78 }
79 }
80 }
81 Ok(())
82}