diff options
author | Rory Dudley | 2024-02-16 22:36:31 -0700 |
---|---|---|
committer | Rory Dudley | 2024-02-16 22:36:31 -0700 |
commit | c101a8c2abf0c25fc75e4101a83ae56bc2a9b789 (patch) | |
tree | 03bb263871842cde18221e258b006da77c3a89aa /src/main.rs | |
parent | f7b6c2dae63a1ada4fd097b5714d93494003ea98 (diff) | |
download | dwarvish-c101a8c2abf0c25fc75e4101a83ae56bc2a9b789.tar.gz |
Capture SIGINT
Added logic to capture the interrupt signal. Using a rust crate called
'ctrlc' to do the heavy lifting. Program will simply reprint the prompt
on a new line if the interrup signal is detected.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 42fa2a9..f78e54d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use ctrlc; use std::fs; use std::io; use std::io::Write; @@ -78,6 +79,8 @@ fn eval(paths: &[&str], prompt: &str) { } fn main() { + // Define paths + // TODO: Hardcoded path should only be the fallback let paths = [ "/bin", "/sbin", @@ -87,7 +90,16 @@ fn main() { "/usr/local/sbin", ]; + // Set the prompt let prompt = "|> "; + // Handle signals + ctrlc::set_handler(move || { + print!("\n{}", prompt); + io::stdout().flush().unwrap(); + }) + .expect("Unable to set <C-c> handler"); + + // Begin evaluating commands eval(&paths, prompt); } |