diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-02-21 11:46:09 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-02-21 11:47:08 +0200 |
commit | ff6025a26312dd2e098fb2d6e3920eecffdad217 (patch) | |
tree | 97bf5bcaef1c6cc44aae0feb0cde78b35a0034e5 /src | |
parent | 0d4e33ca99f104336e93acd0bb9a5a06b427e5d8 (diff) |
Prompt in a loop
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index b40b9ca..f5f96b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,21 @@ -fn main() { - print!(">"); +use std::error::Error; +use std::{io, io::Write}; + +fn prompt() -> Result<(), Box<dyn Error>> { + print!("> "); + io::stdout().flush()?; + Ok(()) +} + +fn read_stdin() -> Result<String, Box<dyn Error>> { + let mut buffer = String::new(); + io::stdin().read_line(&mut buffer)?; + Ok(buffer) +} + +fn main() -> Result<(), Box<dyn Error>> { + loop { + prompt()?; + let _user_input = read_stdin()?; + } } |