From fe672a15db5b32f0cb57ed64b847b7586ca1c8c2 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Fri, 16 Feb 2018 03:12:24 +0000 Subject: [PATCH] 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. --- stand/lua/core.lua | 4 ++++ stand/lua/menu.lua | 6 +++--- stand/lua/password.lua | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/stand/lua/core.lua b/stand/lua/core.lua index 169bcf5d652f..d523493993fd 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -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; diff --git a/stand/lua/menu.lua b/stand/lua/menu.lua index d07512f0da4a..a9bc1682baf1 100644 --- a/stand/lua/menu.lua +++ b/stand/lua/menu.lua @@ -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 diff --git a/stand/lua/password.lua b/stand/lua/password.lua index cf9cbd9aaa5c..f4da63e2180f 100644 --- a/stand/lua/password.lua +++ b/stand/lua/password.lua @@ -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");