From 6a06d3cb7915589670b6cbaf538e5abec7e987bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albin=20Wahl=C3=A9n?= <63047114+wahlencraft@users.noreply.github.com> Date: Tue, 15 Mar 2022 17:17:01 +0100 Subject: [PATCH] Add format option for net and temp widget (#523) --- widget/net.lua | 9 +++++---- widget/temp.lua | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/widget/net.lua b/widget/net.lua index 49e60f4..9b7b165 100644 --- a/widget/net.lua +++ b/widget/net.lua @@ -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 @@ -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 @@ -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() diff --git a/widget/temp.lua b/widget/temp.lua index 05723f5..bafdcdc 100644 --- a/widget/temp.lua +++ b/widget/temp.lua @@ -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() @@ -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)