Changeset View
Changeset View
Standalone View
Standalone View
stand/lua/color.lua
| -- | -- | ||||
| -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD | -- SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
| -- | -- | ||||
| -- Copyright (c) 2023 The SmartixOS Project <ip@smartix.llc> | |||||
| -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> | -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> | ||||
| -- All rights reserved. | -- All rights reserved. | ||||
| -- | -- | ||||
| Context not available. | |||||
| color.disabled = not color.isEnabled() | color.disabled = not color.isEnabled() | ||||
| end | end | ||||
| -- The boot loader variable controlling the theme/color of the brand | |||||
| loader_brand_theme = "loader_brand_theme" | |||||
| -- The boot loader variable controlling the theme/color of the menu | |||||
| loader_menu_theme = "loader_menu_theme" | |||||
| -- The boot loader variable controlling the theme/color of the logo | |||||
| loader_logo_theme = "loader_logo_theme" | |||||
| -- Module exports | -- Module exports | ||||
| color.BLACK = 0 | color.BLACK = 0 | ||||
| color.RED = 1 | color.RED = 1 | ||||
| Context not available. | |||||
| color.BRIGHT = 1 | color.BRIGHT = 1 | ||||
| color.DIM = 2 | color.DIM = 2 | ||||
| --- Magic variables/values used to decide which part of the bootloader display to colorized | |||||
| -- These numbers are chosen at random. In fact they have a specific order still chosen at random. | |||||
| -- For the brand the digits go from 3 to 0 in descending order | |||||
| -- For the menu the digits go from 4 to 1 in descending order | |||||
| -- For the logo the digits go from 5 to 2 in descending order | |||||
| color.BRAND = 3210 | |||||
| color.MENU = 4321 | |||||
| color.LOGO = 5432 | |||||
| -- A table mapping color names to their numerical value | |||||
| --color.table["red"] = color.RED = 1 | |||||
| color.table = { | |||||
| -- no-color | |||||
| ["no-color"]= color.DEFAULT, | |||||
| -- color.RED = 1 | |||||
| ["red"]= color.RED, | |||||
| -- color.GREEN = 2 | |||||
| ["green"]= color.GREEN, | |||||
| -- color.YELLOW = 3 | |||||
| ["yellow"]= color.YELLOW, | |||||
| -- color.BLUE = 4 | |||||
| ["blue"]= color.BLUE, | |||||
| -- color.MAGENTA = 5 | |||||
| ["magenta"]= color.MAGENTA, | |||||
| -- color.CYAN = 6 | |||||
| ["cyan"]= color.CYAN, | |||||
| } --end colors.table | |||||
| function color.isEnabled() | function color.isEnabled() | ||||
| local c = loader.getenv("loader_color") | local loader_color = loader.getenv("loader_color") | ||||
| if c ~= nil then | if loader_color ~= nil then | ||||
| return c:lower() ~= "no" and c ~= "0" | return loader_color:lower() ~= "no" and loader_color ~= "0" | ||||
| end | end | ||||
| return true | return true | ||||
| end | end | ||||
| Context not available. | |||||
| return core.KEYSTR_CSI .. "1m" .. str .. core.KEYSTR_CSI .. "22m" | return core.KEYSTR_CSI .. "1m" .. str .. core.KEYSTR_CSI .. "22m" | ||||
| end | end | ||||
| recalcDisabled() | function recalcDisabled() | ||||
| hook.register("config.loaded", recalcDisabled) | hook.register("config.loaded", recalcDisabled) | ||||
| end | |||||
| -- The requested theme | |||||
| local request | |||||
| -- A function to return the requested theme for a specific section (portion or part) of the bootloader display | |||||
| -- The bootloader display is logically and physically divided in three sections; the brand which displays the vendor's | |||||
| -- trademarked name, the menu that shows a set of options to pick from, and the logo section which displays the vendor's | |||||
| -- trademarked logo. Each section can be stylized individually and this helper function is there to return the requested theme for | |||||
| -- a specific section of the display. It does this by searching for certain bootloader variables which normally contain color names example: "red" | |||||
| -- that are mapped to the correct numerical value using the color table (color.table) above. | |||||
| function color.getTheme(display_section) | |||||
| -- reset the request variable | |||||
| request = nil | |||||
| if display_section == color.BRAND then | |||||
| request = loader.getenv(loader_brand_theme) | |||||
| elseif display_section == color.MENU then | |||||
| request = loader.getenv(loader_menu_theme) | |||||
| elseif display_section == color.LOGO then | |||||
| request = loader.getenv(loader_logo_theme) | |||||
| end -- end if | |||||
| -- if things go bad, return the red theme as the default | |||||
| if request == nil then | |||||
| return color.table["red"] | |||||
| end | |||||
| return color.table[request] | |||||
| end | |||||
| return color | return color | ||||
| Context not available. | |||||