Date: Tue, 27 Feb 2018 21:22:57 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r330082 - head/stand/lua Message-ID: <201802272122.w1RLMvpV018412@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Tue Feb 27 21:22:57 2018 New Revision: 330082 URL: https://svnweb.freebsd.org/changeset/base/330082 Log: 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. Modified: head/stand/lua/password.lua head/stand/lua/screen.lua Modified: head/stand/lua/password.lua ============================================================================== --- head/stand/lua/password.lua Tue Feb 27 19:24:06 2018 (r330081) +++ head/stand/lua/password.lua Tue Feb 27 21:22:57 2018 (r330082) @@ -33,27 +33,46 @@ local core = require("core") local screen = require("screen") local password = {} +-- Asterisks as a password mask +local show_password_mask = false +local twiddle_chars = {"/", "-", "\\", "|"} +local twiddle_pos = 1 -- Module exports function password.read() local str = "" 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 local ch = io.getchar() if ch == core.KEY_ENTER then break 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 n > 0 then 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) end else - -- loader.printc("*") + if show_password_mask then + loader.printc("*") + else + draw_twiddle() + end str = str .. string.char(ch) n = n + 1 end Modified: head/stand/lua/screen.lua ============================================================================== --- head/stand/lua/screen.lua Tue Feb 27 19:24:06 2018 (r330081) +++ head/stand/lua/screen.lua Tue Feb 27 21:22:57 2018 (r330082) @@ -49,6 +49,24 @@ function screen.setcursor(x, y) loader.printc("\027[" .. y .. ";" .. x .. "H") 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) if color.disabled then return color_value
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802272122.w1RLMvpV018412>