summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index d5147ff..527fb8c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,7 +25,12 @@ use termios::{tcsetattr, Termios, ECHO, ICANON, TCSANOW};
/// repl(&mut away, &mut env);
/// }
/// ```
-fn repl(away: &mut Arc<Mutex<bool>>, buffer: &mut Arc<Mutex<Vec<u8>>>, env: &mut Environment) {
+fn repl(
+ away: &mut Arc<Mutex<bool>>,
+ buffer: &mut Arc<Mutex<Vec<u8>>>,
+ pos: &mut Arc<Mutex<usize>>,
+ env: &mut Environment,
+) {
// Setup termios flags
let mut termios = Termios::from_fd(STDIN).unwrap();
termios.c_lflag &= !(ICANON | ECHO);
@@ -55,7 +60,7 @@ fn repl(away: &mut Arc<Mutex<bool>>, buffer: &mut Arc<Mutex<Vec<u8>>>, env: &mut
*away.lock().unwrap() = false;
// Wait for user input
- let bytes = getline(buffer);
+ let bytes = getline(buffer, pos);
// Check if we've reached EOF (i.e. <C-d>)
if bytes == 0 {
@@ -145,11 +150,14 @@ fn main() {
// Handle signals
let mut away = Arc::new(Mutex::new(true));
let mut buffer: Arc<Mutex<Vec<u8>>> = Arc::new(Mutex::new(vec![]));
+ let mut pos: Arc<Mutex<usize>> = Arc::new(Mutex::new(0));
unsafe {
let away = Arc::clone(&away);
let buffer = Arc::clone(&buffer);
+ let pos = Arc::clone(&pos);
signal_hook::low_level::register(signal_hook::consts::SIGINT, move || {
buffer.lock().unwrap().clear();
+ *pos.lock().unwrap() = 0;
if *away.lock().unwrap() {
println!();
} else {
@@ -168,5 +176,5 @@ fn main() {
options(&mut env);
// Begin evaluating commands
- repl(&mut away, &mut buffer, &mut env);
+ repl(&mut away, &mut buffer, &mut pos, &mut env);
}