inquire/prompts/password/
action.rs

1use crate::{
2    ui::{Key, KeyModifiers},
3    InnerAction, InputAction,
4};
5
6use super::config::PasswordConfig;
7
8/// Set of actions for a PasswordPrompt.
9#[derive(Copy, Clone, Debug, PartialEq, Eq)]
10pub enum PasswordPromptAction {
11    /// Action on the value text input handler.
12    ValueInput(InputAction),
13    /// Toggles the display mode between plain text and the initial one.
14    ToggleDisplayMode,
15}
16
17impl InnerAction for PasswordPromptAction {
18    type Config = PasswordConfig;
19
20    fn from_key(key: Key, config: &PasswordConfig) -> Option<Self> {
21        let action = match key {
22            Key::Char('r' | 'R', m)
23                if m.contains(KeyModifiers::CONTROL) && config.enable_display_toggle =>
24            {
25                Self::ToggleDisplayMode
26            }
27            key => match InputAction::from_key(key, &()) {
28                Some(action) => Self::ValueInput(action),
29                None => return None,
30            },
31        };
32
33        Some(action)
34    }
35}