mirror of
https://github.com/LukasKalbertodt/programmieren-in-rust.git
synced 2024-11-18 02:48:58 +01:00
36 lines
741 B
Rust
36 lines
741 B
Rust
|
|
||
|
fn main() {
|
||
|
loop {
|
||
|
// Read input from the user and just do nothing when the input is empty
|
||
|
let input = read_string();
|
||
|
if input.is_empty() {
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
// Debug output
|
||
|
println!("{}", input);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/// Reads a string from the user (with a nice prompt).
|
||
|
fn read_string() -> String {
|
||
|
use std::io::Write;
|
||
|
|
||
|
// Print prompt
|
||
|
print!("calc > ");
|
||
|
std::io::stdout().flush().unwrap();
|
||
|
|
||
|
// Read line
|
||
|
let mut buffer = String::new();
|
||
|
std::io::stdin()
|
||
|
.read_line(&mut buffer)
|
||
|
.expect("something went horribly wrong...");
|
||
|
|
||
|
// Discard trailing newline
|
||
|
let new_len = buffer.trim_right().len();
|
||
|
buffer.truncate(new_len);
|
||
|
|
||
|
buffer
|
||
|
}
|