From 8b2814f254ef63d806bb5435b3d193458cfd4537 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 11 Oct 2020 14:11:40 +0300 Subject: Make Prompt more const --- src/main.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index a4f3c25..0581b13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,12 +5,19 @@ mod builtins; mod prompt; fn main() { - println!("rshell motd"); + match std::fs::read_to_string("/etc/motd") { + Ok(motd) => println!("{}", motd), + Err(_) => {}, + } - let mut prompt = prompt::Prompt::new(); + let prompt = prompt::Prompt::new(); + let mut cwd = match std::env::current_dir() { + Ok(p) => p, + Err(e) => panic!(e), + }; loop { - prompt.print(); + prompt.print(&cwd); let mut input = String::new(); match std::io::stdin().read_line(&mut input) { @@ -36,7 +43,7 @@ fn main() { match command { "cd" => { - prompt.pwd = builtins::cd(args); + cwd = builtins::cd(args); previous_command = None; } "exit" => return, @@ -70,7 +77,11 @@ fn main() { if let Some(mut final_command) = previous_command { match final_command.wait() { Ok(ret) => match ret.code() { - Some(code) => println!("exit code [{}]", code), + Some(code) => { + if cfg!(debug_assertions) { + println!("exit code [{}]", code); + } + }, None => println!("Process termed by signal"), }, Err(e) => eprintln!("error waiting on final command: {}", e), -- cgit v1.2.1