From owner-svn-src-all@freebsd.org Wed Feb 28 04:23:29 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0C3DBF26477; Wed, 28 Feb 2018 04:23:29 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B29EB82D98; Wed, 28 Feb 2018 04:23:28 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 937D51497E; Wed, 28 Feb 2018 04:23:28 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1S4NSGv042634; Wed, 28 Feb 2018 04:23:28 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1S4NSME042632; Wed, 28 Feb 2018 04:23:28 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802280423.w1S4NSME042632@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 28 Feb 2018 04:23:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r330098 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 330098 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Feb 2018 04:23:29 -0000 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