diff options
Diffstat (limited to 'lib/entry/libimagentryview')
-rw-r--r-- | lib/entry/libimagentryview/Cargo.toml | 24 | ||||
-rw-r--r-- | lib/entry/libimagentryview/src/builtin/editor.rs | 44 | ||||
-rw-r--r-- | lib/entry/libimagentryview/src/builtin/mod.rs | 22 | ||||
-rw-r--r-- | lib/entry/libimagentryview/src/builtin/plain.rs | 49 | ||||
-rw-r--r-- | lib/entry/libimagentryview/src/builtin/stdout.rs | 57 | ||||
-rw-r--r-- | lib/entry/libimagentryview/src/error.rs | 32 | ||||
-rw-r--r-- | lib/entry/libimagentryview/src/lib.rs | 48 | ||||
-rw-r--r-- | lib/entry/libimagentryview/src/result.rs | 24 | ||||
-rw-r--r-- | lib/entry/libimagentryview/src/viewer.rs | 36 |
9 files changed, 336 insertions, 0 deletions
diff --git a/lib/entry/libimagentryview/Cargo.toml b/lib/entry/libimagentryview/Cargo.toml new file mode 100644 index 00000000..201215b6 --- /dev/null +++ b/lib/entry/libimagentryview/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "libimagentryview" +version = "0.4.0" +authors = ["Matthias Beyer <mail@beyermatthias.de>"] + +description = "Library for the imag core distribution" + +keywords = ["imag", "PIM", "personal", "information", "management"] +readme = "../README.md" +license = "LGPL-2.1" + +documentation = "https://matthiasbeyer.github.io/imag/imag_documentation/index.html" +repository = "https://github.com/matthiasbeyer/imag" +homepage = "http://imag-pim.org" + +[dependencies] +log = "0.3" +toml = "^0.4" +glob = "0.2" + +libimagrt = { version = "0.4.0", path = "../../../lib/core/libimagrt" } +libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" } +libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" } +libimagentryedit = { version = "0.4.0", path = "../../../lib/entry/libimagentryedit" } diff --git a/lib/entry/libimagentryview/src/builtin/editor.rs b/lib/entry/libimagentryview/src/builtin/editor.rs new file mode 100644 index 00000000..259d4986 --- /dev/null +++ b/lib/entry/libimagentryview/src/builtin/editor.rs @@ -0,0 +1,44 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use libimagstore::store::Entry; +use libimagrt::runtime::Runtime; +use libimagentryedit::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/lib/entry/libimagentryview/src/builtin/mod.rs b/lib/entry/libimagentryview/src/builtin/mod.rs new file mode 100644 index 00000000..26d5b223 --- /dev/null +++ b/lib/entry/libimagentryview/src/builtin/mod.rs @@ -0,0 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +pub mod editor; +pub mod plain; +pub mod stdout; diff --git a/lib/entry/libimagentryview/src/builtin/plain.rs b/lib/entry/libimagentryview/src/builtin/plain.rs new file mode 100644 index 00000000..f40b2527 --- /dev/null +++ b/lib/entry/libimagentryview/src/builtin/plain.rs @@ -0,0 +1,49 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use libimagstore::store::Entry; + +use viewer::Viewer; +use result::Result; + +pub struct PlainViewer { + show_header: bool +} + +impl PlainViewer { + + pub fn new(show_header: bool) -> PlainViewer { + PlainViewer { + show_header: show_header, + } + } + +} + +impl Viewer for PlainViewer { + + fn view_entry(&self, e: &Entry) -> Result<()> { + if self.show_header { + println!("{}", e.get_header()); + } + println!("{}", e.get_content()); + Ok(()) + } + +} diff --git a/lib/entry/libimagentryview/src/builtin/stdout.rs b/lib/entry/libimagentryview/src/builtin/stdout.rs new file mode 100644 index 00000000..3d9fea05 --- /dev/null +++ b/lib/entry/libimagentryview/src/builtin/stdout.rs @@ -0,0 +1,57 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use libimagstore::store::Entry; + +use toml::ser::to_string; + +use viewer::Viewer; +use result::Result; + +pub struct StdoutViewer { + view_header: bool, + view_content: bool, +} + +impl StdoutViewer { + + pub fn new(view_header: bool, view_content: bool) -> StdoutViewer { + StdoutViewer { + view_header: view_header, + view_content: view_content, + } + } + +} + +impl Viewer for StdoutViewer { + + fn view_entry(&self, e: &Entry) -> Result<()> { + if self.view_header { + println!("{}", to_string(e.get_header()).unwrap_or(String::from("TOML Parser error"))); + } + + if self.view_content { + println!("{}", e.get_content()); + } + + Ok(()) + } + +} diff --git a/lib/entry/libimagentryview/src/error.rs b/lib/entry/libimagentryview/src/error.rs new file mode 100644 index 00000000..c471b3f3 --- /dev/null +++ b/lib/entry/libimagentryview/src/error.rs @@ -0,0 +1,32 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +generate_error_module!( + generate_error_types!(ViewError, ViewErrorKind, + Unknown => "Unknown view error", + GlobError => "Error while glob()ing", + PatternError => "Error in glob() pattern", + PatternBuildingError => "Could not build glob() pattern", + ViewError => "Failed to start viewer" + ); +); + +pub use self::error::ViewError; +pub use self::error::ViewErrorKind; +pub use self::error::MapErrInto; diff --git a/lib/entry/libimagentryview/src/lib.rs b/lib/entry/libimagentryview/src/lib.rs new file mode 100644 index 00000000..55d58d6a --- /dev/null +++ b/lib/entry/libimagentryview/src/lib.rs @@ -0,0 +1,48 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +#![deny( + dead_code, + non_camel_case_types, + non_snake_case, + path_statements, + trivial_numeric_casts, + unstable_features, + unused_allocation, + unused_import_braces, + unused_imports, + unused_must_use, + unused_mut, + unused_qualifications, + while_true, +)] + +extern crate glob; +extern crate toml; + +extern crate libimagstore; +extern crate libimagrt; +#[macro_use] extern crate libimagerror; +extern crate libimagentryedit; + +pub mod error; +pub mod builtin; +pub mod result; +pub mod viewer; + diff --git a/lib/entry/libimagentryview/src/result.rs b/lib/entry/libimagentryview/src/result.rs new file mode 100644 index 00000000..3650b1fe --- /dev/null +++ b/lib/entry/libimagentryview/src/result.rs @@ -0,0 +1,24 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use std::result::Result as RResult; + +use error::ViewError; + +pub type Result<T> = RResult<T, ViewError>; diff --git a/lib/entry/libimagentryview/src/viewer.rs b/lib/entry/libimagentryview/src/viewer.rs new file mode 100644 index 00000000..35763126 --- /dev/null +++ b/lib/entry/libimagentryview/src/viewer.rs @@ -0,0 +1,36 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use libimagstore::store::Entry; + +use result::Result; + +pub trait Viewer { + + fn view_entry(&self, e: &Entry) -> Result<()>; + + fn view_entries<I: Iterator<Item = Entry>>(&self, entries: I) -> Result<()> { + for entry in entries { + if let Err(e) = self.view_entry(&entry) { + return Err(e); + } + } + Ok(()) + } +} |