Add Runtime::store_backend_to_stdout(), make _stdio() variant use stdin properly

This commit is contained in:
Matthias Beyer 2017-06-20 20:57:03 +02:00
parent 2790042f6f
commit 699f4083e9

View file

@ -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<Command> {
self.cli()