From b981e37c2c0e5befd8cf1a55ceffe0a92f270b01 Mon Sep 17 00:00:00 2001 From: Peter Jiang <2892084432j@gmail.com> Date: Tue, 18 Jun 2024 22:48:01 -0400 Subject: [PATCH] handle EOF correctly --- core/src/command_console/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/command_console/mod.rs b/core/src/command_console/mod.rs index 2fa7067e..12a49fd0 100644 --- a/core/src/command_console/mod.rs +++ b/core/src/command_console/mod.rs @@ -38,7 +38,11 @@ pub fn init(app_state: AppState) { loop { let app_state = app_state.clone(); let mut input = String::new(); - std::io::stdin().read_line(&mut input).unwrap(); + let buf_size = std::io::stdin().read_line(&mut input).unwrap(); + if buf_size == 0 { + println!("EOF"); + break; + } let input_tokens = input.split_whitespace().collect::>(); match input_tokens.first() { Some(&"di") => { @@ -46,7 +50,7 @@ pub fn init(app_state: AppState) { handle_docker_command(&input_tokens[1..], app_state).await; } _ => { - println!("Unknown command"); + println!("Unknown command: {}", input); continue; } }