Skip to content

Commit

Permalink
Add format option for net and temp widget (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
wahlencraft authored Mar 15, 2022
1 parent 4933d6c commit 6a06d3c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions widget/net.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local function factory(args)
local wifi_state = args.wifi_state or "off"
local eth_state = args.eth_state or "off"
local screen = args.screen or 1
local format = args.format or "%.1f"
local settings = args.settings or function() end

-- Compatibility with old API where iface was a string corresponding to 1 interface
Expand Down Expand Up @@ -63,8 +64,8 @@ local function factory(args)
net_now.sent = net_now.sent + dev_now.sent
net_now.received = net_now.received + dev_now.received

dev_now.sent = string.format("%.1f", dev_now.sent)
dev_now.received = string.format("%.1f", dev_now.received)
dev_now.sent = string.format(format, dev_now.sent)
dev_now.received = string.format(format, dev_now.received)

dev_now.last_t = now_t
dev_now.last_r = now_r
Expand Down Expand Up @@ -106,8 +107,8 @@ local function factory(args)
-- the totals across all specified devices
end

net_now.sent = string.format("%.1f", net_now.sent)
net_now.received = string.format("%.1f", net_now.received)
net_now.sent = string.format(format, net_now.sent)
net_now.received = string.format(format, net_now.received)

widget = net.widget
settings()
Expand Down
3 changes: 2 additions & 1 deletion widget/temp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local function factory(args)
local temp = { widget = args.widget or wibox.widget.textbox() }
local timeout = args.timeout or 30
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

function temp.update()
Expand All @@ -31,7 +32,7 @@ local function factory(args)
temp_now[t] = temp_value and temp_value/1e3 or temp_fl
end
end
coretemp_now = temp_now[tempfile] or "N/A"
coretemp_now = string.format(format, temp_now[tempfile]) or "N/A"
widget = temp.widget
settings()
end)
Expand Down

0 comments on commit 6a06d3c

Please sign in to comment.