1
//! View dispatch types and traits.
2

            
3
pub mod console;
4
pub mod list;
5
pub mod reports;
6
pub mod select_list;
7
#[cfg(test)]
8
mod tests;
9

            
10
use crate::hits::Hits;
11
use tvui::{FrameState, Theme};
12

            
13
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14
pub enum ViewId {
15
    Accounts = 0,
16
    Transactions = 1,
17
    Commodities = 2,
18
    Reports = 3,
19
    Config = 4,
20
    SshKeys = 5,
21
    Tags = 6,
22
    Templates = 7,
23
    Console = 8,
24
    Scripts = 9,
25
    /// Not among [`ViewId::ALL`]: a viewer opens for what it shows, never blank.
26
    Viewer = 10,
27
}
28

            
29
impl ViewId {
30
    pub const ALL: [ViewId; 10] = [
31
        ViewId::Accounts,
32
        ViewId::Transactions,
33
        ViewId::Commodities,
34
        ViewId::Reports,
35
        ViewId::Config,
36
        ViewId::SshKeys,
37
        ViewId::Tags,
38
        ViewId::Templates,
39
        ViewId::Console,
40
        ViewId::Scripts,
41
    ];
42

            
43
36
    pub fn index(self) -> usize {
44
36
        self as usize
45
36
    }
46

            
47
163226
    pub fn label(self) -> &'static str {
48
163226
        match self {
49
30977
            ViewId::Accounts => "Accounts",
50
26059
            ViewId::Transactions => "Transactions",
51
23162
            ViewId::Commodities => "Commodities",
52
19910
            ViewId::Reports => "Reports",
53
17583
            ViewId::Config => "Config",
54
14717
            ViewId::SshKeys => "SSH keys",
55
12298
            ViewId::Tags => "Tags",
56
8894
            ViewId::Templates => "Templates",
57
3278
            ViewId::Scripts => "Scripts",
58
6348
            ViewId::Console => "Console",
59
            ViewId::Viewer => "Viewer",
60
        }
61
163226
    }
62
}
63

            
64
/// `Tab` is an alias so existing `Tab::Accounts`, `Tab::ALL`, etc. keep compiling.
65
pub type Tab = ViewId;
66

            
67
pub struct DrawCtx<'a> {
68
    /// True when the view currently holds keyboard focus (e.g. console input active).
69
    pub is_active: bool,
70
    /// What the window's frame shows; passive for a rear window and under a modal.
71
    pub frame: FrameState,
72
    /// The window's frame title, from [`crate::window::View::title`].
73
    pub title: String,
74
    pub theme: &'a Theme,
75
    /// The areas the view draws that a click can land on.
76
    pub hits: &'a mut Hits,
77
}
78

            
79
pub enum Handled {
80
    Consumed(Vec<Cmd>),
81
    Ignored,
82
}
83

            
84
pub enum Cmd {
85
    Status(String),
86
    SwitchView(ViewId),
87
}