diff --git a/libimagentryview/Cargo.toml b/libimagentryview/Cargo.toml index 42b6fa8d..ca3cec15 100644 --- a/libimagentryview/Cargo.toml +++ b/libimagentryview/Cargo.toml @@ -8,6 +8,9 @@ log = "0.3" toml = "0.2.*" glob = "0.2.11" +[dependencies.libimagrt] +path = "../libimagrt" + [dependencies.libimagstore] path = "../libimagstore" diff --git a/libimagentryview/src/builtin/editor.rs b/libimagentryview/src/builtin/editor.rs new file mode 100644 index 00000000..0f35c98e --- /dev/null +++ b/libimagentryview/src/builtin/editor.rs @@ -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)))) + } +} + diff --git a/libimagentryview/src/builtin/mod.rs b/libimagentryview/src/builtin/mod.rs index 449d9b67..ec41fd0f 100644 --- a/libimagentryview/src/builtin/mod.rs +++ b/libimagentryview/src/builtin/mod.rs @@ -1,3 +1,4 @@ +pub mod editor; pub mod plain; pub mod stdout; pub mod versions; diff --git a/libimagentryview/src/error.rs b/libimagentryview/src/error.rs index f26c6081..fbc31487 100644 --- a/libimagentryview/src/error.rs +++ b/libimagentryview/src/error.rs @@ -3,7 +3,8 @@ generate_error_module!( Unknown => "Unknown view error", GlobError => "Error while glob()ing", PatternError => "Error in glob() pattern", - PatternBuildingError => "Could not build glob() pattern" + PatternBuildingError => "Could not build glob() pattern", + ViewError => "Failed to start viewer" ); ); diff --git a/libimagentryview/src/lib.rs b/libimagentryview/src/lib.rs index b31642f8..159e0fa2 100644 --- a/libimagentryview/src/lib.rs +++ b/libimagentryview/src/lib.rs @@ -19,6 +19,7 @@ extern crate glob; extern crate toml; extern crate libimagstore; +extern crate libimagrt; #[macro_use] extern crate libimagerror; pub mod error;