#113 power formatting on turbine energy in main overview

This commit is contained in:
Mikayla Fischler
2022-11-02 14:47:18 -04:00
parent 54264f5149
commit c620310e51
6 changed files with 160 additions and 33 deletions

View File

@@ -4,29 +4,6 @@ local util = require("scada-common.util")
local element = require("graphics.element")
-- format a number string with commas as the thousands separator
--
-- subtracts from spaces at the start if present for each comma used
---@param num string number string
---@return string
local function comma_format(num)
local formatted = num
local commas = 0
local i = 1
while i > 0 do
formatted, i = formatted:gsub("^(%s-%d+)(%d%d%d)", '%1,%2')
if i > 0 then commas = commas + 1 end
end
local _, num_spaces = formatted:gsub(" %s-", "")
local remove = math.min(num_spaces, commas)
formatted = string.sub(formatted, remove + 1)
return formatted
end
---@class data_indicator_args
---@field label string indicator label
---@field unit? string indicator unit
@@ -78,7 +55,7 @@ local function data(args)
e.window.setCursorPos(data_start, 1)
e.window.setTextColor(e.fg_bg.fgd)
if args.commas then
e.window.write(comma_format(data_str))
e.window.write(util.comma_format(data_str))
else
e.window.write(data_str)
end