From a0d3ad8f018a0691ba35e52262493ebd1dd0cd63 Mon Sep 17 00:00:00 2001 From: David Senk Date: Thu, 7 Sep 2023 13:07:55 -0400 Subject: [PATCH] input loop --- src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.rs b/src/main.rs index e7a11a9..6e43406 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,23 @@ +use std::io; +use std::io::Write; + fn main() { println!("Hello, world!"); + + loop { + let mut input = String::new(); + print!("> "); + + io::stdout() + .flush() + .expect("flush to stdout should not fail"); + + io::stdin() + .read_line(&mut input) + .expect("failed to read line"); + + let output = input.trim(); + + println!("input received: '{output}'"); + } }