lualoader: Add a twiddle at password prompt
This gives some form of feedback while typing, and matches-(ish*) Forth behavior. The cursor generally rests two column after the password prompt, then the twiddle is drawn three columns later and the cursor reset to resting position after being drawn. I've removed the note about re-evaluating it for security considerations and instead set it up as a module-local variable that we can set later depending on environment or something. It's set to false with no chance of changing at the moment. *As close as I can tell from reading check-password.4th, because I don't have an easy test (or deployed) setup for forth loader to check how close it is. Please do mention if it's not close enough.
This commit is contained in:
parent
6b554d26ed
commit
a6f1506f1a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=330082
@ -33,27 +33,46 @@ local core = require("core")
|
|||||||
local screen = require("screen")
|
local screen = require("screen")
|
||||||
|
|
||||||
local password = {}
|
local password = {}
|
||||||
|
-- Asterisks as a password mask
|
||||||
|
local show_password_mask = false
|
||||||
|
local twiddle_chars = {"/", "-", "\\", "|"}
|
||||||
|
local twiddle_pos = 1
|
||||||
|
|
||||||
-- Module exports
|
-- Module exports
|
||||||
function password.read()
|
function password.read()
|
||||||
local str = ""
|
local str = ""
|
||||||
local n = 0
|
local n = 0
|
||||||
|
|
||||||
|
twiddle_pos = 1
|
||||||
|
local function draw_twiddle()
|
||||||
|
loader.printc(" " .. twiddle_chars[twiddle_pos])
|
||||||
|
screen.movecursor(-3, -1)
|
||||||
|
twiddle_pos = (twiddle_pos % #twiddle_chars) + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Space between the prompt and any on-screen feedback
|
||||||
|
loader.printc(" ")
|
||||||
while true do
|
while true do
|
||||||
local ch = io.getchar()
|
local ch = io.getchar()
|
||||||
if ch == core.KEY_ENTER then
|
if ch == core.KEY_ENTER then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
-- XXX TODO: Evaluate if we really want this or not, as a
|
|
||||||
-- security consideration of sorts
|
|
||||||
if ch == core.KEY_BACKSPACE or ch == core.KEY_DELETE then
|
if ch == core.KEY_BACKSPACE or ch == core.KEY_DELETE then
|
||||||
if n > 0 then
|
if n > 0 then
|
||||||
n = n - 1
|
n = n - 1
|
||||||
-- loader.printc("\008 \008")
|
if show_password_mask then
|
||||||
|
loader.printc("\008 \008")
|
||||||
|
else
|
||||||
|
draw_twiddle()
|
||||||
|
end
|
||||||
str = str:sub(1, n)
|
str = str:sub(1, n)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- loader.printc("*")
|
if show_password_mask then
|
||||||
|
loader.printc("*")
|
||||||
|
else
|
||||||
|
draw_twiddle()
|
||||||
|
end
|
||||||
str = str .. string.char(ch)
|
str = str .. string.char(ch)
|
||||||
n = n + 1
|
n = n + 1
|
||||||
end
|
end
|
||||||
|
@ -49,6 +49,24 @@ function screen.setcursor(x, y)
|
|||||||
loader.printc("\027[" .. y .. ";" .. x .. "H")
|
loader.printc("\027[" .. y .. ";" .. x .. "H")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function screen.movecursor(dx, dy)
|
||||||
|
if core.isSerialBoot() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if dx < 0 then
|
||||||
|
loader.printc("\027[" .. -dx .. "D")
|
||||||
|
elseif dx > 0 then
|
||||||
|
loader.printc("\027[" .. dx .. "C")
|
||||||
|
end
|
||||||
|
|
||||||
|
if dy < 0 then
|
||||||
|
loader.printc("\027[" .. -dy .. "A")
|
||||||
|
elseif dy > 0 then
|
||||||
|
loader.printc("\027[" .. dy .. "B")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function screen.setforeground(color_value)
|
function screen.setforeground(color_value)
|
||||||
if color.disabled then
|
if color.disabled then
|
||||||
return color_value
|
return color_value
|
||||||
|
Loading…
Reference in New Issue
Block a user