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.
This commit is contained in:
Kyle Evans 2018-02-28 04:23:28 +00:00
parent b93bb974cc
commit 0901ba3aa1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=330098
2 changed files with 20 additions and 24 deletions

View File

@ -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

View File

@ -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