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/poem/recite.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/poem/recite.rs')
-rw-r--r-- | src/poem/recite.rs | 15 |
1 files changed, 8 insertions, 7 deletions
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<String>, stdout: Option<bool>) -> Result<String, io::Error>; + fn recite(&self, env: &mut Environment, stdout: Option<bool>) -> Result<String, io::Error>; } impl Reciteable for Poem { - fn recite(&self, bins: &mut Vec<String>, stdout: Option<bool>) -> Result<String, io::Error> { + fn recite(&self, env: &mut Environment, stdout: Option<bool>) -> Result<String, io::Error> { // 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 { |