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

pedrosouza at FreeBSD.org pedrosouza at FreeBSD.org
Sun Sep 7 00:13:20 UTC 2014


Author: pedrosouza
Date: Sun Sep  7 00:13:17 2014
New Revision: 273744
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=273744

Log:
  Added proper loader color checking

Modified:
  soc2014/pedrosouza/lua_loader/head/sys/boot/lua/core.lua
  soc2014/pedrosouza/lua_loader/head/sys/boot/lua/drawer.lua
  soc2014/pedrosouza/lua_loader/head/sys/boot/lua/loader.lua
  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/core.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/core.lua	Sat Sep  6 22:38:32 2014	(r273743)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/core.lua	Sun Sep  7 00:13:17 2014	(r273744)
@@ -80,4 +80,25 @@
 
 function core.boot()
     loader.perform("boot");
+end
+
+function core.bootserial()
+    local c = loader.getenv("console");
+
+    if c ~= nil then
+        if c:find("comconsole") ~= nil then
+            return true;
+        end
+    end
+    
+    local s = loader.getenv("boot_serial");
+    if s ~= nil then
+        return true;
+    end
+
+    local m = loader.getenv("boot_multicons");
+    if m ~= nil then
+        return true;
+    end
+    return false;
 end
\ No newline at end of file

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/drawer.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/drawer.lua	Sat Sep  6 22:38:32 2014	(r273743)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/drawer.lua	Sun Sep  7 00:13:17 2014	(r273744)
@@ -111,9 +111,6 @@
     "         .---.....----."
 };
 
-function drawer.isColorEnabled()
-    return true;
-end
 
 function drawer.draw(x, y, logo)
     for i = 1, #logo do
@@ -126,11 +123,11 @@
     local x = tonumber(loader.getenv("loader_brand_x"));
     local y = tonumber(loader.getenv("loader_brand_y"));
     
-    if (x == nil) then x = drawer.brand_position.x; end
-    if (y == nil) then y = drawer.brand_position.y; end
+    if not x then x = drawer.brand_position.x; end
+    if not y then y = drawer.brand_position.y; end
     
     local logo = load("return " .. tostring(loader.getenv("loader_brand")))();
-    if (logo == nil) then logo = drawer.fbsd_logo; end
+    if not logo then logo = drawer.fbsd_logo; end
     drawer.draw(x, y, logo);
 end
 
@@ -138,20 +135,34 @@
     local x = tonumber(loader.getenv("loader_logo_x"));
     local y = tonumber(loader.getenv("loader_logo_y"));
     
-    if (x == nil) then x = drawer.logo_position.x; end
-    if (y == nil) then y = drawer.logo_position.y; end
+    if not x then x = drawer.logo_position.x; end
+    if not y then y = drawer.logo_position.y; end
     
     local logo = loader.getenv("loader_logo");
-    if (logo == "beastie") then logo = drawer.beastie_color; 
-    elseif (logo == "beastiebw") then logo = drawer.beastie;
-    elseif (logo == "fbsdbw") then logo = drawer.fbsd_logo_v;
-    elseif (logo == "orb") then logo = drawer.orb_color;
-    elseif (logo == "orbbw") then logo = drawer.orb;
-    elseif (logo == "tribute") then logo = drawer.fbsd_logo;
-    elseif (logo == "tributebw") then logo = drawer.fbsd_logo;
-    elseif (logo == nil) then
-        if (drawer.isColorEnabled() == true) then logo = drawer.orb_color;
+    local s = {x = 0, y = 0};
+    local colored = color.isEnabled();
+    
+    if logo == "beastie" then
+        if colored then logo = drawer.beastie_color; end
+    elseif logo == "beastiebw" then
+        logo = drawer.beastie;
+    elseif logo == "fbsdbw" then
+        logo = drawer.fbsd_logo_v;
+        s = drawer.fbsd_logo_shift;
+    elseif logo == "orb" then
+        if colored then logo = drawer.orb_color; end
+        s = drawer.orb_shift;
+    elseif logo == "orbbw" then
+        logo = drawer.orb;
+        s = drawer.orb_shift;
+    elseif logo == "tribute" then
+        logo = drawer.fbsd_logo;
+    elseif logo == "tributebw" then
+        logo = drawer.fbsd_logo;
+    end
+    if not logo then
+        if colored then logo = drawer.orb_color;
         else logo = drawer.orb; end
     end
-    drawer.draw(x, y, logo);
+    drawer.draw(x + s.x, y + s.y, logo);
 end
\ No newline at end of file

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/loader.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/loader.lua	Sat Sep  6 22:38:32 2014	(r273743)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/loader.lua	Sun Sep  7 00:13:17 2014	(r273744)
@@ -7,10 +7,11 @@
     end
 end
 
-include("/boot/menu.lua");
+
 include("/boot/password.lua");
 include("/boot/config.lua");
-
 config.load();
 password.check();
+
+include("/boot/menu.lua");
 menu.run();

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua	Sat Sep  6 22:38:32 2014	(r273743)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua	Sun Sep  7 00:13:17 2014	(r273744)
@@ -23,6 +23,13 @@
 end
 
 function menu.run(opts)
+
+    -- no escape code supported do not draw menu
+    if core.bootserial() then
+        core.autoboot();
+        return;
+    end
+
     if (opts == nil) then
         opts = menu.options;
     end
@@ -213,7 +220,7 @@
     if (b) then
         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
 

Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/screen.lua
==============================================================================
--- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/screen.lua	Sat Sep  6 22:38:32 2014	(r273743)
+++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/screen.lua	Sun Sep  7 00:13:17 2014	(r273744)
@@ -1,3 +1,5 @@
+include("/boot/core.lua");
+
 screen = {};
 color = {};
 
@@ -14,41 +16,62 @@
 color.BRIGHT  = 1;
 color.DIM     = 2;
 
+function color.isEnabled()
+    local c = loader.getenv("loader_color");
+    if c ~= nil then
+        if c:lower() == "no"  or c == "0" then
+            return false;
+        end
+    end
+    return not core.bootserial();
+end
+
+color.disabled = not color.isEnabled();
+
 
 function color.escapef(c)
+    if color.disabled then return c; end
     return "\027[3"..c.."m";
 end
 
 function color.escapeb(c)
+    if color.disabled then return c; end
     return "\027[4"..c.."m";
 end
 
 function color.escape(fg, bg, att)
+    if color.disabled then return ""; end
     if not att then att = "" else att = att..";"; end
     return "\027["..att.."3"..fg..";4"..bg.."m";
 end
 
 function color.default()
+    if color.disabled then return ""; end
     return "\027[0;37;40m";
 end
 
 function color.highlight(str)
+    if color.disabled then return str; end
     return "\027[1m"..str.."\027[0m";
 end
 
 function screen.clear()
+    if core.bootserial() then return; end
     print("\027[H\027[J");
 end
 
 function screen.setcursor(x, y)
+    if core.bootserial() then return; end
     print("\027["..y..";"..x.."H");
 end
 
 function screen.setforeground(c)
+    if color.disabled then return c; end
     print("\027[3"..c.."m");
 end
 
 function screen.setbackground(c)
+    if color.disabled then return c; end
     print("\027[4"..c.."m");
 end
 
@@ -57,5 +80,6 @@
 end
 
 function screen.defcursor()
+    if core.bootserial() then return; end
     print("\027[25;0H");
 end
\ No newline at end of file


More information about the svn-soc-all mailing list