diff options
-rw-r--r-- | src/compose/environment.rs | 3 | ||||
-rw-r--r-- | src/poem/elements/verse/logic.rs | 10 | ||||
-rw-r--r-- | src/poem/recite.rs | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/compose/environment.rs b/src/compose/environment.rs index 18d59c4..151c7a5 100644 --- a/src/compose/environment.rs +++ b/src/compose/environment.rs @@ -14,6 +14,7 @@ use std::collections::HashMap; /// bins - A lookup table for +x files, constructed from the $PATH /// cs - Indication of callstack level, helpful for recursively dealing with /// aliases +/// fc - Force the capture of stdout (for internal poems) /// /// # Examples /// ``` @@ -29,6 +30,7 @@ pub struct Environment { pub aliases: HashMap<String, String>, pub bins: Vec<String>, pub cs: u8, + pub fc: bool, } impl Environment { @@ -38,6 +40,7 @@ impl Environment { aliases: HashMap::new(), bins: Vec::new(), cs: 0, + fc: false, } } } diff --git a/src/poem/elements/verse/logic.rs b/src/poem/elements/verse/logic.rs index c1d3d62..f5efdee 100644 --- a/src/poem/elements/verse/logic.rs +++ b/src/poem/elements/verse/logic.rs @@ -28,6 +28,11 @@ macro_rules! incant { $command.stderr(Stdio::piped()); } + // Capture stdout if (f)orce (c)apture is set + if $env.fc { + $command.stdout(Stdio::piped()); + } + // Detach the process group, if in the [Rune::Quiet] meter if $self.meter == Rune::Quiet { $command.process_group(0); @@ -59,6 +64,9 @@ macro_rules! incant { $out.append(&mut output.stdout); err.append(&mut output.stderr); } + if $env.fc { + $out.append(&mut output.stdout); + } } Rune::Couplet => { output = child.wait_with_output()?; @@ -210,7 +218,7 @@ macro_rules! incant { } err.clear(); - if $self.meter != Rune::Couplet { + if $self.meter != Rune::Couplet && $env.fc != true { $out.clear(); } diff --git a/src/poem/recite.rs b/src/poem/recite.rs index b27ef75..7ceecca 100644 --- a/src/poem/recite.rs +++ b/src/poem/recite.rs @@ -98,7 +98,9 @@ impl Reciteable for Poem { Some(poem) => poem, None => break, // TODO: Return an error }; + env.fc = true; let mut out = poem.recite(env)?; + env.fc = false; match out.last() { Some(last) => { if *last == b'\n' { |