summaryrefslogtreecommitdiffstats
path: root/src/compose.rs
diff options
context:
space:
mode:
authorRory Dudley2024-03-30 19:05:23 -0600
committerRory Dudley2024-03-30 19:05:23 -0600
commitd408624afeb0035217d3d327e21b24a62b803f28 (patch)
tree891f52eb69f827ca71de157ab67f51606c7b40f0 /src/compose.rs
parent491d3fbff384d4b04483b54e5bb78d23bb1181c5 (diff)
downloaddwarvish-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/compose.rs')
-rw-r--r--src/compose.rs19
1 files changed, 13 insertions, 6 deletions
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());