From 92c848dc816508a7296cb1513a4b01c6eed39672 Mon Sep 17 00:00:00 2001 From: Kai Sickeler Date: Mon, 1 Aug 2016 17:13:49 +0200 Subject: [PATCH 1/3] Added editor support --- libimagentryview/Cargo.toml | 4 ++++ libimagentryview/src/builtin/editor.rs | 25 +++++++++++++++++++++++++ libimagentryview/src/builtin/mod.rs | 1 + libimagentryview/src/lib.rs | 2 ++ 4 files changed, 32 insertions(+) create mode 100644 libimagentryview/src/builtin/editor.rs diff --git a/libimagentryview/Cargo.toml b/libimagentryview/Cargo.toml index 43c2830c..60d8d262 100644 --- a/libimagentryview/Cargo.toml +++ b/libimagentryview/Cargo.toml @@ -7,6 +7,10 @@ authors = ["Matthias Beyer "] log = "0.3" toml = "0.1.25" glob = "0.2.11" +tempfile = "2.1.4" + +[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/lib.rs b/libimagentryview/src/lib.rs index b31642f8..84992562 100644 --- a/libimagentryview/src/lib.rs +++ b/libimagentryview/src/lib.rs @@ -17,8 +17,10 @@ #[macro_use] extern crate log; extern crate glob; extern crate toml; +extern crate tempfile; extern crate libimagstore; +extern crate libimagrt; #[macro_use] extern crate libimagerror; pub mod error; From fcb9001c1edf13e7aa0e1b2371254f9c315b9086 Mon Sep 17 00:00:00 2001 From: Kai Sickeler Date: Sat, 6 Aug 2016 16:54:05 +0200 Subject: [PATCH 2/3] Added ViewError --- libimagentryview/src/error.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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" ); ); From 96e88d6c8023be85e11c0b687b698407ec58fcef Mon Sep 17 00:00:00 2001 From: Kai Sickeler Date: Sat, 6 Aug 2016 19:19:03 +0200 Subject: [PATCH 3/3] removed unused dependency --- libimagentryview/Cargo.toml | 1 - libimagentryview/src/lib.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/libimagentryview/Cargo.toml b/libimagentryview/Cargo.toml index 60d8d262..29c6ef4e 100644 --- a/libimagentryview/Cargo.toml +++ b/libimagentryview/Cargo.toml @@ -7,7 +7,6 @@ authors = ["Matthias Beyer "] log = "0.3" toml = "0.1.25" glob = "0.2.11" -tempfile = "2.1.4" [dependencies.libimagrt] path = "../libimagrt" diff --git a/libimagentryview/src/lib.rs b/libimagentryview/src/lib.rs index 84992562..159e0fa2 100644 --- a/libimagentryview/src/lib.rs +++ b/libimagentryview/src/lib.rs @@ -17,7 +17,6 @@ #[macro_use] extern crate log; extern crate glob; extern crate toml; -extern crate tempfile; extern crate libimagstore; extern crate libimagrt;