summaryrefslogtreecommitdiffstats
path: root/src/util.rs
blob: 3d99b393460dfd911aac71849d5f358e89a0a876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use anyhow::Error;
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();
    })
}

pub fn error_dialog_for(e: Error) -> Dialog {
    let s = e.chain()
        .rev()
        .enumerate()
        .map(|(i, e)| format!("{}: {}", i, e))
        .fold(String::new(), |acc, s| {
            acc + &s + "\n"
        });

    dialog_for(s)
}