diff --git a/src/main.rs b/src/main.rs index d4ce347..d43b637 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,26 @@ -use std::{io::stdin, process::Command}; +use std::{io::{stdin, stdout, Write}, process::Command}; fn main(){ - let mut input = String::new(); - stdin().read_line(&mut input).unwrap(); + loop { + // use the `>` character as the prompt + // need to explicitly flush this to ensure it prints before read_line + print!("> "); + stdout().flush(); - // read_line leaves a trailing newline, which trim removes - let command = input.trim(); + let mut input = String::new(); + stdin().read_line(&mut input).unwrap(); - Command::new(command) - .spawn() - .unwrap(); + let mut parts = input.trim().split_whitespace(); + let command = parts.next().unwrap(); + let args = parts; + + let mut child = Command::new(command) + .args(args) + .spawn() + .unwrap(); + + // don't accept another command until this one completes + child.wait(); + } } +