Lines
100 %
Functions
50 %
Branches
//! Modal overlay types.
//!
//! The TUI keeps a LIFO stack of modals via [`crate::overlay::OverlayStack`].
//! The topmost modal owns keyboard focus and is rendered on top of the current
//! tab. Each modal carries a [`KeyPolicy`] that the keymap resolver uses to
//! decide whether `q` closes the overlay or inserts a literal character.
pub use crate::form::Form;
#[cfg(test)]
mod tests;
/// Keyboard handling policy for an overlay.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyPolicy {
/// Display overlay (Help, Confirm): both `q` and `Esc` close.
Display,
/// Input overlay (Form): `Esc` closes; `q` inserts literally.
Input,
}
/// Action to execute when a confirm overlay is accepted with `y` or Enter.
#[derive(Debug)]
pub enum ConfirmAction {
DeleteTransaction(String),
/// Anything renderable as an overlay. Kept as an enum rather than a trait
/// object so modal state stays `Debug` and survives through the [`crate::overlay::OverlayStack`].
pub enum Modal {
Form(Form),
Help,
Confirm {
prompt: String,
action: ConfirmAction,
},
impl Modal {
/// Key handling policy for this overlay variant.
#[must_use]
pub fn key_policy(&self) -> KeyPolicy {
match self {
Modal::Help | Modal::Confirm { .. } => KeyPolicy::Display,
Modal::Form(_) => KeyPolicy::Input,