]> git.seodisparate.com - mpd_info_screen/commitdiff
WIP Impl --pprompt
authorStephen Seo <seo.disparate@gmail.com>
Wed, 15 Dec 2021 05:55:20 +0000 (14:55 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 15 Dec 2021 05:55:20 +0000 (14:55 +0900)
src/display.rs

index d2b890e421280bc2f7f0fb0980f8f5b6b24b5010..c55c03642e8617f914c71b9bdc40d8c7be43cb56 100644 (file)
@@ -117,7 +117,11 @@ impl EventHandler for MPDDisplay {
     }
 
     fn text_input_event(&mut self, _ctx: &mut Context, character: char) {
-        if !self.is_initialized && self.opts.enable_prompt_password {
+        if !self.is_initialized
+            && self.opts.enable_prompt_password
+            && character.is_ascii()
+            && !character.is_ascii_control()
+        {
             if self.opts.password.is_none() {
                 let s = String::from(character);
                 self.opts.password = Some(s);
@@ -143,8 +147,13 @@ impl EventHandler for MPDDisplay {
                 if s.ends_with("*") {
                     self.notice_text = Text::new(TextFragment::new(s[0..(s.len() - 1)].to_owned()));
                 }
+
+                if let Some(input_p) = &mut self.opts.password {
+                    input_p.pop();
+                }
             } else if keycode == event::KeyCode::Return {
                 self.password_entered = true;
+                //log(format!("Entered \"{}\"", self.opts.password.as_ref().unwrap_or(&String::new())));
             }
         }
     }