Skip to main content

tui/view/
mod.rs

1//! View dispatch types and traits.
2
3pub mod console;
4pub mod list;
5pub mod reports;
6pub mod select_list;
7#[cfg(test)]
8mod tests;
9
10use crate::hits::Hits;
11use tvui::{FrameState, Theme};
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub 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
29impl 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    pub fn index(self) -> usize {
44        self as usize
45    }
46
47    pub fn label(self) -> &'static str {
48        match self {
49            ViewId::Accounts => "Accounts",
50            ViewId::Transactions => "Transactions",
51            ViewId::Commodities => "Commodities",
52            ViewId::Reports => "Reports",
53            ViewId::Config => "Config",
54            ViewId::SshKeys => "SSH keys",
55            ViewId::Tags => "Tags",
56            ViewId::Templates => "Templates",
57            ViewId::Scripts => "Scripts",
58            ViewId::Console => "Console",
59            ViewId::Viewer => "Viewer",
60        }
61    }
62}
63
64/// `Tab` is an alias so existing `Tab::Accounts`, `Tab::ALL`, etc. keep compiling.
65pub type Tab = ViewId;
66
67pub 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
79pub enum Handled {
80    Consumed(Vec<Cmd>),
81    Ignored,
82}
83
84pub enum Cmd {
85    Status(String),
86    SwitchView(ViewId),
87}