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