Merge pull request #610 from asuivelentine/libimagentryview/editor

Libimagentryview/editor
This commit is contained in:
Matthias Beyer 2016-08-07 17:09:18 +02:00 committed by GitHub
commit 41969d7fb8
5 changed files with 32 additions and 1 deletions

View file

@ -8,6 +8,9 @@ log = "0.3"
toml = "0.2.*" toml = "0.2.*"
glob = "0.2.11" glob = "0.2.11"
[dependencies.libimagrt]
path = "../libimagrt"
[dependencies.libimagstore] [dependencies.libimagstore]
path = "../libimagstore" path = "../libimagstore"

View file

@ -0,0 +1,25 @@
use libimagstore::store::Entry;
use libimagrt::runtime::Runtime;
use libimagrt::edit::edit_in_tmpfile;
use viewer::Viewer;
use result::Result;
use error::ViewErrorKind as VEK;
use error::ViewError as VE;
pub struct EditorView<'a>(&'a Runtime<'a>);
impl<'a> EditorView<'a> {
pub fn new(rt: &'a Runtime) -> EditorView<'a> {
EditorView(rt)
}
}
impl<'a> Viewer for EditorView<'a> {
fn view_entry(&self, e: &Entry) -> Result<()> {
let mut entry = e.to_str().clone().to_string();
edit_in_tmpfile(self.0, &mut entry)
.map_err(|e| VE::new(VEK::ViewError, Some(Box::new(e))))
}
}

View file

@ -1,3 +1,4 @@
pub mod editor;
pub mod plain; pub mod plain;
pub mod stdout; pub mod stdout;
pub mod versions; pub mod versions;

View file

@ -3,7 +3,8 @@ generate_error_module!(
Unknown => "Unknown view error", Unknown => "Unknown view error",
GlobError => "Error while glob()ing", GlobError => "Error while glob()ing",
PatternError => "Error in glob() pattern", PatternError => "Error in glob() pattern",
PatternBuildingError => "Could not build glob() pattern" PatternBuildingError => "Could not build glob() pattern",
ViewError => "Failed to start viewer"
); );
); );

View file

@ -19,6 +19,7 @@ extern crate glob;
extern crate toml; extern crate toml;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagrt;
#[macro_use] extern crate libimagerror; #[macro_use] extern crate libimagerror;
pub mod error; pub mod error;