oo_ide/views.rs
1pub(crate) mod command_runner;
2pub(crate) mod commit;
3pub mod editor;
4pub mod project_search;
5pub(crate) mod save_state;
6pub(crate) mod extension_config;
7pub mod file_selector;
8pub(crate) mod git_branches;
9pub(crate) mod git_history;
10pub(crate) mod git_history_editor;
11pub(crate) mod git_pull;
12pub(crate) mod issue_view;
13pub(crate) mod log_view;
14// legacy SearchReplace view removed — editor now hosts expanded project search
15pub(crate) mod task_archive;
16pub mod terminal;
17
18use ratatui::{Frame, layout::Rect};
19
20use crate::input;
21use crate::operation::{Event, Operation};
22use crate::theme::Theme;
23use crate::settings::Settings;
24
25/// Whether a view is a primary working context or a temporary overlay.
26///
27/// - **Primary** views (Editor, Terminal, CommitWindow, GitHistory) represent the
28/// user's main working context. When opening a modal the current primary is
29/// stashed so it can be restored when the modal closes.
30/// - **Modal** views (FileSelector, CommandRunner, LogView, SearchReplace,
31/// ExtensionConfig) are overlays. Pressing `Esc` while in a modal view returns
32/// to the stashed primary view.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum ViewKind {
35 Primary,
36 Modal,
37}
38
39/// Every full-screen view implements this trait.
40///
41/// # Responsibilities
42///
43/// - `handle_key` — translate raw input into operations (no mutation)
44/// - `handle_mouse` — translate mouse events into operations (default no-op)
45/// - `handle_operation` — apply operations the view owns; emit an event on success
46/// - `render` — draw the current state to the terminal frame
47///
48/// Views own their slice of state. Nobody mutates a view's internals except
49/// the view itself, through `handle_operation`.
50pub trait View {
51 /// The kind of this view: [`ViewKind::Primary`] or [`ViewKind::Modal`].
52 ///
53 /// Used by the escape logic to decide whether to revert to the last primary
54 /// view or to ignore the key press.
55 const KIND: ViewKind;
56 /// Translate a key event into zero or more operations.
57 /// Must not mutate `self` — use `handle_operation` for that.
58 fn handle_key(&self, key: input::KeyEvent) -> Vec<Operation>;
59
60 /// Translate a mouse event into zero or more operations.
61 /// Default implementation is a no-op; views that support mouse override this.
62 fn handle_mouse(&self, _mouse: input::MouseEvent) -> Vec<Operation> {
63 vec![]
64 }
65
66 /// Apply a single operation if it is relevant to this view.
67 ///
68 /// Returns `Some(event)` if the operation was applied (so the event loop
69 /// can broadcast the resulting event to subscribers), or `None` if this
70 /// view does not own the operation.
71 fn handle_operation(&mut self, op: &Operation, settings: &Settings) -> Option<Event>;
72
73 /// Save the current state of the view before it is closed.
74 fn save_state(&mut self, app_state: &mut crate::app_state::AppState);
75
76 /// Draw the view into the provided `area` of the current frame.
77 fn render(&self, frame: &mut Frame, area: Rect, theme: &Theme);
78
79 /// Populate the global status bar with view-specific content.
80 ///
81 /// The default implementation is a no-op; views that want to surface
82 /// information in the status bar override this.
83 fn status_bar(&self, _state: &crate::app_state::AppState, _bar: &mut crate::widgets::status_bar::StatusBarBuilder) {}
84}