From 5d965f1f24b6ea74613688bd45f1f2c42f3e4cef Mon Sep 17 00:00:00 2001 From: Odysseas Stavrou Date: Wed, 24 Nov 2021 14:07:36 +0200 Subject: [PATCH] Help Message for Interactive shell --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/main.rs | 26 ++++++++++++++------------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc74a35..9211b1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,7 @@ dependencies = [ "clap", "colored", "log", + "pad", "rand 0.8.4", "serialport", "simplelog", @@ -291,6 +292,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "pad" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ad9b889f1b12e0b9ee24db044b5129150d5eada288edc800f789928dc8c0e3" +dependencies = [ + "unicode-width", +] + [[package]] name = "pkg-config" version = "0.3.22" diff --git a/Cargo.toml b/Cargo.toml index 9c3e81e..38d1156 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +pad = "0.1.6" sudoku = "0.7.0" anyhow = "1.0.44" serialport = "4.0.1" diff --git a/src/main.rs b/src/main.rs index 099bc35..9408069 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use colored::*; use std::thread; +use pad::PadStr; use std::fs::File; use std::time::Duration; use structopt::StructOpt; @@ -422,7 +423,7 @@ fn go_interactive(port: &mut Port, sudoku: &lib::SudokuAvr, flag: bool) -> Resul continue; } lib::write_uart(port, [b'N', x, y, z, b'\x0D', b'\x0A'].as_ref())?; - lib::wait_response(port, b"OK\x0D\x0A")?; + lib::wait_response(port, OK)?; }, "debug" => { if user_input_vec.len() > 3 { @@ -483,15 +484,16 @@ fn recv_and_check(port: &mut Port, sudoku: &lib::SudokuAvr) -> Result<()> { fn print_help() { - println!("{}", "Available Commands: ".yellow()); - println!("at"); - println!("download"); - println!("break"); - println!("fill"); - println!("debug"); - println!("exit"); - println!("clear"); - println!("solution"); - println!("unsolved"); - println!("help | '?' "); + println!("{}", "Available Commands: ".yellow().bold()); + println!("{}{}", "at".pad_to_width(20), "Attention"); + println!("{}{}", "clear".pad_to_width(20), "Clear Board"); + println!("{}{}", "play".pad_to_width(20), "Play Game"); + println!("{}{}", "fill".pad_to_width(20), "Fill Cell [x y num]"); + println!("{}{}", "solution".pad_to_width(20), "Print Solution"); + println!("{}{}", "unsolved".pad_to_width(20), "Print Board"); + println!("{}{}", "download".pad_to_width(20), "Download Board to AVR"); + println!("{}{}", "break".pad_to_width(20), "Break"); + println!("{}{}", "debug".pad_to_width(20), "Return the contents of a Cell [x y num]"); + println!("{}{}", "exit".pad_to_width(20), "Exit"); + println!("{}{}", "help or ?".pad_to_width(20), "Print this Help message"); }