From dc314144fdd2ea4f86d7e951770b0763ea22be78 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Fri, 24 Feb 2023 10:56:06 +0200 Subject: Exit --- src/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') 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> { fn main() -> Result<(), Box> { 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(()) } -- cgit v1.2.3