grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] password: Fix backspace in username prompt


From: Egor Ignatov
Subject: [PATCH] password: Fix backspace in username prompt
Date: Thu, 4 Mar 2021 18:41:34 +0300

From: Egor Ignatov <egori@altlinux.org>

Make backspace work in superuser login prompt.

The problem was that bidi logical to visual ignored BN type,
so you couldn't print control characters.

Use grub_printf() 3 times, because if you print "\b \b" at
once the cursor will get stuck on the second last character.

Resolves: #60114
Signed-off-by: Egor Ignatov <egori@altlinux.org>
---
 grub-core/normal/auth.c    | 10 +++++++++-
 grub-core/normal/charset.c |  1 +
 grub-core/term/gfxterm.c   |  9 ++++++++-
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/grub-core/normal/auth.c b/grub-core/normal/auth.c
index 6be678c0d..cf57a1b7e 100644
--- a/grub-core/normal/auth.c
+++ b/grub-core/normal/auth.c
@@ -177,7 +177,15 @@ grub_username_get (char buf[], unsigned buf_size)
          if (cur_len)
            {
              cur_len--;
-             grub_printf ("\b \b");
+             /* NOTE(egori@altlinux.org):
+                grub_printf used 3 times, because for some reason
+                (line wrapping I guess) if you print "\b \b" at once
+                the backspace key doesn't work on the second last
+                character.
+             */
+             grub_printf ("\b");
+             grub_printf (" ");
+             grub_printf ("\b");
            }
          continue;
        }
diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c
index 4dfcc3107..77073c12f 100644
--- a/grub-core/normal/charset.c
+++ b/grub-core/normal/charset.c
@@ -931,6 +931,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t 
*logical,
            pop_stack ();
            break;
          case GRUB_BIDI_TYPE_BN:
+           visual_len++;
            break;
          case GRUB_BIDI_TYPE_R:
          case GRUB_BIDI_TYPE_AL:
diff --git a/grub-core/term/gfxterm.c b/grub-core/term/gfxterm.c
index af7c090a3..5b0660cd2 100644
--- a/grub-core/term/gfxterm.c
+++ b/grub-core/term/gfxterm.c
@@ -847,7 +847,14 @@ grub_gfxterm_putchar (struct grub_term_output *term,
         {
         case '\b':
           if (virtual_screen.cursor_x > 0)
-            virtual_screen.cursor_x--;
+            {
+              virtual_screen.cursor_x--;
+            }
+          else if (virtual_screen.cursor_y > 0)
+            {
+              virtual_screen.cursor_y--;
+              virtual_screen.cursor_x = virtual_screen.columns-2;
+            }
           break;
 
         case '\n':
-- 
2.25.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]