extensions from laptop
This commit is contained in:
@@ -11,6 +11,26 @@ local command = [[awk '
|
||||
local previous = {}
|
||||
local request_in_flight = false
|
||||
|
||||
local function colorForUsage(percent)
|
||||
if percent >= 85 then
|
||||
return "#ff453a" -- red
|
||||
end
|
||||
if percent >= 70 then
|
||||
return "#ff8800" -- orange
|
||||
end
|
||||
if percent >= 50 then
|
||||
return "#ffd60a" -- yellow
|
||||
end
|
||||
return "#ffffff" -- white
|
||||
end
|
||||
|
||||
local function renderStatus(text, color)
|
||||
barWidget.render(ui.row({ gap = 4, align = "center" }, {
|
||||
ui.glyph({ name = "cpu", size = 14, color = color }),
|
||||
ui.label({ text = text, color = color }),
|
||||
}))
|
||||
end
|
||||
|
||||
function update()
|
||||
noctalia.setUpdateInterval(2000)
|
||||
|
||||
@@ -23,7 +43,8 @@ function update()
|
||||
request_in_flight = false
|
||||
|
||||
if result.exitCode ~= 0 then
|
||||
barWidget.setText("CPU —")
|
||||
renderStatus("CPU —", "#fff1e6")
|
||||
barWidget.setTooltip("Unable to read CPU utilization")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -47,12 +68,19 @@ function update()
|
||||
previous[name] = { total = total, idle = idle }
|
||||
end
|
||||
|
||||
barWidget.setGlyph("cpu")
|
||||
if sampled > 0 then
|
||||
barWidget.setText(string.format("%.0f%%", utilization))
|
||||
barWidget.setTooltip("Aggregate CPU utilization (100% per logical CPU)")
|
||||
-- Keep the aggregate display, but base its heat color on average
|
||||
-- utilization per logical CPU so multicore systems do not stay red.
|
||||
local per_cpu_utilization = utilization / sampled
|
||||
renderStatus(string.format("%.0f%%", utilization), colorForUsage(per_cpu_utilization))
|
||||
barWidget.setTooltip(
|
||||
string.format(
|
||||
"Aggregate CPU utilization (100%% per logical CPU) · %.0f%% average per CPU",
|
||||
per_cpu_utilization
|
||||
)
|
||||
)
|
||||
else
|
||||
barWidget.setText("—")
|
||||
renderStatus("—", "#fff1e6")
|
||||
barWidget.setTooltip("Sampling CPU utilization…")
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -8,16 +8,37 @@ $1 == "SwapFree:" { swap_free = $2 }
|
||||
END {
|
||||
if (!total || !available) exit 1
|
||||
used = total - available
|
||||
memory_used = used * 100 / total
|
||||
if (swap_total > 0) {
|
||||
swap_used = (swap_total - swap_free) * 100 / swap_total
|
||||
printf "RAM %.1f/%.1f GiB S %.0f%%\n", used / 1048576, total / 1048576, swap_used
|
||||
printf "%.1f/%.1f GiB S %.0f%%\t%.0f\t%.0f\n", used / 1048576, total / 1048576, swap_used, memory_used, swap_used
|
||||
} else {
|
||||
printf "RAM %.1f/%.1f GiB S —\n", used / 1048576, total / 1048576
|
||||
printf "%.1f/%.1f GiB S —\t%.0f\t0\n", used / 1048576, total / 1048576, memory_used
|
||||
}
|
||||
}' /proc/meminfo]]
|
||||
|
||||
local request_in_flight = false
|
||||
|
||||
local function colorForUsage(percent)
|
||||
if percent >= 85 then
|
||||
return "#ff453a" -- red
|
||||
end
|
||||
if percent >= 70 then
|
||||
return "#ff8800" -- orange
|
||||
end
|
||||
if percent >= 50 then
|
||||
return "#ffd60a" -- yellow
|
||||
end
|
||||
return "#ffffff" -- white
|
||||
end
|
||||
|
||||
local function renderStatus(text, color)
|
||||
barWidget.render(ui.row({ gap = 4, align = "center" }, {
|
||||
ui.glyph({ name = "memory", size = 14, color = color }),
|
||||
ui.label({ text = text, color = color }),
|
||||
}))
|
||||
end
|
||||
|
||||
function update()
|
||||
noctalia.setUpdateInterval(5000)
|
||||
|
||||
@@ -30,14 +51,32 @@ function update()
|
||||
request_in_flight = false
|
||||
|
||||
if result.exitCode ~= 0 then
|
||||
barWidget.setText("RAM —")
|
||||
renderStatus("RAM —", "#fff1e6")
|
||||
barWidget.setTooltip("Unable to read /proc/meminfo")
|
||||
return
|
||||
end
|
||||
|
||||
local text = string.gsub(result.stdout, "%s+$", "")
|
||||
barWidget.setGlyph("memory")
|
||||
barWidget.setText(text)
|
||||
barWidget.setTooltip("RAM used / total · S = swap used")
|
||||
local text, memory_percent, swap_percent = string.match(
|
||||
result.stdout,
|
||||
"^([^\t]+)\t([%d.]+)\t([%d.]+)"
|
||||
)
|
||||
memory_percent = tonumber(memory_percent)
|
||||
swap_percent = tonumber(swap_percent)
|
||||
|
||||
if text == nil or memory_percent == nil or swap_percent == nil then
|
||||
renderStatus("RAM —", "#fff1e6")
|
||||
barWidget.setTooltip("Unable to parse memory utilization")
|
||||
return
|
||||
end
|
||||
|
||||
local highest_usage = math.max(memory_percent, swap_percent)
|
||||
renderStatus(text, colorForUsage(highest_usage))
|
||||
barWidget.setTooltip(
|
||||
string.format(
|
||||
"RAM used / total · %.0f%% RAM · %.0f%% swap",
|
||||
memory_percent,
|
||||
swap_percent
|
||||
)
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ name = "System Status"
|
||||
version = "1.0.0"
|
||||
plugin_api = 3
|
||||
author = "alex"
|
||||
description = "Low-overhead memory and swap indicator for the bar."
|
||||
description = "Low-overhead system and network status indicators for the bar."
|
||||
|
||||
[[widget]]
|
||||
id = "cpu"
|
||||
@@ -17,6 +17,10 @@ entry = "memory.luau"
|
||||
id = "battery-rate"
|
||||
entry = "battery-rate.luau"
|
||||
|
||||
[[widget]]
|
||||
id = "network-rate"
|
||||
entry = "network-rate.luau"
|
||||
|
||||
[[widget]]
|
||||
id = "gpu-mode"
|
||||
entry = "gpu-mode.luau"
|
||||
|
||||
Reference in New Issue
Block a user