diff --git a/ahnlich/Cargo.toml b/ahnlich/Cargo.toml index ff17122c..06b402bc 100644 --- a/ahnlich/Cargo.toml +++ b/ahnlich/Cargo.toml @@ -7,7 +7,9 @@ members = [ "typegen", "utils", "similarity", - "ai", "task-manager", + "ai", + "task-manager", + "cli", ] resolver = "2" diff --git a/ahnlich/cli/Cargo.toml b/ahnlich/cli/Cargo.toml new file mode 100644 index 00000000..027e7c9f --- /dev/null +++ b/ahnlich/cli/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cli" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "ahnlich_cli" +path = "src/main.rs" + + +[dependencies] +crossterm = "0.28.1" +clap.workspace = true +thiserror.workspace = true +ahnlich_client_rs = { path = "../client", version = "*" } diff --git a/ahnlich/cli/src/main.rs b/ahnlich/cli/src/main.rs new file mode 100644 index 00000000..39461dff --- /dev/null +++ b/ahnlich/cli/src/main.rs @@ -0,0 +1,46 @@ +use crossterm::{ + cursor::position, + event::{self, read, Event, KeyCode, KeyEvent}, + style::{self, Stylize}, + terminal, ExecutableCommand, QueueableCommand, +}; +use std::io::{self, Write}; +use std::time::Duration; + +const RESERVED_WORDS: [&str; 3] = ["hello", "print", "ping"]; + +pub fn read_line() -> io::Result { + let mut line = String::new(); + while let Event::Key(KeyEvent { code, .. }) = event::read()? { + match code { + KeyCode::Enter => { + break; + } + KeyCode::Char(c) => { + line.push(c); + } + KeyCode::Esc => { + break; + } + _ => {} + } + } + Ok(line) +} + +fn main() -> io::Result<()> { + let line = read_line()?; + + let output = String::from_iter(line.split(" ").map(|ex| { + if RESERVED_WORDS.contains(&ex) { + format!("{} ", ex.yellow()) + } else { + format!("{} ", ex.green()) + } + })); + + println!("read line:"); + println!("{output}"); + + Ok(()) +}