stand/lua: Reduce magic numbers

Enter/backspace values are hardcoded in both the menu and password scripts.
Separate these out to core for reuse between the two.
This commit is contained in:
Kyle Evans 2018-02-16 03:12:24 +00:00
parent 27b95863a9
commit fe672a15db
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329349
3 changed files with 9 additions and 5 deletions

View File

@ -28,6 +28,10 @@
local core = {};
-- Commonly appearing constants
core.KEY_ENTER = 13
core.KEY_BACKSPACE = 127
function core.setVerbose(b)
if (b == nil) then
b = not core.verbose;

View File

@ -273,9 +273,9 @@ function menu.run(m)
local key = io.getchar();
-- Special key behaviors
if (key == 127) and (m ~= menu.welcome) then
if (key == core.KEY_BACKSPACE) and (m ~= menu.welcome) then
break
elseif (key == 13) then
elseif (key == core.KEY_ENTER) then
core.boot();
-- Should not return
end
@ -357,7 +357,7 @@ function menu.autoboot()
screen.defcursor();
if io.ischar() then
local ch = io.getchar();
if ch == 13 then
if ch == core.KEY_ENTER then
break;
else
-- prevent autoboot when escaping to interpreter

View File

@ -37,11 +37,11 @@ function password.read()
repeat
ch = io.getchar();
if ch == 13 then
if ch == core.KEY_ENTER then
break;
end
if ch == 8 then
if ch == core.KEY_BACKSPACE then
if n > 0 then
n = n - 1;
-- loader.printc("\008 \008");