summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 3cb2a74..04d58eb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@ use recite::path::prefresh;
use recite::Poem;
use std::io::{self, Write};
use std::path::Path;
+use std::sync::{Arc, Mutex};
/// Starts the main shell loop
///
@@ -20,7 +21,7 @@ use std::path::Path;
/// repl(&path, prompt);
/// }
/// ```
-fn repl(path: &Vec<&Path>, prompt: &str) {
+fn repl(path: &Vec<&Path>, prompt: &str, at_prompt: &mut Arc<Mutex<bool>>) {
// Initial path refresh on startup
let mut bins: Vec<String> = prefresh(path);
@@ -30,6 +31,9 @@ fn repl(path: &Vec<&Path>, prompt: &str) {
print!("{}", prompt);
io::stdout().flush().unwrap();
+ // At the prompt
+ *at_prompt.lock().unwrap() = true;
+
// Wait for user input
let mut poetry = String::new();
let bytes = io::stdin()
@@ -50,6 +54,9 @@ fn repl(path: &Vec<&Path>, prompt: &str) {
continue;
}
+ // Not at the prompt
+ *at_prompt.lock().unwrap() = false;
+
// Parse a poem
let poem = Poem::read(poetry);
match poem {
@@ -80,16 +87,22 @@ fn main() {
// Set the prompt
let prompt = "|> ";
+ let mut at_prompt = Arc::new(Mutex::new(false));
// Handle signals
unsafe {
+ let at_prompt = Arc::clone(&at_prompt);
signal_hook::low_level::register(signal_hook::consts::SIGINT, move || {
- print!("\n{}", prompt);
- io::stdout().flush().unwrap();
+ if *at_prompt.lock().unwrap() {
+ print!("\n{}", prompt);
+ io::stdout().flush().unwrap();
+ } else {
+ println!();
+ }
})
.unwrap();
};
// Begin evaluating commands
- repl(&path, prompt);
+ repl(&path, prompt, &mut at_prompt);
}