From b9da0b289f0e0da3a8702638d25fdc9dadfcdc92 Mon Sep 17 00:00:00 2001 From: Federico Lolli <federico.lolli@skywarder.eu> Date: Wed, 20 Mar 2024 15:13:32 +0100 Subject: [PATCH] Moved cli in its own module and added color --- on-host/src/cli.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++ on-host/src/main.rs | 17 ++----------- 2 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 on-host/src/cli.rs diff --git a/on-host/src/cli.rs b/on-host/src/cli.rs new file mode 100644 index 0000000..a1a7483 --- /dev/null +++ b/on-host/src/cli.rs @@ -0,0 +1,58 @@ +use std::path::PathBuf; + +use clap::{ + builder::{ + styling::{AnsiColor, Color, Style}, + Styles, + }, + Parser, +}; + +#[derive(Debug, Parser)] +#[command(styles=get_styles())] +pub struct Cli { + /// The serial port to use + #[clap(short, long, value_name = "PORT")] + pub port: Option<String>, + + /// The input csv file to read from + pub csv_input: PathBuf, + + /// baud rate + #[clap(short, long, default_value = "115200")] + pub baud_rate: u32, +} + +pub fn get_styles() -> Styles { + Styles::styled() + .usage( + Style::new() + .bold() + .underline() + .fg_color(Some(Color::Ansi(AnsiColor::Yellow))), + ) + .header( + Style::new() + .bold() + .underline() + .fg_color(Some(Color::Ansi(AnsiColor::Yellow))), + ) + .literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Green)))) + .invalid( + Style::new() + .bold() + .fg_color(Some(Color::Ansi(AnsiColor::Red))), + ) + .error( + Style::new() + .bold() + .fg_color(Some(Color::Ansi(AnsiColor::Red))), + ) + .valid( + Style::new() + .bold() + .underline() + .fg_color(Some(Color::Ansi(AnsiColor::Green))), + ) + .placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::White)))) +} diff --git a/on-host/src/main.rs b/on-host/src/main.rs index 4f99928..96d885f 100644 --- a/on-host/src/main.rs +++ b/on-host/src/main.rs @@ -1,10 +1,10 @@ +mod cli; mod packet; mod utils; use std::{ fs::File, io::{self, Read}, - path::PathBuf, time::{Duration, Instant}, }; @@ -17,26 +17,13 @@ use skyward_mavlink::{ }; use crate::{ + cli::Cli, packet::PacketSequence, utils::{get_first_stm32_serial_port, print_stats}, }; const ACK: u8 = 0x06; -#[derive(Debug, Parser)] -struct Cli { - /// The serial port to use - #[clap(short, long, value_name = "PORT")] - port: Option<String>, - - /// The input csv file to read from - csv_input: PathBuf, - - /// baud rate - #[clap(short, long, default_value = "115200")] - baud_rate: u32, -} - fn main() { simple_logger::SimpleLogger::new() .with_level(log::LevelFilter::Info) -- GitLab