Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Aug 2014 05:37:08 +0000
From:      "Wojciech A. Koszek" <wkoszek@freebsd.org>
To:        pedrosouza@freebsd.org
Cc:        svn-soc-all@freebsd.org
Subject:   Re: socsvn commit: r271623 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua
Message-ID:  <20140802053708.GB98217@FreeBSD.org>
In-Reply-To: <201407301950.s6UJovS1023444@socsvn.freebsd.org>
References:  <201407301950.s6UJovS1023444@socsvn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jul 30, 2014 at 07:50:57PM +0000, pedrosouza@freebsd.org wrote:
> Author: pedrosouza
> Date: Wed Jul 30 19:50:56 2014
> New Revision: 271623
> URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271623
> 
> Log:
>   Added boot menu shortcuts
>

Pedro,

I walked through all your last commits.

All your work looks pretty good. I don't see anything fundamentally wrong in
code your wrote. If I were to give feedback, in the order of priority:

The most crucial part would be to make sure password checking can't be
ommited. Thus we should try to do rigorous testing there. We should also
check if by doing strange things we can crash the Lua in a way that would
skip password checking. Make sure we catch all exceptions and error
conditions there.

To make this code easily mergable, we should probably target
src/sys/lua/. This way you can make 'lua*' utilities available to
users. Alternatively: src/sys/contrib/lua/.

It should be plain Lua source code, so that upgrading to new Luas as they
get released would be as simple as unpacking the .tar.bz2 there. The FreeBSD
wrapper for Lua loader could live in src/sys/boot/lua.

Think whether you also feel 80x25 rule for Lua code should be preserved. At
some point we could also start lua.style.8 man page.

Thanks for all this work. It's nice to see coming nicely along.

Wojciech

> Modified:
>   soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua
>   soc2014/pedrosouza/lua_loader/head/sys/boot/lua/screen.lua
> 
> Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua
> ==============================================================================
> --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua	Wed Jul 30 18:47:31 2014	(r271622)
> +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua	Wed Jul 30 19:50:56 2014	(r271623)
> @@ -8,13 +8,16 @@
>      screen.setcursor(x, y);
>      print("Boot Menu");
>      for k, v in pairs(opts) do
> -        screen.setcursor(x, y + v.index);
> -        local name = v.name;
> -        
> -        if (name == nil) then
> -            name = v.getName();
> +        -- skip alias
> +        if k ~= "alias" then
> +            screen.setcursor(x, y + v.index);
> +            local name = v.name;
> +            
> +            if (name == nil) then
> +                name = v.getName();
> +            end
> +            print(k .. " - " .. name);
>          end
> -        print(k .. " - " .. name);
>      end
>  end
>  
> @@ -29,6 +32,7 @@
>          menu.drawbox(4, 10, 40, 10);
>          drawer.drawbrand();
>          drawer.drawlogo();
> +        screen.defcursor();
>          local ch = string.char(io.getchar());
>          if (opts[ch] ~= nil) then
>              local ret = opts[ch].func();
> @@ -36,6 +40,17 @@
>                  print("Exiting menu!\n");
>                  return;
>              end
> +        else
> +        --try alias key
> +            if opts.alias ~= nil then
> +                if opts.alias[ch] ~= nil then
> +                    local ret = opts.alias[ch].func();
> +                    if (ret) then
> +                        print("Exiting menu!\n");
> +                        return;
> +                    end
> +                end
> +            end
>          end
>      end
>  end
> @@ -65,26 +80,39 @@
>  end
>  
>  menu.options = {
> -    ["1"] = {index = 1, name = "Boot Multi user",       func = function () core.setSingleUser(false); loader.perform("boot"); end},
> -    ["2"] = {index = 2, name = "Boot Single user",      func = function () core.setSingleUser(true); loader.perform("boot"); end},
> -    ["3"] = {index = 3, name = "Escape to lua interpreter", func = function () return true; end},
> -    ["4"] = {index = 4, name = "Reboot",                func = function () loader.perform("reboot"); end},
> -    ["5"] = {index = 5, name = "Boot Options",          func = function () menu.run(boot_options); return false; end} 
> +    -- Boot multi user
> +    ["1"] = {index = 1, name = color.highlight("B").."oot Multi user", func = function () core.setSingleUser(false); loader.perform("boot"); end},
> +    -- boot single user
> +    ["2"] = {index = 2, name = "Boot "..color.highlight("S").."ingle user",  func = function () core.setSingleUser(true); loader.perform("boot"); end},
> +    -- escape to interpreter
> +    ["3"] = {index = 3, name = color.highlight("E").."scape to lua interpreter", func = function () return true; end},
> +    -- reboot
> +    ["4"] = {index = 4, name = color.highlight("R").."eboot", func = function () loader.perform("reboot"); end},
> +    -- boot options
> +    ["5"] = {index = 5, name = "Boot "..color.highlight("O").."ptions", func = function () menu.run(boot_options); return false; end} 
> +};
> +
> +menu.options.alias = {
> +    ["b"] = menu.options["1"],
> +    ["s"] = menu.options["2"],
> +    ["e"] = menu.options["3"],
> +    ["r"] = menu.options["4"],
> +    ["o"] = menu.options["5"]
>  };
>  
>  function OnOff(str, b)
>      if (b) then
> -        return str .. color.escapef(color.GREEN)..": On"..color.escapef(color.WHITE);
> +        return str .. color.escapef(color.GREEN).."On"..color.escapef(color.WHITE);
>      else
> -        return str .. color.escapef(color.RED)..": Off"..color.escapef(color.WHITE);
> +        return str .. color.escapef(color.RED).."Off"..color.escapef(color.WHITE);
>      end
>  end
>  
>  boot_options = {
>      ["1"] = {index = 1, name = "Back to menu", func = function () return true; end },
>      ["2"] = {index = 2, name = "Load System defaults", func = function () core.setDefaults(); return false; end },
> -    ["3"] = {index = 3, getName = function () return OnOff("ACPI       ", core.acpi); end, func = function () core.setACPI(); return false; end },
> -    ["4"] = {index = 4, getName = function () return OnOff("Safe Mode  ", core.sm); end,   func = function () core.setSafeMode(); return false; end },
> -    ["5"] = {index = 5, getName = function () return OnOff("Single user", core.su); end,   func = function () core.setSingleUser(); return false; end },
> -    ["6"] = {index = 6, getName = function () return OnOff("Verbose    ", core.verbose); end, func = function () core.setVerbose(); return false; end }
> +    ["3"] = {index = 3, getName = function () return OnOff("ACPI       :", core.acpi); end, func = function () core.setACPI(); return false; end },
> +    ["4"] = {index = 4, getName = function () return OnOff("Safe Mode  :", core.sm); end,   func = function () core.setSafeMode(); return false; end },
> +    ["5"] = {index = 5, getName = function () return OnOff("Single user:", core.su); end,   func = function () core.setSingleUser(); return false; end },
> +    ["6"] = {index = 6, getName = function () return OnOff("Verbose    :", core.verbose); end, func = function () core.setVerbose(); return false; end }
>  }
> \ No newline at end of file
> 
> Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/screen.lua
> ==============================================================================
> --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/screen.lua	Wed Jul 30 18:47:31 2014	(r271622)
> +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/screen.lua	Wed Jul 30 19:50:56 2014	(r271623)
> @@ -32,6 +32,10 @@
>      return "\027[0;37;40m";
>  end
>  
> +function color.highlight(str)
> +    return "\027[1m"..str.."\027[0m";
> +end
> +
>  function screen.clear()
>      print("\027[H\027[J");
>  end
> @@ -53,5 +57,5 @@
>  end
>  
>  function screen.defcursor()
> -    print("\027[24;0H");
> +    print("\027[25;0H");
>  end
> \ No newline at end of file
> _______________________________________________
> svn-soc-all@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/svn-soc-all
> To unsubscribe, send any mail to "svn-soc-all-unsubscribe@freebsd.org"

-- 
Wojciech A. Koszek
wkoszek@FreeBSD.czest.pl
http://FreeBSD.czest.pl/~wkoszek/



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