From owner-svn-src-all@freebsd.org Sat Feb 17 05:52:26 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 90E63F11884; Sat, 17 Feb 2018 05:52:26 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 33A6468840; Sat, 17 Feb 2018 05:52:26 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2E7D518A67; Sat, 17 Feb 2018 05:52:26 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1H5qQM1097614; Sat, 17 Feb 2018 05:52:26 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1H5qPX4097607; Sat, 17 Feb 2018 05:52:25 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802170552.w1H5qPX4097607@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 17 Feb 2018 05:52:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329435 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 329435 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Feb 2018 05:52:26 -0000 Author: kevans Date: Sat Feb 17 05:52:25 2018 New Revision: 329435 URL: https://svnweb.freebsd.org/changeset/base/329435 Log: stand/lua: Style pass These are the style points that I'd like to try and maintain in our lua scripts: - Parentheses around conditionals - Trailing semicolons, except on block terminators - s:method(...) instead of string.method(s, ...) where applicable There's likely more, but that'll get hammered out as we continue. Modified: head/stand/lua/color.lua head/stand/lua/config.lua head/stand/lua/core.lua head/stand/lua/drawer.lua head/stand/lua/menu.lua head/stand/lua/password.lua head/stand/lua/screen.lua Modified: head/stand/lua/color.lua ============================================================================== --- head/stand/lua/color.lua Sat Feb 17 05:28:06 2018 (r329434) +++ head/stand/lua/color.lua Sat Feb 17 05:52:25 2018 (r329435) @@ -45,36 +45,35 @@ color.DIM = 2; function color.isEnabled() local c = loader.getenv("loader_color"); - if c ~= nil then - if c:lower() == "no" or c == "0" then + if (c ~= nil) then + if (c:lower() == "no") or (c == "0") then return false; end end - return not core.bootserial(); + return (not core.bootserial()); end -color.disabled = not color.isEnabled(); +color.disabled = (not color.isEnabled()); - function color.escapef(c) - if color.disabled then + if (color.disabled) then return c; end return "\027[3"..c.."m"; end function color.escapeb(c) - if color.disabled then + if (color.disabled) then return c; end return "\027[4"..c.."m"; end function color.escape(fg, bg, att) - if color.disabled then + if (color.disabled) then return ""; end - if not att then + if (not att) then att = "" else att = att..";"; @@ -83,17 +82,17 @@ function color.escape(fg, bg, att) end function color.default() - if color.disabled then + if (color.disabled) then return ""; end return "\027[0;37;40m"; end function color.highlight(str) - if color.disabled then + if (color.disabled) then return str; end return "\027[1m"..str.."\027[0m"; end -return color +return color; Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Sat Feb 17 05:28:06 2018 (r329434) +++ head/stand/lua/config.lua Sat Feb 17 05:52:25 2018 (r329435) @@ -280,7 +280,7 @@ function config.loadkernel(other_kernel) end return try_load(bootfile); - end; + end -- kernel not set, try load from default module_path if kernel == nil then Modified: head/stand/lua/core.lua ============================================================================== --- head/stand/lua/core.lua Sat Feb 17 05:28:06 2018 (r329434) +++ head/stand/lua/core.lua Sat Feb 17 05:52:25 2018 (r329435) @@ -128,13 +128,13 @@ function core.kernelList() local kernels = {}; local i = 0; - if k ~= nil then + if (k ~= nil) then i = i + 1; kernels[i] = k; end for n in v:gmatch("([^; ]+)[; ]?") do - if n ~= k then + if (n ~= k) then i = i + 1; kernels[i] = n; end @@ -160,23 +160,23 @@ end function core.bootserial() local c = loader.getenv("console"); - if c ~= nil then - if c:find("comconsole") ~= nil then + if (c ~= nil) then + if (c:find("comconsole") ~= nil) then return true; end end local s = loader.getenv("boot_serial"); - if s ~= nil then + if (s ~= nil) then return true; end local m = loader.getenv("boot_multicons"); - if m ~= nil then + if (m ~= nil) then return true; end return false; end -core.setACPI(core.getACPIPresent(false)) -return core +core.setACPI(core.getACPIPresent(false)); +return core; Modified: head/stand/lua/drawer.lua ============================================================================== --- head/stand/lua/drawer.lua Sat Feb 17 05:28:06 2018 (r329434) +++ head/stand/lua/drawer.lua Sat Feb 17 05:52:25 2018 (r329435) @@ -179,7 +179,7 @@ function drawer.drawmenu(m) if (#choices < caridx) then caridx = 1; - end; + end name = e.name(caridx, choices[caridx], choices); else name = e.name(); @@ -247,60 +247,48 @@ function drawer.draw(x, y, logo) end function drawer.drawbrand() - local x = tonumber(loader.getenv("loader_brand_x")); - local y = tonumber(loader.getenv("loader_brand_y")); + local x = tonumber(loader.getenv("loader_brand_x")) or + drawer.brand_position.x; + local y = tonumber(loader.getenv("loader_brand_y")) or + drawer.brand_position.y; - 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 not logo then - logo = drawer.fbsd_logo; - end + local logo = load("return " .. tostring(loader.getenv("loader_brand")))() or + drawer.fbsd_logo; drawer.draw(x, y, logo); end function drawer.drawlogo() - local x = tonumber(loader.getenv("loader_logo_x")); - local y = tonumber(loader.getenv("loader_logo_y")); + local x = tonumber(loader.getenv("loader_logo_x")) or + drawer.logo_position.x; + local y = tonumber(loader.getenv("loader_logo_y")) or + drawer.logo_position.y; - 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"); local s = {x = 0, y = 0}; local colored = color.isEnabled(); - if logo == "beastie" then - if colored then + if (logo == "beastie") then + if (colored) then logo = drawer.beastie_color; end - elseif logo == "beastiebw" then + elseif (logo == "beastiebw") then logo = drawer.beastie; - elseif logo == "fbsdbw" then + elseif (logo == "fbsdbw") then logo = drawer.fbsd_logo_v; s = drawer.fbsd_logo_shift; - elseif logo == "orb" then - if colored then + elseif (logo == "orb") then + if (colored) then logo = drawer.orb_color; end s = drawer.orb_shift; - elseif logo == "orbbw" then + elseif (logo == "orbbw") then logo = drawer.orb; s = drawer.orb_shift; - elseif logo == "tribute" then + elseif (logo == "tribute") then logo = drawer.fbsd_logo; - elseif logo == "tributebw" then + elseif (logo == "tributebw") then logo = drawer.fbsd_logo; - elseif logo == "none" then + elseif (logo == "none") then --centre brand and text if no logo drawer.brand_position.x = drawer.brand_position.x + drawer.none_shift.x; drawer.brand_position.y = drawer.brand_position.y + drawer.none_shift.y; @@ -313,8 +301,8 @@ function drawer.drawlogo() drawer.none_shift.y = 0; logo = drawer.none; end - if not logo then - if colored then + if (not logo) then + if (colored) then logo = drawer.orb_color; else logo = drawer.orb; @@ -323,4 +311,4 @@ function drawer.drawlogo() drawer.draw(x + s.x, y + s.y, logo); end -return drawer +return drawer; Modified: head/stand/lua/menu.lua ============================================================================== --- head/stand/lua/menu.lua Sat Feb 17 05:28:06 2018 (r329434) +++ head/stand/lua/menu.lua Sat Feb 17 05:52:25 2018 (r329435) @@ -63,7 +63,7 @@ menu.boot_options = { return "Load System "..color.highlight("D").."efaults"; end, func = function() - core.setDefaults() + core.setDefaults(); end, alias = {"d", "D"} }, @@ -162,7 +162,7 @@ menu.welcome = { return color.highlight("Esc").."ape to loader prompt"; end, func = function() - loader.setenv("autoboot_delay", "NO") + loader.setenv("autoboot_delay", "NO"); end, alias = {core.KEYSTR_ESCAPE} }, @@ -200,14 +200,14 @@ menu.welcome = { carousel_id = "kernel", items = core.kernelList, name = function(idx, choice, all_choices) - if #all_choices == 0 then + if (#all_choices == 0) then return "Kernel: "; end local is_default = (idx == 1); local kernel_name = ""; local name_color; - if is_default then + if (is_default) then name_color = color.escapef(color.GREEN); kernel_name = "default/"; else @@ -273,7 +273,7 @@ function menu.run(m) menu.autoboot(); cont = true; - while cont do + while (cont) do local key = io.getchar(); -- Special key behaviors @@ -295,7 +295,7 @@ function menu.run(m) end -- if we have an alias do the assigned action: - if(sel_entry ~= nil) then + if (sel_entry ~= nil) then if (sel_entry.entry_type == core.MENU_ENTRY) then -- run function sel_entry.func(); @@ -339,11 +339,11 @@ function menu.run(m) end function menu.skip() - if core.bootserial() then + if (core.bootserial() )then return true; end local c = string.lower(loader.getenv("console") or ""); - if (c:match("^efi[ ;]") or c:match("[ ;]efi[ ;]")) ~= nil then + if ((c:match("^efi[ ;]") or c:match("[ ;]efi[ ;]")) ~= nil) then return true; end @@ -353,7 +353,7 @@ function menu.skip() end function menu.autoboot() - if menu.already_autoboot == true then + if (menu.already_autoboot == true) then return; end menu.already_autoboot = true; @@ -378,9 +378,9 @@ function menu.autoboot() print("Autoboot in "..time.." seconds, hit [Enter] to boot" .." or any other key to stop "); screen.defcursor(); - if io.ischar() then + if (io.ischar()) then local ch = io.getchar(); - if ch == core.KEY_ENTER then + if (ch == core.KEY_ENTER) then break; else -- erase autoboot msg @@ -406,4 +406,4 @@ function OnOff(str, b) end end -return menu +return menu; Modified: head/stand/lua/password.lua ============================================================================== --- head/stand/lua/password.lua Sat Feb 17 05:28:06 2018 (r329434) +++ head/stand/lua/password.lua Sat Feb 17 05:52:25 2018 (r329435) @@ -37,23 +37,23 @@ function password.read() repeat ch = io.getchar(); - if ch == core.KEY_ENTER then + if (ch == core.KEY_ENTER) then break; end -- XXX TODO: Evaluate if we really want this or not, as a -- security consideration of sorts if (ch == core.KEY_BACKSPACE) or (ch == core.KEY_DELETE) then - if n > 0 then + if (n > 0) then n = n - 1; -- loader.printc("\008 \008"); - str = string.sub(str, 1, n); + str = str:sub(1, n); end else -- loader.printc("*"); str = str .. string.char(ch); n = n + 1; end - until n == 16 + until (n == 16); return str; end @@ -61,17 +61,17 @@ function password.check() screen.defcursor(); -- pwd is optionally supplied if we want to check it local function do_prompt(prompt, pwd) - while true do + while (true) do loader.printc(prompt); local read_pwd = password.read(); if (not pwd) or (pwd == read_pwd) then + -- Throw an extra newline after password prompt + print(""); return read_pwd; end print("\n\nloader: incorrect password!\n"); loader.delay(3*1000*1000); end - -- Throw an extra newline out after the password prompt - print("") end local function compare(prompt, pwd) if (pwd == nil) then @@ -80,20 +80,20 @@ function password.check() do_prompt(prompt, pwd); end - local boot_pwd = loader.getenv("bootlock_password"); + local boot_pwd = "boot" --loader.getenv("bootlock_password"); compare("Boot password: ", boot_pwd); local geli_prompt = loader.getenv("geom_eli_passphrase_prompt"); if (geli_prompt ~= nil) and (geli_prompt:lower() == "yes") then local passphrase = do_prompt("GELI Passphrase: "); - loader.setenv("kern.geom.eli.passphrase", passphrase) + loader.setenv("kern.geom.eli.passphrase", passphrase); end local pwd = loader.getenv("password"); - if (pwd ~=nil) then + if (pwd ~= nil) then core.autoboot(); end compare("Password: ", pwd); end -return password +return password; Modified: head/stand/lua/screen.lua ============================================================================== --- head/stand/lua/screen.lua Sat Feb 17 05:28:06 2018 (r329434) +++ head/stand/lua/screen.lua Sat Feb 17 05:52:25 2018 (r329435) @@ -33,24 +33,24 @@ local core = require("core"); -- XXX TODO: This should be fixed in the interpreter to not print decimals function intstring(num) - local str = tostring(num) - local decimal = string.find(str, "%.") + local str = tostring(num); + local decimal = str:find("%."); - if decimal then - return string.sub(str, 1, decimal - 1) + if (decimal) then + return str:sub(1, decimal - 1); end - return str + return str; end function screen.clear() - if core.bootserial() then + if (core.bootserial()) then return; end loader.printc("\027[H\027[J"); end function screen.setcursor(x, y) - if core.bootserial() then + if (core.bootserial()) then return; end @@ -58,14 +58,14 @@ function screen.setcursor(x, y) end function screen.setforeground(c) - if color.disabled then + if (color.disabled) then return c; end loader.printc("\027[3"..c.."m"); end function screen.setbackground(c) - if color.disabled then + if (color.disabled) then return c; end loader.printc("\027[4"..c.."m"); @@ -76,10 +76,10 @@ function screen.defcolor() end function screen.defcursor() - if core.bootserial() then + if (core.bootserial()) then return; end loader.printc("\027[25;0H"); end -return screen +return screen;