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/compose.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/compose.rs') diff --git a/src/compose.rs b/src/compose.rs index 8c4b3ea..3d2a2db 100644 --- a/src/compose.rs +++ b/src/compose.rs @@ -1,8 +1,13 @@ use crate::poem::{read::Readable, recite::Reciteable, Poem}; +pub mod environment; +pub use environment::Environment; use std::fs; use std::path::PathBuf; -pub fn env() { +pub fn env() -> Environment { + // Create a new Environment object, to store some extra shell info + let mut env = Environment::new(); + // Use local repo path if running the debug target let global_rc = if cfg!(debug_assertions) { let mut base = PathBuf::from(env!("CARGO_MANIFEST_DIR")); @@ -17,11 +22,14 @@ pub fn env() { local_rc.push(".dwvshrc"); // Read, read, and recite - rrr(global_rc); - rrr(local_rc); + rrr(global_rc, &mut env); + rrr(local_rc, &mut env); + + // Return the new environment + env } -fn rrr(path: PathBuf) { +fn rrr(path: PathBuf, env: &mut Environment) { let poetry = match fs::read_to_string(&path) { Ok(poetry) => poetry, Err(e) => { @@ -47,8 +55,7 @@ fn rrr(path: PathBuf) { } }; - let mut bins = vec![]; - match poem.recite(&mut bins, None) { + match poem.recite(env, None) { Ok(_) => {} Err(e) => { eprintln!("dwvsh: {}", e.to_string().to_lowercase()); -- cgit v1.2.3