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:
2025-12-18 17:14:36 +01:00
parent f4064e013c
commit b890a4efcd
5 changed files with 298 additions and 45 deletions

View File

@@ -32,6 +32,9 @@ local msg = require("mp.msg")
local utils = require("mp.utils")
local jit = rawget(_G, "jit") or {}
package.path = mp.command_native({ "expand-path", "~~/scripts/lib/?.lua;" }) .. package.path
local lib = require("utils")
local function coerce_boolean(value, default)
if type(value) == "boolean" then
return value
@@ -136,10 +139,6 @@ if unsupported_platform() then
return
end
local function trim(str)
return str and str:match("^%s*(.-)%s*$") or ""
end
local function build_brightnessctl_args(extra)
local args = { config.brightnessctl_path }
if config.led_path ~= nil and config.led_path ~= "" then
@@ -193,7 +192,7 @@ local function run_brightnessctl(extra, action)
end
if result.status ~= 0 then
local stderr_text = trim(result.stderr or "")
local stderr_text = lib.trim(result.stderr or "")
msg.error(("brightnessctl %s failed (exit %d): %s"):format(action, result.status, stderr_text))
log_permission_hint(stderr_text)
state.control_blocked = true
@@ -233,7 +232,7 @@ local function read_current_brightness()
return nil, err
end
local cleaned = trim(stdout)
local cleaned = lib.trim(stdout)
if cleaned == "" then
msg.error("brightnessctl returned empty output")
return nil, "empty output"