1
//! Modal overlay types.
2
//!
3
//! The TUI keeps a LIFO stack of modals via [`crate::overlay::OverlayStack`].
4
//! The topmost modal owns keyboard focus and is rendered on top of the current
5
//! tab. Each modal carries a [`KeyPolicy`] that the keymap resolver uses to
6
//! decide whether `q` closes the overlay or inserts a literal character.
7

            
8
pub use crate::form::Form;
9

            
10
#[cfg(test)]
11
mod tests;
12

            
13
/// Keyboard handling policy for an overlay.
14
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15
pub enum KeyPolicy {
16
    /// Display overlay (Help, Confirm): both `q` and `Esc` close.
17
    Display,
18
    /// Input overlay (Form): `Esc` closes; `q` inserts literally.
19
    Input,
20
}
21

            
22
/// Action to execute when a confirm overlay is accepted with `y` or Enter.
23
#[derive(Debug)]
24
pub enum ConfirmAction {
25
    DeleteTransaction(String),
26
}
27

            
28
/// Anything renderable as an overlay. Kept as an enum rather than a trait
29
/// object so modal state stays `Debug` and survives through the [`crate::overlay::OverlayStack`].
30
#[derive(Debug)]
31
pub enum Modal {
32
    Form(Form),
33
    Help,
34
    Confirm {
35
        prompt: String,
36
        action: ConfirmAction,
37
    },
38
}
39

            
40
impl Modal {
41
    /// Key handling policy for this overlay variant.
42
    #[must_use]
43
34
    pub fn key_policy(&self) -> KeyPolicy {
44
34
        match self {
45
10
            Modal::Help | Modal::Confirm { .. } => KeyPolicy::Display,
46
24
            Modal::Form(_) => KeyPolicy::Input,
47
        }
48
34
    }
49
}