From 10ef1497ad7aaf4b3f4d092bbdcc03c313f1ed37 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 24 Jul 2020 19:05:16 +0200 Subject: Add error dialog helper function Signed-off-by: Matthias Beyer --- src/main.rs | 1 + src/main_view.rs | 14 ++++---------- src/util.rs | 11 +++++++++++ 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 src/util.rs diff --git a/src/main.rs b/src/main.rs index 6f7000e..37cf160 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use cursive::event::{Event, EventTrigger}; mod main_view; mod maillist_view; mod configuration; +mod util; use configuration::Configuration; diff --git a/src/main_view.rs b/src/main_view.rs index 63e54f0..d870a1f 100644 --- a/src/main_view.rs +++ b/src/main_view.rs @@ -118,6 +118,8 @@ impl MainView { } fn add_notmuch_query_layer(siv: &mut Cursive) { + use crate::util::dialog_for; + let edit_view = EditView::new() .on_submit(move |siv: &mut Cursive, query: &str| { siv.call_on_name(MAIN_VIEW_NAME, move |main_view: &mut MainView| { @@ -139,20 +141,12 @@ impl MainView { }) .unwrap_or_else(|| { siv.pop_layer(); - siv.add_layer({ - Dialog::around({ - TextView::new("Failed to get database connection set up") - }) - }); + siv.add_layer(dialog_for("Failed to get database connection set up")); Ok(()) }) .unwrap_or_else(|e: anyhow::Error| { siv.pop_layer(); - siv.add_layer({ - Dialog::around({ - TextView::new(format!("{}", e.to_string())) - }) - }); + siv.add_layer(dialog_for(e)) }); }) .with_name("query"); diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..fcb4432 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,11 @@ +use cursive::views::Dialog; +use cursive::views::TextView; + +pub fn dialog_for(e: S) -> Dialog { + Dialog::around({ + TextView::new(e.to_string()) + }) + .button("Ok", |s| { + s.pop_layer(); + }) +} -- cgit v1.2.3