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/poem/recite.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/poem/recite.rs') diff --git a/src/poem/recite.rs b/src/poem/recite.rs index f2af591..e37b7c6 100644 --- a/src/poem/recite.rs +++ b/src/poem/recite.rs @@ -1,5 +1,6 @@ mod ps; use super::Poem; +use crate::compose::Environment; use crate::path; use crate::poem::anthology; use crate::poem::elements::rune::Rune; @@ -10,11 +11,11 @@ use std::{ }; pub trait Reciteable { - fn recite(&self, bins: &mut Vec, stdout: Option) -> Result; + fn recite(&self, env: &mut Environment, stdout: Option) -> Result; } impl Reciteable for Poem { - fn recite(&self, bins: &mut Vec, stdout: Option) -> Result { + fn recite(&self, env: &mut Environment, stdout: Option) -> Result { // Should we print to stdout or always capture it let stdout = stdout.unwrap_or(true); @@ -84,7 +85,7 @@ impl Reciteable for Poem { Some(poem) => poem, None => break, // TODO: Return an error }; - let out = poem.recite(bins, Some(false))?; + let out = poem.recite(env, Some(false))?; if out.contains("\n") { let mut out = out.split("\n"); let next = out.next().unwrap_or("").trim(); @@ -121,16 +122,16 @@ impl Reciteable for Poem { // Incant the verse if it's a built-in let index = anthology::lookup(&verse.verb()); let status = if index.is_some() { - anthology::incant(&verse, index.unwrap(), bins) + anthology::incant(&verse, index.unwrap(), env) } else { // Incant the verse, based on its meter // Check if the verb exists // If it doesn't exist, try refreshing the binary cache, and check // again // If it still doesn't exist, print an error - if !verse.spellcheck(bins) { - *bins = path::refresh(); - if !verse.spellcheck(bins) { + if !verse.spellcheck(&env.bins) { + env.bins = path::refresh(); + if !verse.spellcheck(&env.bins) { eprintln!("dwvsh: {}: command not found", verse.verb()); if verse.meter != Rune::And { -- cgit v1.2.3