From 699f4083e9eb84a691bdbb0167178a5268ba5e53 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 20 Jun 2017 20:57:03 +0200 Subject: [PATCH] Add Runtime::store_backend_to_stdout(), make _stdio() variant use stdin properly --- libimagrt/src/runtime.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index e4597c73..60ec08f3 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -358,7 +358,7 @@ impl<'a> Runtime<'a> { use std::rc::Rc; use std::cell::RefCell; - let mut input = ::std::io::empty(); + let mut input = ::std::io::stdin(); let output = ::std::io::stdout(); let output = Rc::new(RefCell::new(output)); let mapper = JsonMapper::new(); @@ -372,6 +372,25 @@ impl<'a> Runtime<'a> { }) } + pub fn store_backend_to_stdout(&mut self) -> Result<(), RuntimeError> { + use libimagstore::file_abstraction::stdio::mapper::json::JsonMapper; + use libimagstore::file_abstraction::stdio::out::StdoutFileAbstraction; + use std::rc::Rc; + use std::cell::RefCell; + + let output = ::std::io::stdout(); + let output = Rc::new(RefCell::new(output)); + let mapper = JsonMapper::new(); + + StdoutFileAbstraction::new(output, mapper) + .map_err_into(RuntimeErrorKind::Instantiate) + .and_then(|backend| { + self.store + .reset_backend(Box::new(backend)) + .map_err_into(RuntimeErrorKind::Instantiate) + }) + } + /// Get a editor command object which can be called to open the $EDITOR pub fn editor(&self) -> Option { self.cli()