diff options
author | Rory Dudley | 2024-03-30 19:05:23 -0600 |
---|---|---|
committer | Rory Dudley | 2024-03-30 19:05:23 -0600 |
commit | d408624afeb0035217d3d327e21b24a62b803f28 (patch) | |
tree | 891f52eb69f827ca71de157ab67f51606c7b40f0 /src/main.rs | |
parent | 491d3fbff384d4b04483b54e5bb78d23bb1181c5 (diff) | |
download | dwarvish-d408624afeb0035217d3d327e21b24a62b803f28.tar.gz |
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.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 11 |
1 files changed, 6 insertions, 5 deletions
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<Mutex<bool>>) { +fn repl(prompt: &str, at_prompt: &mut Arc<Mutex<bool>>, env: &mut Environment) { // Initial path refresh on startup - let mut bins: Vec<String> = path::refresh(); + env.bins = path::refresh(); // Main shell loop loop { @@ -67,7 +68,7 @@ fn repl(prompt: &str, at_prompt: &mut Arc<Mutex<bool>>) { }; // 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); } |