Compare commits
3 commits
1fc2c8adbd
...
eaa9622446
Author | SHA1 | Date | |
---|---|---|---|
eaa9622446 | |||
5584f49c87 | |||
fdcaa99feb |
3 changed files with 11 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::command::Command;
|
||||
use crate::exit_code::ExitCode;
|
||||
use crate::interface::{get_user_input, print_prompt};
|
||||
use crate::interface::get_user_input;
|
||||
use crate::parser::parse;
|
||||
|
||||
fn exit(code: &ExitCode) {
|
||||
|
@ -13,7 +13,6 @@ pub fn run() {
|
|||
let mut current_exit_code = ExitCode::new(0);
|
||||
|
||||
loop {
|
||||
print_prompt();
|
||||
let user_input = get_user_input();
|
||||
|
||||
if user_input.is_some() {
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
use std::io::Write;
|
||||
use std::io::{stdin, stdout};
|
||||
|
||||
pub fn print_prompt() {
|
||||
fn print_prompt() {
|
||||
print!("$ ");
|
||||
stdout().flush().unwrap();
|
||||
}
|
||||
|
||||
pub fn get_user_input() -> Option<String> {
|
||||
print_prompt();
|
||||
|
||||
let mut user_input = String::new();
|
||||
|
||||
let bytes_read = stdin()
|
||||
.read_line(&mut user_input)
|
||||
.expect("error reading user input");
|
||||
|
||||
if bytes_read == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(user_input)
|
||||
match bytes_read {
|
||||
0 => None,
|
||||
_ => Some(user_input),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,10 @@ fn parse_quote(characters: &mut Vec<char>) -> String {
|
|||
}
|
||||
|
||||
fn parse_backslash(characters: &mut Vec<char>) -> Option<char> {
|
||||
let mut escaped_char: Option<char> = None;
|
||||
|
||||
if !characters.is_empty() {
|
||||
escaped_char = Some(characters.pop().unwrap());
|
||||
}
|
||||
let escaped_char = match characters.is_empty() {
|
||||
false => Some(characters.pop().unwrap()),
|
||||
true => None,
|
||||
};
|
||||
|
||||
escaped_char
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue