mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
util pad function
This commit is contained in:
parent
3c2f631451
commit
7f011369c4
@ -45,11 +45,7 @@ local function state_indicator(args)
|
|||||||
args.width = string.len(state_def.text)
|
args.width = string.len(state_def.text)
|
||||||
end
|
end
|
||||||
|
|
||||||
local len = string.len(state_def.text)
|
local text = util.pad(state_def.text, args.width)
|
||||||
local lpad = math.floor((args.width - len) / 2)
|
|
||||||
local rpad = args.width - lpad
|
|
||||||
|
|
||||||
local text = util.spaces(lpad) .. state_def.text .. util.spaces(rpad)
|
|
||||||
|
|
||||||
table.insert(state_blit_cmds, {
|
table.insert(state_blit_cmds, {
|
||||||
text = text,
|
text = text,
|
||||||
|
@ -231,17 +231,14 @@ function log.dmesg_working(msg, tag, tag_color)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function done(ok)
|
local function done(ok)
|
||||||
local lpad = math.max(math.floor((width - 4) / 2), 0)
|
|
||||||
local rpad = (width - 4) - lpad
|
|
||||||
|
|
||||||
out.setCursorPos(ts_coord.x1, ts_coord.y)
|
out.setCursorPos(ts_coord.x1, ts_coord.y)
|
||||||
|
|
||||||
if ok or ok == nil then
|
if ok or ok == nil then
|
||||||
out.setTextColor(colors.green)
|
out.setTextColor(colors.green)
|
||||||
out.write(util.spaces(lpad) .. "DONE" .. util.spaces(rpad))
|
out.write(util.pad("DONE", width))
|
||||||
else
|
else
|
||||||
out.setTextColor(colors.red)
|
out.setTextColor(colors.red)
|
||||||
out.write(util.spaces(lpad) .. "FAIL" .. util.spaces(rpad))
|
out.write(util.pad("FAIL", width))
|
||||||
end
|
end
|
||||||
|
|
||||||
out.setTextColor(initial_color)
|
out.setTextColor(initial_color)
|
||||||
|
@ -75,6 +75,18 @@ function util.spaces(n)
|
|||||||
return util.strrep(" ", n)
|
return util.strrep(" ", n)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- pad text to a minimum width
|
||||||
|
---@param str string text
|
||||||
|
---@param n integer minimum width
|
||||||
|
---@return string
|
||||||
|
function util.pad(str, n)
|
||||||
|
local len = string.len(str)
|
||||||
|
local lpad = math.floor((n - len) / 2)
|
||||||
|
local rpad = (n - len) - lpad
|
||||||
|
|
||||||
|
return util.spaces(lpad) .. str .. util.spaces(rpad)
|
||||||
|
end
|
||||||
|
|
||||||
-- wrap a string into a table of lines, supporting single dash splits
|
-- wrap a string into a table of lines, supporting single dash splits
|
||||||
---@param str string
|
---@param str string
|
||||||
---@param limit integer line limit
|
---@param limit integer line limit
|
||||||
|
Loading…
Reference in New Issue
Block a user