svn commit: r338065 - head/stand/lua

Kyle Evans kevans at FreeBSD.org
Sun Aug 19 18:22:02 UTC 2018


Author: kevans
Date: Sun Aug 19 18:22:01 2018
New Revision: 338065
URL: https://svnweb.freebsd.org/changeset/base/338065

Log:
  lualoader: Hide most of the internal drawing functions
  
  Ideally, all of the functionality to revamp the loader screen has associated
  APIs that are flexible enough that third-party scripts wouldn't need to
  override these.

Modified:
  head/stand/lua/drawer.lua

Modified: head/stand/lua/drawer.lua
==============================================================================
--- head/stand/lua/drawer.lua	Sun Aug 19 18:18:19 2018	(r338064)
+++ head/stand/lua/drawer.lua	Sun Aug 19 18:22:01 2018	(r338065)
@@ -90,131 +90,7 @@ local function draw(x, y, logo)
 	end
 end
 
-fbsd_brand = {
-"  ______               ____   _____ _____  ",
-" |  ____|             |  _ \\ / ____|  __ \\ ",
-" | |___ _ __ ___  ___ | |_) | (___ | |  | |",
-" |  ___| '__/ _ \\/ _ \\|  _ < \\___ \\| |  | |",
-" | |   | | |  __/  __/| |_) |____) | |__| |",
-" | |   | | |    |    ||     |      |      |",
-" |_|   |_|  \\___|\\___||____/|_____/|_____/ "
-}
-none = {""}
-
--- Module exports
-drawer.default_brand = 'fbsd'
-
-drawer.menu_name_handlers = {
-	-- Menu name handlers should take the menu being drawn and entry being
-	-- drawn as parameters, and return the name of the item.
-	-- This is designed so that everything, including menu separators, may
-	-- have their names derived differently. The default action for entry
-	-- types not specified here is to use entry.name directly.
-	[core.MENU_SEPARATOR] = function(_, entry)
-		if entry.name ~= nil then
-			if type(entry.name) == "function" then
-				return entry.name()
-			end
-			return entry.name
-		end
-		return ""
-	end,
-	[core.MENU_CAROUSEL_ENTRY] = function(_, entry)
-		local carid = entry.carousel_id
-		local caridx = config.getCarouselIndex(carid)
-		local choices = entry.items
-		if type(choices) == "function" then
-			choices = choices()
-		end
-		if #choices < caridx then
-			caridx = 1
-		end
-		return entry.name(caridx, choices[caridx], choices)
-	end,
-}
-
-drawer.brand_position = {x = 2, y = 1}
-drawer.logo_position = {x = 46, y = 4}
-drawer.menu_position = {x = 5, y = 10}
-drawer.frame_size = {w = 42, h = 13}
-drawer.default_shift = {x = 0, y = 0}
-drawer.shift = drawer.default_shift
-
-drawer.branddefs = {
-	-- Indexed by valid values for loader_brand in loader.conf(5). Valid
-	-- keys are: graphic (table depicting graphic)
-	["fbsd"] = {
-		graphic = fbsd_brand,
-	},
-	["none"] = {
-		graphic = none,
-	},
-}
-
-function drawer.addBrand(name, def)
-	drawer.branddefs[name] = def
-end
-
-function drawer.addLogo(name, def)
-	drawer.logodefs[name] = def
-end
-
-drawer.logodefs = {
-	-- Indexed by valid values for loader_logo in loader.conf(5). Valid keys
-	-- are: requires_color (boolean), graphic (table depicting graphic), and
-	-- shift (table containing x and y).
-	["tribute"] = {
-		graphic = fbsd_brand,
-	},
-	["tributebw"] = {
-		graphic = fbsd_brand,
-	},
-	["none"] = {
-		graphic = none,
-		shift = {x = 17, y = 0},
-	},
-}
-
-drawer.frame_styles = {
-	-- Indexed by valid values for loader_menu_frame in loader.conf(5).
-	-- All of the keys appearing below must be set for any menu frame style
-	-- added to drawer.frame_styles.
-	["ascii"] = {
-		horizontal	= "-",
-		vertical	= "|",
-		top_left	= "+",
-		bottom_left	= "+",
-		top_right	= "+",
-		bottom_right	= "+",
-	},
-	["single"] = {
-		horizontal	= "\xC4",
-		vertical	= "\xB3",
-		top_left	= "\xDA",
-		bottom_left	= "\xC0",
-		top_right	= "\xBF",
-		bottom_right	= "\xD9",
-	},
-	["double"] = {
-		horizontal	= "\xCD",
-		vertical	= "\xBA",
-		top_left	= "\xC9",
-		bottom_left	= "\xC8",
-		top_right	= "\xBB",
-		bottom_right	= "\xBC",
-	},
-}
-
-function drawer.drawscreen(menu_opts)
-	-- drawlogo() must go first.
-	-- it determines the positions of other elements
-	drawer.drawlogo()
-	drawer.drawbrand()
-	drawer.drawbox()
-	return drawer.drawmenu(menu_opts)
-end
-
-function drawer.drawmenu(menudef)
+local function drawmenu(menudef)
 	local x = drawer.menu_position.x
 	local y = drawer.menu_position.y
 
@@ -258,7 +134,7 @@ function drawer.drawmenu(menudef)
 	return alias_table
 end
 
-function drawer.drawbox()
+local function drawbox()
 	local x = drawer.menu_position.x - 3
 	local y = drawer.menu_position.y - 1
 	local w = drawer.frame_size.w
@@ -327,7 +203,7 @@ function drawer.drawbox()
 	printc(menu_header)
 end
 
-function drawer.drawbrand()
+local function drawbrand()
 	local x = tonumber(loader.getenv("loader_brand_x")) or
 	    drawer.brand_position.x
 	local y = tonumber(loader.getenv("loader_brand_y")) or
@@ -346,7 +222,7 @@ function drawer.drawbrand()
 	draw(x, y, graphic)
 end
 
-function drawer.drawlogo()
+local function drawlogo()
 	local x = tonumber(loader.getenv("loader_logo_x")) or
 	    drawer.logo_position.x
 	local y = tonumber(loader.getenv("loader_logo_y")) or
@@ -382,6 +258,130 @@ function drawer.drawlogo()
 	end
 
 	draw(x, y, logodef.graphic)
+end
+
+fbsd_brand = {
+"  ______               ____   _____ _____  ",
+" |  ____|             |  _ \\ / ____|  __ \\ ",
+" | |___ _ __ ___  ___ | |_) | (___ | |  | |",
+" |  ___| '__/ _ \\/ _ \\|  _ < \\___ \\| |  | |",
+" | |   | | |  __/  __/| |_) |____) | |__| |",
+" | |   | | |    |    ||     |      |      |",
+" |_|   |_|  \\___|\\___||____/|_____/|_____/ "
+}
+none = {""}
+
+-- Module exports
+drawer.default_brand = 'fbsd'
+
+drawer.menu_name_handlers = {
+	-- Menu name handlers should take the menu being drawn and entry being
+	-- drawn as parameters, and return the name of the item.
+	-- This is designed so that everything, including menu separators, may
+	-- have their names derived differently. The default action for entry
+	-- types not specified here is to use entry.name directly.
+	[core.MENU_SEPARATOR] = function(_, entry)
+		if entry.name ~= nil then
+			if type(entry.name) == "function" then
+				return entry.name()
+			end
+			return entry.name
+		end
+		return ""
+	end,
+	[core.MENU_CAROUSEL_ENTRY] = function(_, entry)
+		local carid = entry.carousel_id
+		local caridx = config.getCarouselIndex(carid)
+		local choices = entry.items
+		if type(choices) == "function" then
+			choices = choices()
+		end
+		if #choices < caridx then
+			caridx = 1
+		end
+		return entry.name(caridx, choices[caridx], choices)
+	end,
+}
+
+drawer.brand_position = {x = 2, y = 1}
+drawer.logo_position = {x = 46, y = 4}
+drawer.menu_position = {x = 5, y = 10}
+drawer.frame_size = {w = 42, h = 13}
+drawer.default_shift = {x = 0, y = 0}
+drawer.shift = drawer.default_shift
+
+drawer.branddefs = {
+	-- Indexed by valid values for loader_brand in loader.conf(5). Valid
+	-- keys are: graphic (table depicting graphic)
+	["fbsd"] = {
+		graphic = fbsd_brand,
+	},
+	["none"] = {
+		graphic = none,
+	},
+}
+
+function drawer.addBrand(name, def)
+	drawer.branddefs[name] = def
+end
+
+function drawer.addLogo(name, def)
+	drawer.logodefs[name] = def
+end
+
+drawer.logodefs = {
+	-- Indexed by valid values for loader_logo in loader.conf(5). Valid keys
+	-- are: requires_color (boolean), graphic (table depicting graphic), and
+	-- shift (table containing x and y).
+	["tribute"] = {
+		graphic = fbsd_brand,
+	},
+	["tributebw"] = {
+		graphic = fbsd_brand,
+	},
+	["none"] = {
+		graphic = none,
+		shift = {x = 17, y = 0},
+	},
+}
+
+drawer.frame_styles = {
+	-- Indexed by valid values for loader_menu_frame in loader.conf(5).
+	-- All of the keys appearing below must be set for any menu frame style
+	-- added to drawer.frame_styles.
+	["ascii"] = {
+		horizontal	= "-",
+		vertical	= "|",
+		top_left	= "+",
+		bottom_left	= "+",
+		top_right	= "+",
+		bottom_right	= "+",
+	},
+	["single"] = {
+		horizontal	= "\xC4",
+		vertical	= "\xB3",
+		top_left	= "\xDA",
+		bottom_left	= "\xC0",
+		top_right	= "\xBF",
+		bottom_right	= "\xD9",
+	},
+	["double"] = {
+		horizontal	= "\xCD",
+		vertical	= "\xBA",
+		top_left	= "\xC9",
+		bottom_left	= "\xC8",
+		top_right	= "\xBB",
+		bottom_right	= "\xBC",
+	},
+}
+
+function drawer.drawscreen(menudef)
+	-- drawlogo() must go first.
+	-- it determines the positions of other elements
+	drawlogo()
+	drawbrand()
+	drawbox()
+	return drawmenu(menudef)
 end
 
 return drawer


More information about the svn-src-all mailing list