summaryrefslogtreecommitdiffstats
path: root/src/mailview.rs
blob: 236eea58d1f3553643ce563f790c5fd1e302b66e (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use cursive::Printer;
use cursive::Rect;
use cursive::View;
use cursive::XY;
use cursive::direction::Direction;
use cursive::event::Event;
use cursive::event::EventResult;
use cursive::view::Selector;
use cursive::views::TextView;
use itertools::Itertools;

use crate::maillist_view::MailListingData;

pub struct MailView(TextView);

impl MailView {
    pub fn create_for(mldata: MailListingData) -> Self {
        let text = indoc::formatdoc!(r#"
                Id     : {id}
                Tags   : {tags}
                Date   : {date}
                From   : {from}
                To     : {to}
                Subject: {subject}
            "#,
            id = mldata.mail_id(),
            tags = mldata.tags().iter().join(", "),
            date = mldata.date(),
            from = mldata.from(),
            to = mldata.to(),
            subject = mldata.subject(),
        );
        MailView(TextView::new(text))
    }
}

impl View for MailView {
    fn draw(&self, printer: &Printer) {
        self.0.draw(printer)
    }

    fn layout(&mut self, xy: XY<usize>) {
        self.0.layout(xy)
    }

    fn needs_relayout(&self) -> bool {
        self.0.needs_relayout()
    }

    fn required_size(&mut self, constraint: XY<usize>) -> XY<usize> {
        self.0.required_size(constraint)
    }

    fn on_event(&mut self, e: Event) -> EventResult {
        self.0.on_event(e)
    }

    fn call_on_any<'a>(&mut self, s: &Selector, tpl: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)) {
        self.0.call_on_any(s, tpl);
    }

    fn focus_view(&mut self, s: &Selector) -> Result<(), ()> {
        self.0.focus_view(s)
    }

    fn take_focus(&mut self, source: Direction) -> bool {
        self.0.take_focus(source)
    }

    fn important_area(&self, view_size: XY<usize>) -> Rect {
        self.0.important_area(view_size)
    }

    fn type_name(&self) -> &'static str {
        self.0.type_name()
    }

}