Author: kevans
Date: Wed Feb 28 04:23:28 2018
New Revision: 330098
URL: https://svnweb.freebsd.org/changeset/base/330098

Log:
  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.

Modified:
  head/stand/lua/password.lua
  head/stand/lua/screen.lua

Modified: head/stand/lua/password.lua
==============================================================================
--- head/stand/lua/password.lua Wed Feb 28 02:49:48 2018        (r330097)
+++ head/stand/lua/password.lua Wed Feb 28 04:23:28 2018        (r330098)
@@ -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

Modified: head/stand/lua/screen.lua
==============================================================================
--- head/stand/lua/screen.lua   Wed Feb 28 02:49:48 2018        (r330097)
+++ head/stand/lua/screen.lua   Wed Feb 28 04:23:28 2018        (r330098)
@@ -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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to