diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 951c46f..ce5f611 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,31 +1,28 @@ use std::io::{self, Write}; -use std::path::Path; use std::sync::{Arc, Mutex}; mod path; mod poem; use poem::{read::Readable, recite::Reciteable, Poem}; +mod compose; /// Starts the main shell loop /// /// # Arguments -/// * `path` - A reference to a vector that holds a list to the shell $PATHs /// * `prompt` - A string slice indicating the shell's prompt /// * `at_prompt` - A mutex, indicating whether or not user is at the prompt /// /// # Examples /// ``` /// fn main() { -/// let path = vec!["/bin"]; -/// let path = path.into_iter().map(Path::new).collect(); /// let prompt = "|> "; /// let mut at_prompt = Arc::new(Mutex::new(false)); /// ... -/// repl(&path, prompt, &mut at_prompt); +/// repl(prompt, &mut at_prompt); /// } /// ``` -fn repl(path: &Vec<&Path>, prompt: &str, at_prompt: &mut Arc<Mutex<bool>>) { +fn repl(prompt: &str, at_prompt: &mut Arc<Mutex<bool>>) { // Initial path refresh on startup - let mut bins: Vec<String> = path::refresh(path); + let mut bins: Vec<String> = path::refresh(); // Main shell loop loop { @@ -70,7 +67,7 @@ fn repl(path: &Vec<&Path>, prompt: &str, at_prompt: &mut Arc<Mutex<bool>>) { }; // Recite the poem - match poem.recite(path, &mut bins, None) { + match poem.recite(&mut bins, None) { Ok(_) => {} Err(e) => eprintln!("dwvsh: {}", e.to_string().to_lowercase()), } @@ -81,17 +78,10 @@ fn repl(path: &Vec<&Path>, prompt: &str, at_prompt: &mut Arc<Mutex<bool>>) { /// /// Shell setup and entry fn main() { - // Define paths - // TODO: Hardcoded path should only be the fallback - let path = vec![ - "/bin", - "/sbin", - "/usr/bin", - "/usr/sbin", - "/usr/local/bin", - "/usr/local/sbin", - ]; - let path = path.into_iter().map(Path::new).collect(); + // Compose the environment for dwvsh + // TODO: All instances of `env!("HOME")` need to be changed to use env::var + // TODO: Will probably need to set $HOME in dwv{profile,login} via passwd + compose::env(); // Set the prompt let prompt = "|> "; @@ -112,5 +102,5 @@ fn main() { }; // Begin evaluating commands - repl(&path, prompt, &mut at_prompt); + repl(prompt, &mut at_prompt); } |