From f988ed188d304c1a9ddc31d7653c3dda75519c87 Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Sat, 27 Apr 2024 15:09:20 +0200 Subject: [PATCH] Always close user menu when user is selected (#131). --- src/greeter.rs | 1 + src/ipc.rs | 3 +++ src/keyboard.rs | 10 ++++++---- src/ui/prompt.rs | 12 +++++++----- src/ui/util.rs | 3 ++- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/greeter.rs b/src/greeter.rs index 735077a..39e1f2e 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -62,6 +62,7 @@ pub enum Mode { #[default] Username, Password, + Action, Users, Command, Sessions, diff --git a/src/ipc.rs b/src/ipc.rs index 7687847..e9161e4 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -91,6 +91,9 @@ impl Ipc { AuthMessageType::Info => { greeter.remove_prompt(); + greeter.previous_mode = greeter.mode; + greeter.mode = Mode::Action; + if let Some(message) = &mut greeter.message { message.push('\n'); message.push_str(auth_message.trim_end()); diff --git a/src/keyboard.rs b/src/keyboard.rs index 27f6401..14e70fe 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -240,6 +240,8 @@ pub async fn handle(greeter: Arc>, input: KeyEvent, ipc: Ipc) -> greeter.username = MaskedString::from(username, name); } + greeter.mode = greeter.previous_mode; + validate_username(&mut greeter, &ipc).await; } @@ -271,7 +273,7 @@ pub async fn handle(greeter: Arc>, input: KeyEvent, ipc: Ipc) -> greeter.mode = greeter.previous_mode; } - Mode::Processing => {} + _ => {} }, // Do not handle any other controls keybindings @@ -296,7 +298,7 @@ async fn insert_key(greeter: &mut Greeter, c: char) { Mode::Username => &greeter.username.value, Mode::Password => &greeter.buffer, Mode::Command => &greeter.buffer, - Mode::Users | Mode::Sessions | Mode::Power | Mode::Processing => return, + _ => return, }; let index = (value.chars().count() as i16 + greeter.cursor_offset) as usize; @@ -322,7 +324,7 @@ async fn delete_key(greeter: &mut Greeter, key: KeyCode) { Mode::Username => &greeter.username.value, Mode::Password => &greeter.buffer, Mode::Command => &greeter.buffer, - Mode::Users | Mode::Sessions | Mode::Power | Mode::Processing => return, + _ => return, }; let index = match key { @@ -341,7 +343,7 @@ async fn delete_key(greeter: &mut Greeter, key: KeyCode) { Mode::Username => greeter.username.value = value, Mode::Password => greeter.buffer = value, Mode::Command => greeter.buffer = value, - Mode::Users | Mode::Sessions | Mode::Power | Mode::Processing => return, + _ => return, }; if let KeyCode::Delete = key { diff --git a/src/ui/prompt.rs b/src/ui/prompt.rs index e752c21..8edbc07 100644 --- a/src/ui/prompt.rs +++ b/src/ui/prompt.rs @@ -35,11 +35,13 @@ pub fn draw(greeter: &mut Greeter, f: &mut Frame) -> Result<(u16, u16), Box Result<(u16, u16), Box { + Mode::Username | Mode::Password | Mode::Action => { f.render_widget(username_label, chunks[USERNAME_INDEX]); if !greeter.user_menu || !greeter.username.value.is_empty() { diff --git a/src/ui/util.rs b/src/ui/util.rs index 6b63d97..caade8a 100644 --- a/src/ui/util.rs +++ b/src/ui/util.rs @@ -18,6 +18,7 @@ pub fn should_hide_cursor(greeter: &Greeter) -> bool { || greeter.mode == Mode::Sessions || greeter.mode == Mode::Power || greeter.mode == Mode::Processing + || greeter.mode == Mode::Action } // Computes the height of the main window where we display content, depending on @@ -37,7 +38,7 @@ pub fn get_height(greeter: &Greeter) -> u16 { let prompt_padding = greeter.prompt_padding(); let initial = match greeter.mode { - Mode::Username | Mode::Command => (2 * container_padding) + 1, + Mode::Username | Mode::Action | Mode::Command => (2 * container_padding) + 1, Mode::Password => match greeter.prompt { Some(_) => (2 * container_padding) + prompt_padding + 2, None => (2 * container_padding) + 1,