Add format option for net and temp widget (#523)

This commit is contained in:
Albin Wahlén 2022-03-15 17:17:01 +01:00 committed by GitHub
parent 4933d6cb27
commit 6a06d3cb79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -24,6 +24,7 @@ local function factory(args)
local wifi_state = args.wifi_state or "off" local wifi_state = args.wifi_state or "off"
local eth_state = args.eth_state or "off" local eth_state = args.eth_state or "off"
local screen = args.screen or 1 local screen = args.screen or 1
local format = args.format or "%.1f"
local settings = args.settings or function() end local settings = args.settings or function() end
-- Compatibility with old API where iface was a string corresponding to 1 interface -- Compatibility with old API where iface was a string corresponding to 1 interface
@ -63,8 +64,8 @@ local function factory(args)
net_now.sent = net_now.sent + dev_now.sent net_now.sent = net_now.sent + dev_now.sent
net_now.received = net_now.received + dev_now.received net_now.received = net_now.received + dev_now.received
dev_now.sent = string.format("%.1f", dev_now.sent) dev_now.sent = string.format(format, dev_now.sent)
dev_now.received = string.format("%.1f", dev_now.received) dev_now.received = string.format(format, dev_now.received)
dev_now.last_t = now_t dev_now.last_t = now_t
dev_now.last_r = now_r dev_now.last_r = now_r
@ -106,8 +107,8 @@ local function factory(args)
-- the totals across all specified devices -- the totals across all specified devices
end end
net_now.sent = string.format("%.1f", net_now.sent) net_now.sent = string.format(format, net_now.sent)
net_now.received = string.format("%.1f", net_now.received) net_now.received = string.format(format, net_now.received)
widget = net.widget widget = net.widget
settings() settings()

View File

@ -18,6 +18,7 @@ local function factory(args)
local temp = { widget = args.widget or wibox.widget.textbox() } local temp = { widget = args.widget or wibox.widget.textbox() }
local timeout = args.timeout or 30 local timeout = args.timeout or 30
local tempfile = args.tempfile or "/sys/devices/virtual/thermal/thermal_zone0/temp" local tempfile = args.tempfile or "/sys/devices/virtual/thermal/thermal_zone0/temp"
local format = args.format or "%.1f"
local settings = args.settings or function() end local settings = args.settings or function() end
function temp.update() function temp.update()
@ -31,7 +32,7 @@ local function factory(args)
temp_now[t] = temp_value and temp_value/1e3 or temp_fl temp_now[t] = temp_value and temp_value/1e3 or temp_fl
end end
end end
coretemp_now = temp_now[tempfile] or "N/A" coretemp_now = string.format(format, temp_now[tempfile]) or "N/A"
widget = temp.widget widget = temp.widget
settings() settings()
end) end)