summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-07-24 19:05:16 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-07-24 19:10:23 +0200
commit10ef1497ad7aaf4b3f4d092bbdcc03c313f1ed37 (patch)
tree692b9e77f8315d82454a663087e53b90176551de
parent827101712e15193a4ba86fee85a06e6ab5da8f3a (diff)
Add error dialog helper function
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/main.rs1
-rw-r--r--src/main_view.rs14
-rw-r--r--src/util.rs11
3 files changed, 16 insertions, 10 deletions
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<S: ToString>(e: S) -> Dialog {
+ Dialog::around({
+ TextView::new(e.to_string())
+ })
+ .button("Ok", |s| {
+ s.pop_layer();
+ })
+}