diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-02-24 10:56:06 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-02-24 10:56:06 +0200 |
commit | dc314144fdd2ea4f86d7e951770b0763ea22be78 (patch) | |
tree | f4a1df26ef21ea58d21688d39a556c47564faa23 /src | |
parent | ff6025a26312dd2e098fb2d6e3920eecffdad217 (diff) |
Exit
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index f5f96b4..93880de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,23 @@ fn read_stdin() -> Result<String, Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> { loop { prompt()?; - let _user_input = read_stdin()?; + let user_input = read_stdin()?; + + if user_input.len() == 0 { + // control-d or end of input. Needs to be specially handled before + // the match because this is identical to whitespace after the trim. + break; + } + + match user_input.trim() { + "" => {} + "exit" => { + break; + } + other_input => { + println!("Unknown input {}", other_input); + } + } } + Ok(()) } |