From fa9ee5f864cf88ae3a154f52461a37f675318946 Mon Sep 17 00:00:00 2001 From: Daniel Kluge Date: Thu, 18 Jan 2024 18:04:58 +0100 Subject: [PATCH] Make pwd accessible --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 223b3cf..d426d1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,7 +127,7 @@ checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasm-terminal" -version = "0.1.0" +version = "0.1.1" dependencies = [ "console_error_panic_hook", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 836e19a..f22a53c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasm-terminal" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["Daniel Kluge "] description = "Console application with commands in WASM for my website" diff --git a/src/lib.rs b/src/lib.rs index 6a4bb2a..2f4b070 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,7 +185,8 @@ impl Console { #[wasm_bindgen] impl Console { pub fn new() -> Console { - // TODO remove in release + + #[cfg(not(debug_assertions))] console_error_panic_hook::set_once(); let root = Rc::new(RefCell::new(Directory::new("".to_string(), "".to_string()))); @@ -205,6 +206,13 @@ impl Console { self.output.clone() } + pub fn get_pwd(&self) -> String { + match self.pwd.borrow().last() { + Some(dir) => dir.borrow().get_path(), + None => "/".to_string(), + } + } + pub fn get_last_commands(&self) -> Vec { self.last_commands.clone() }