From 0901ba3aa149d7453e65d98ee8083237dd5db9f0 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Wed, 28 Feb 2018 04:23:28 +0000 Subject: [PATCH] lualoader: Re-do twiddle It worked on my test setup, but is clearly non-functional on others. Further examination of check-password.4th showed that it actually reset the cursor to 0,25 every time and overwrote the previous password prompt. Do that, and also clear the "Incorrect Password" text if the correct password gets entered. --- stand/lua/password.lua | 26 ++++++++++++++++++++------ stand/lua/screen.lua | 18 ------------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/stand/lua/password.lua b/stand/lua/password.lua index c00e51ee34d..d14dec67543 100644 --- a/stand/lua/password.lua +++ b/stand/lua/password.lua @@ -33,19 +33,21 @@ local core = require("core") local screen = require("screen") local password = {} + +local INCORRECT_PASSWORD = "loader: incorrect password!" -- Asterisks as a password mask local show_password_mask = false local twiddle_chars = {"/", "-", "\\", "|"} -- Module exports -function password.read() +function password.read(prompt_length) local str = "" local n = 0 local twiddle_pos = 1 local function draw_twiddle() loader.printc(" " .. twiddle_chars[twiddle_pos]) - screen.movecursor(-3, 0) + screen.setcursor(prompt_length + 2, 25) twiddle_pos = (twiddle_pos % #twiddle_chars) + 1 end @@ -84,15 +86,27 @@ function password.check() screen.defcursor() -- pwd is optionally supplied if we want to check it local function doPrompt(prompt, pwd) + local attempts = 1 + + local function clear_incorrect_text_prompt() + loader.printc("\n") + loader.printc(string.rep(" ", #INCORRECT_PASSWORD)) + end + while true do + screen.defcursor() loader.printc(prompt) - local read_pwd = password.read() + local read_pwd = password.read(#prompt) if pwd == nil or pwd == read_pwd then - -- Throw an extra newline after password prompt - print("") + -- Clear the prompt + twiddle + loader.printc(string.rep(" ", #prompt + 5)) + if attempts > 1 then + clear_incorrect_text_prompt() + end return read_pwd end - print("\n\nloader: incorrect password!\n") + loader.printc("\n" .. INCORRECT_PASSWORD) + attempts = attempts + 1 loader.delay(3*1000*1000) end end diff --git a/stand/lua/screen.lua b/stand/lua/screen.lua index feea0e60287..04ab98817c3 100644 --- a/stand/lua/screen.lua +++ b/stand/lua/screen.lua @@ -49,24 +49,6 @@ function screen.setcursor(x, y) loader.printc(core.KEYSTR_CSI .. y .. ";" .. x .. "H") end -function screen.movecursor(dx, dy) - if core.isSerialBoot() then - return - end - - if dx < 0 then - loader.printc(core.KEYSTR_CSI .. -dx .. "D") - elseif dx > 0 then - loader.printc(core.KEYSTR_CSI .. dx .. "C") - end - - if dy < 0 then - loader.printc(core.KEYSTR_CSI .. -dy .. "A") - elseif dy > 0 then - loader.printc(core.KEYSTR_CSI .. dy .. "B") - end -end - function screen.setforeground(color_value) if color.disabled then return color_value