Nettoyage du code

This commit is contained in:
Hippolyte Chauvin 2023-11-01 14:42:25 +01:00
parent 6ca8606081
commit 7a92b46df5
2 changed files with 22 additions and 15 deletions

View file

@ -12,13 +12,26 @@ impl Buffer {
}
}
pub fn read_line(&mut self) -> stdio::Result<usize> {
pub fn read_line(&mut self) -> usize {
self.buffer.clear();
let result: stdio::Result<usize> = stdin().read_line(&mut self.buffer);
if result.is_err() {
eprintln!("error: invalid UTF-8 characters were read");
self.buffer.clear();
1
} else {
self.buffer = self.buffer.trim().to_string();
result.unwrap()
}
}
result
pub fn is_empty(&self) -> bool {
self.buffer.is_empty()
}
pub fn get_buffer(&self) -> &String {
&self.buffer
}
}

View file

@ -1,27 +1,21 @@
use std::io;
mod r#in;
mod r#out;
mod parser;
pub fn run() -> i32 {
let mut buffer = r#in::Buffer::new();
let mut bytes_read_result: io::Result<usize>;
let mut bytes_read: usize = 1;
let mut command_line: String;
let mut argv: Vec<String>;
while bytes_read != 0 {
out::print_ps1();
bytes_read_result = buffer.read_line();
bytes_read = buffer.read_line();
if bytes_read_result.is_err() {
bytes_read = 1;
} else {
bytes_read = bytes_read_result.unwrap();
if bytes_read != 0 {
//let command_vec: Vec<String> = parser::parse(&buffer);
//println!("{:?}", command_vec);
}
if ! buffer.is_empty() {
command_line = buffer.get_buffer().to_string();
argv = parser::parse(&command_line);
println!("{:?}", argv);
}
}