feat: add power gauge/delta/minmax to ac-power and extract shared utils
ac-power enhancements: - Add visual block gauge [████░░░░] colored by power level - Show delta indicator (+50W) colored by trend (green=dropping, red=rising) - Track min/max values with persistence to ~/.cache/mpv/ - Multi-process safe file writes (merges values on save) - New script-message: ac-power-reset-minmax Shared library (scripts/lib/utils.lua): - Extract common helpers: trim, clamp, rgb_to_bgr, colorize - Update all scripts to use shared module via package.path
This commit is contained in:
44
scripts/lib/utils.lua
Normal file
44
scripts/lib/utils.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
--[[
|
||||
Shared utility functions for mpv scripts.
|
||||
]]
|
||||
|
||||
local M = {}
|
||||
|
||||
-- String utilities
|
||||
function M.trim(str)
|
||||
return str and str:match("^%s*(.-)%s*$") or ""
|
||||
end
|
||||
|
||||
-- Math utilities
|
||||
function M.clamp(value, min_v, max_v)
|
||||
if value < min_v then
|
||||
return min_v
|
||||
end
|
||||
if value > max_v then
|
||||
return max_v
|
||||
end
|
||||
return value
|
||||
end
|
||||
|
||||
-- ASS color utilities
|
||||
function M.rgb_to_bgr(rgb)
|
||||
return rgb:sub(5, 6) .. rgb:sub(3, 4) .. rgb:sub(1, 2)
|
||||
end
|
||||
|
||||
function M.colorize(text, color_rgb, use_colors)
|
||||
if use_colors == false then
|
||||
return text
|
||||
end
|
||||
return "{\\1c&H" .. M.rgb_to_bgr(color_rgb) .. "&}" .. text .. "{\\1c&HFFFFFF&}"
|
||||
end
|
||||
|
||||
-- Debug logging factory
|
||||
function M.make_dbg(prefix, log_fn)
|
||||
return function(text, config_enabled)
|
||||
if config_enabled ~= false then
|
||||
log_fn(prefix .. ": " .. text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user