socsvn commit: r271623 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua

pedrosouza at FreeBSD.org pedrosouza at FreeBSD.org
Wed Jul 30 19:50:58 UTC 2014


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

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


More information about the svn-soc-all mailing list