From feaa65e21aa33fbb1a7c69222a5d241c6dcd5341 Mon Sep 17 00:00:00 2001 From: able Date: Tue, 9 Mar 2021 20:31:31 -0600 Subject: [PATCH] Itchy --- .gitignore | 1 + Cargo.lock | 25 ++++++++++++++++++++ Cargo.toml | 10 ++++++++ src/main.rs | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..ec5dc3a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rash" +version = "0.1.0" +dependencies = [ + "toml", +] + +[[package]] +name = "serde" +version = "1.0.124" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4fdfb49 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "rash" +version = "0.1.0" +authors = ["able "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +toml="*" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..593c4a7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,68 @@ +// Rash +//Rusty bASH +// Really Awesome SHell +use std::io::Write; +use std::io::{stdin, stdout}; + +use toml::Value; + +const VALUE: &str = " +cursor='> ' +"; + +const VERSION: &str = "0.1.0"; +fn main() { + let value = VALUE.parse::().unwrap(); + let motd = "frick"; + let terminal_cursor = value["cursor"].as_str(); + + println!("{}", value); + + clear_term(); + println!("{}", motd); + + loop { + print!("{}", terminal_cursor.unwrap()); + let _err = stdout().flush(); // Excplicitly flush to ensure > gets printed + // handle the _err + let mut input = String::new(); + stdin().read_line(&mut input).unwrap(); // read_line leaves a trailing newline, which trim removes + let command = input.trim(); + match command { + "rush" => { + println!("Version: {}", VERSION); + } // Maybe parse via clap + "clear()" | "clean()" => { + clear_term(); + } + "random()" => { + println!("1"); // this has been decided as the cryptographically secure random + } + "script()" => { + let mut script = String::new(); + loop { + let mut line = String::new(); + stdin().read_line(&mut line).unwrap(); // read_line leaves a trailing + line = line.trim().to_string(); + if line == "end()" { + println!("{}", script); + break; + } else { + // append line to script + script = format!("{}\n{}", script, line); + } + } + } + "ls" => { + println!("bonk"); + } + _ => { + println!("Command {} not found", command); + } + } + } +} + +fn clear_term() { + print!("\x1B[2J\x1B[1;1H"); +}