More stream stuff

This commit is contained in:
Yehuda Katz 2019-05-11 20:14:16 -07:00
parent e6da37f5be
commit 786da8fd9d
2 changed files with 36 additions and 9 deletions

View file

@ -1,5 +1,6 @@
use crate::object::Value; use crate::object::Value;
use derive_new::new; use derive_new::new;
use std::cell::Cell;
use std::collections::VecDeque; use std::collections::VecDeque;
#[derive(Debug, Default)] #[derive(Debug, Default)]
@ -7,20 +8,46 @@ pub struct ObjectStream {
queue: VecDeque<Value>, queue: VecDeque<Value>,
} }
#[derive(Debug, Default)]
pub struct Streams { pub struct Streams {
success: ObjectStream, success: Cell<ObjectStream>,
error: ObjectStream, // error: ObjectStream,
warning: ObjectStream, // warning: ObjectStream,
debug: ObjectStream, // debug: ObjectStream,
trace: ObjectStream, // trace: ObjectStream,
verbose: ObjectStream, // verbose: ObjectStream,
}
impl std::fmt::Debug for Streams {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Streams")
}
}
impl Streams {
crate fn new() -> Streams {
Streams {
success: Cell::new(ObjectStream::default()),
}
}
crate fn take_success(&mut self) -> Cell<ObjectStream> {
let new_stream = Cell::new(ObjectStream::default());
self.success.swap(&new_stream);
new_stream
}
// fn take_stream(&mut self, stream: &mut ObjectStream) -> ObjectStream {
// let mut new_stream = Cell::new(ObjectStream::default());
// new_stream.swap()
// std::mem::swap(stream, &mut new_stream);
// new_stream
// }
} }
#[derive(Debug, new)] #[derive(Debug, new)]
pub struct Args { pub struct Args {
argv: Vec<Value>, argv: Vec<Value>,
#[new(default)] #[new(value = "Streams::new()")]
streams: Streams, streams: Streams,
} }

View file

@ -5,7 +5,7 @@ use std::path::PathBuf;
pub trait CommandBlueprint { pub trait CommandBlueprint {
fn create( fn create(
&self, &self,
args: crate::Args, input: crate::Args,
host: &dyn crate::Host, host: &dyn crate::Host,
env: &mut crate::Environment, env: &mut crate::Environment,
) -> Result<Box<dyn Command>, ShellError>; ) -> Result<Box<dyn Command>, ShellError>;