1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{
    ui::{Key, KeyModifiers},
    InnerAction, InputAction,
};

use super::config::PasswordConfig;

/// Set of actions for a PasswordPrompt.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PasswordPromptAction {
    /// Action on the value text input handler.
    ValueInput(InputAction),
    /// Toggles the display mode between plain text and the initial one.
    ToggleDisplayMode,
}

impl InnerAction for PasswordPromptAction {
    type Config = PasswordConfig;

    fn from_key(key: Key, config: &PasswordConfig) -> Option<Self> {
        let action = match key {
            Key::Char('r' | 'R', m)
                if m.contains(KeyModifiers::CONTROL) && config.enable_display_toggle =>
            {
                Self::ToggleDisplayMode
            }
            key => match InputAction::from_key(key, &()) {
                Some(action) => Self::ValueInput(action),
                None => return None,
            },
        };

        Some(action)
    }
}