From d408624afeb0035217d3d327e21b24a62b803f28 Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Sat, 30 Mar 2024 19:05:23 -0600 Subject: Add wrapper for global shell environment Instead of having to pass around a bunch of different data structures for various shell functions, create the wrapper compose::Environment, which serves as a global shell state. It is configured via login/profile/rc scripts initially, but can of course be modified throughout the lifetime of the shell. --- src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index ce5f611..898d19e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ mod path; mod poem; use poem::{read::Readable, recite::Reciteable, Poem}; mod compose; +use compose::Environment; /// Starts the main shell loop /// @@ -20,9 +21,9 @@ mod compose; /// repl(prompt, &mut at_prompt); /// } /// ``` -fn repl(prompt: &str, at_prompt: &mut Arc>) { +fn repl(prompt: &str, at_prompt: &mut Arc>, env: &mut Environment) { // Initial path refresh on startup - let mut bins: Vec = path::refresh(); + env.bins = path::refresh(); // Main shell loop loop { @@ -67,7 +68,7 @@ fn repl(prompt: &str, at_prompt: &mut Arc>) { }; // Recite the poem - match poem.recite(&mut bins, None) { + match poem.recite(env, None) { Ok(_) => {} Err(e) => eprintln!("dwvsh: {}", e.to_string().to_lowercase()), } @@ -81,7 +82,7 @@ fn main() { // 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(); + let mut env = compose::env(); // Set the prompt let prompt = "|> "; @@ -102,5 +103,5 @@ fn main() { }; // Begin evaluating commands - repl(prompt, &mut at_prompt); + repl(prompt, &mut at_prompt, &mut env); } -- cgit v1.2.3