Skip to content

Commit

Permalink
Entry point into ahnlich cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamdavidonuh committed Sep 25, 2024
1 parent 7a72d9a commit c21f5dd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ahnlich/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ members = [
"typegen",
"utils",
"similarity",
"ai", "task-manager",
"ai",
"task-manager",
"cli",
]
resolver = "2"

Expand Down
15 changes: 15 additions & 0 deletions ahnlich/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = "*" }
46 changes: 46 additions & 0 deletions ahnlich/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
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(())
}

0 comments on commit c21f5dd

Please sign in to comment.