ghostscope_ui/components/ebpf_panel/
panel.rs

1use crate::action::Action;
2use crate::model::panel_state::EbpfPanelState;
3use crossterm::event::{KeyCode, KeyModifiers};
4use ratatui::crossterm::event::KeyEvent;
5
6/// Handles input events for the eBPF panel
7#[derive(Debug)]
8pub struct EbpfPanelHandler;
9
10impl EbpfPanelHandler {
11    pub fn new() -> Self {
12        Self
13    }
14
15    /// Handle key events for the eBPF panel
16    pub fn handle_key_event(&mut self, state: &mut EbpfPanelState, key: KeyEvent) -> Vec<Action> {
17        let actions = Vec::new();
18
19        // Expanded view key handling
20        if state.is_expanded() {
21            let half = state.last_inner_height.max(1) / 2;
22            match key.code {
23                KeyCode::Up | KeyCode::Char('k') => state.scroll_expanded_up(1),
24                KeyCode::Down | KeyCode::Char('j') => state.scroll_expanded_down(1, usize::MAX),
25                KeyCode::PageUp => state.scroll_expanded_up(state.last_inner_height.max(1)),
26                KeyCode::PageDown => {
27                    state.scroll_expanded_down(state.last_inner_height.max(1), usize::MAX)
28                }
29                KeyCode::Enter => {} // no-op
30                KeyCode::Esc => {
31                    state.close_expanded();
32                }
33                KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => {
34                    state.close_expanded();
35                }
36                _ => {
37                    // ignore other keys in expanded view
38                }
39            }
40
41            if key.modifiers.contains(KeyModifiers::CONTROL) {
42                match key.code {
43                    KeyCode::Char('d') => state.scroll_expanded_down(half.max(1), usize::MAX),
44                    KeyCode::Char('u') => state.scroll_expanded_up(half.max(1)),
45                    _ => {}
46                }
47            }
48
49            return actions; // Expanded view handled exclusively
50        } else {
51            // List view key handling (existing behavior)
52            match key.code {
53                KeyCode::Up | KeyCode::Char('k') => {
54                    state.move_cursor_up();
55                }
56                KeyCode::Down | KeyCode::Char('j') => {
57                    state.move_cursor_down();
58                }
59                KeyCode::Char('g') => {
60                    state.handle_g_key();
61                }
62                KeyCode::Char('G') => {
63                    state.confirm_goto();
64                }
65                KeyCode::Char(d) if d.is_ascii_digit() => {
66                    state.push_numeric_digit(d);
67                }
68                KeyCode::Enter => {
69                    state.open_expanded_current();
70                }
71                KeyCode::Esc => {
72                    state.exit_to_auto_refresh();
73                }
74                _ => {}
75            }
76
77            if key.modifiers.contains(KeyModifiers::CONTROL) {
78                match key.code {
79                    KeyCode::Char('d') => {
80                        state.move_cursor_down_10();
81                    }
82                    KeyCode::Char('u') => {
83                        state.move_cursor_up_10();
84                    }
85                    _ => {}
86                }
87            }
88        }
89
90        actions
91    }
92}
93
94impl Default for EbpfPanelHandler {
95    fn default() -> Self {
96        Self::new()
97    }
98}