Moins de lignes dans main.rs
, délégation de l'appel de parse
à struct Buffer
This commit is contained in:
parent
b77b887081
commit
9022d04ca9
2 changed files with 11 additions and 12 deletions
13
src/input.rs
13
src/input.rs
|
@ -1,5 +1,6 @@
|
||||||
use std::io as stdio;
|
use std::io as stdio;
|
||||||
use stdio::stdin;
|
use stdio::stdin;
|
||||||
|
use crate::parser;
|
||||||
|
|
||||||
pub struct Buffer {
|
pub struct Buffer {
|
||||||
buffer: String,
|
buffer: String,
|
||||||
|
@ -27,11 +28,11 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn parse(&self) -> Option<Vec<String>> {
|
||||||
self.buffer.is_empty()
|
if ! self.buffer.is_empty() {
|
||||||
}
|
Some(parser::parse(&self.buffer))
|
||||||
|
} else {
|
||||||
pub fn get_buffer(&self) -> &String {
|
None
|
||||||
&self.buffer
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -7,17 +7,15 @@ mod parser;
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut buffer = input::Buffer::new();
|
let mut buffer = input::Buffer::new();
|
||||||
let mut bytes_read: usize = 1;
|
let mut bytes_read: usize = 1;
|
||||||
let mut command_line: String;
|
let mut argv: Option<Vec<String>>;
|
||||||
let mut argv: Vec<String>;
|
|
||||||
|
|
||||||
while bytes_read != 0 {
|
while bytes_read != 0 {
|
||||||
output::print_ps1();
|
output::print_ps1();
|
||||||
bytes_read = buffer.read_line();
|
bytes_read = buffer.read_line();
|
||||||
|
|
||||||
if ! buffer.is_empty() {
|
argv = buffer.parse();
|
||||||
command_line = buffer.get_buffer().to_string();
|
if argv.is_some() {
|
||||||
argv = parser::parse(&command_line);
|
println!("{:?}", argv.unwrap());
|
||||||
println!("{:?}", argv);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue