Merge pull request #610 from asuivelentine/libimagentryview/editor
Libimagentryview/editor
This commit is contained in:
commit
41969d7fb8
5 changed files with 32 additions and 1 deletions
|
@ -8,6 +8,9 @@ log = "0.3"
|
|||
toml = "0.2.*"
|
||||
glob = "0.2.11"
|
||||
|
||||
[dependencies.libimagrt]
|
||||
path = "../libimagrt"
|
||||
|
||||
[dependencies.libimagstore]
|
||||
path = "../libimagstore"
|
||||
|
||||
|
|
25
libimagentryview/src/builtin/editor.rs
Normal file
25
libimagentryview/src/builtin/editor.rs
Normal 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))))
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod editor;
|
||||
pub mod plain;
|
||||
pub mod stdout;
|
||||
pub mod versions;
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ extern crate glob;
|
|||
extern crate toml;
|
||||
|
||||
extern crate libimagstore;
|
||||
extern crate libimagrt;
|
||||
#[macro_use] extern crate libimagerror;
|
||||
|
||||
pub mod error;
|
||||
|
|
Loading…
Reference in a new issue