Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Feb 2018 09:37:37 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Kyle Evans <kevans@freebsd.org>
Cc:        src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org,  svn-src-head@freebsd.org
Subject:   Re: svn commit: r329349 - head/stand/lua
Message-ID:  <CANCZdfrAXq-XDRSjNv_mwOv2EhU2FmTY8n0gXATpu0dptDu9Fg@mail.gmail.com>
In-Reply-To: <CACNAnaGDEOBjJGSz8eE4wKAg_GJLAbLA=Yg9P7hu9s3T7SEY7Q@mail.gmail.com>
References:  <201802160312.w1G3CO3r085739@repo.freebsd.org> <CACNAnaGDEOBjJGSz8eE4wKAg_GJLAbLA=Yg9P7hu9s3T7SEY7Q@mail.gmail.com>

index | next in thread | previous in thread | raw e-mail

On Feb 16, 2018 6:58 AM, "Kyle Evans" <kevans@freebsd.org> wrote:

On Thu, Feb 15, 2018 at 9:12 PM, Kyle Evans <kevans@freebsd.org> wrote:
> Author: kevans
> Date: Fri Feb 16 03:12:24 2018
> New Revision: 329349
> URL: https://svnweb.freebsd.org/changeset/base/329349
>
> Log:
>   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.
>
> Modified:
>   head/stand/lua/core.lua
>   head/stand/lua/menu.lua
>   head/stand/lua/password.lua
>
> Modified: head/stand/lua/core.lua
> ============================================================
==================
> --- head/stand/lua/core.lua     Fri Feb 16 01:33:01 2018        (r329348)
> +++ head/stand/lua/core.lua     Fri Feb 16 03:12:24 2018        (r329349)
> @@ -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;
>
> Modified: head/stand/lua/menu.lua
> ============================================================
==================
> --- head/stand/lua/menu.lua     Fri Feb 16 01:33:01 2018        (r329348)
> +++ head/stand/lua/menu.lua     Fri Feb 16 03:12:24 2018        (r329349)
> @@ -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
>
> Modified: head/stand/lua/password.lua
> ============================================================
==================
> --- head/stand/lua/password.lua Fri Feb 16 01:33:01 2018        (r329348)
> +++ head/stand/lua/password.lua Fri Feb 16 03:12:24 2018        (r329349)
> @@ -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

It's worth noting that this changes the comparison from 'ch == 8' to
'ch == 127'. The password prompt was non-functional on my test systems
until this change, because I can never type my password right the
first time. =)

Pointed out by: cem@


History has shown we likely want to  accept both BS (8) and DEL (127) as
logical 'backwards erase character' signals.

Warner


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfrAXq-XDRSjNv_mwOv2EhU2FmTY8n0gXATpu0dptDu9Fg>