Meilleur contrôle de l'exécution du programme

La commande en cours d'écriture n'est pas envoyée au parser si EOF est
envoyé
This commit is contained in:
Hippolyte Chauvin 2023-10-28 15:41:09 +02:00
parent 4c70fda118
commit 50c6647ad4

View file

@ -5,9 +5,10 @@ mod parser;
fn main() {
let mut buffer = String::new();
let mut result_bytes_read: io::Result<usize> = Ok(1);
let mut result_bytes_read: io::Result<usize>;
let mut bytes_read: usize = 1;
while result_bytes_read.unwrap() != 0 {
while bytes_read != 0 {
buffer.clear();
print!("$ ");
@ -16,12 +17,15 @@ fn main() {
}
result_bytes_read = io::stdin().read_line(&mut buffer);
if !result_bytes_read.is_err() {
let command_vec: Vec<String> = parser::parse(&buffer);
println!("{:?}", command_vec);
} else {
if result_bytes_read.is_err() {
eprintln!("error: invalid UTF-8 characters were read");
result_bytes_read = Ok(1);
bytes_read = 1;
} else {
bytes_read = result_bytes_read.unwrap();
if bytes_read != 0 {
let command_vec: Vec<String> = parser::parse(&buffer);
println!("{:?}", command_vec);
}
}
}
}