Skip to main content

cbtop/app/
panels.rs

1//! Active panel definitions for the cbtop TUI.
2
3/// Active panel in the UI
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub enum ActivePanel {
6    #[default]
7    Overview,
8    Cpu,
9    Gpu,
10    Pcie,
11    Memory,
12    Thermal,
13    Load,
14    Config,
15    Help,
16}
17
18impl ActivePanel {
19    /// Get panel from key (1-9)
20    pub fn from_key(key: char) -> Option<Self> {
21        match key {
22            '1' => Some(Self::Overview),
23            '2' => Some(Self::Cpu),
24            '3' => Some(Self::Gpu),
25            '4' => Some(Self::Pcie),
26            '5' => Some(Self::Memory),
27            '6' => Some(Self::Thermal),
28            '7' => Some(Self::Load),
29            '8' => Some(Self::Config),
30            '9' => Some(Self::Help),
31            _ => None,
32        }
33    }
34
35    /// Panel title
36    pub fn title(&self) -> &'static str {
37        match self {
38            Self::Overview => "Overview",
39            Self::Cpu => "CPU",
40            Self::Gpu => "GPU",
41            Self::Pcie => "PCIe",
42            Self::Memory => "Memory",
43            Self::Thermal => "Thermal",
44            Self::Load => "Load",
45            Self::Config => "Config",
46            Self::Help => "Help",
47        }
48    }
49
50    /// All panels for tab bar rendering (UI-10)
51    pub fn all() -> &'static [Self] {
52        &[
53            Self::Overview,
54            Self::Cpu,
55            Self::Gpu,
56            Self::Pcie,
57            Self::Memory,
58            Self::Thermal,
59            Self::Load,
60            Self::Config,
61            Self::Help,
62        ]
63    }
64
65    /// Key number for this panel (1-9)
66    pub fn key_number(&self) -> char {
67        match self {
68            Self::Overview => '1',
69            Self::Cpu => '2',
70            Self::Gpu => '3',
71            Self::Pcie => '4',
72            Self::Memory => '5',
73            Self::Thermal => '6',
74            Self::Load => '7',
75            Self::Config => '8',
76            Self::Help => '9',
77        }
78    }
79}