diff options
Diffstat (limited to 'net-speed-widget/net-speed.lua')
-rw-r--r-- | net-speed-widget/net-speed.lua | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/net-speed-widget/net-speed.lua b/net-speed-widget/net-speed.lua index d67d86a..dd724a3 100644 --- a/net-speed-widget/net-speed.lua +++ b/net-speed-widget/net-speed.lua @@ -17,25 +17,32 @@ local ICONS_DIR = WIDGET_DIR .. 'icons/' local net_speed_widget = {} -local function convert_to_h(bytes) +local function convert_to_h(bytes, bits_not_bytes) local speed local dim local bits = bytes * 8 - if bits < 1000 then - speed = bits - dim = 'B/s' - elseif bits < 1000000 then - speed = bits/1000 - dim = 'KB/s' - elseif bits < 1000000000 then - speed = bits/1000000 - dim = 'MB/s' - elseif bits < 1000000000000 then - speed = bits/1000000000 - dim = 'GB/s' + if bits_not_bytes then + units = bits + unitsuffix = 'bps' else - speed = tonumber(bits) - dim = 'b/s' + units = bytes + unitsuffix = 'Bps' + end + if units < 1000 then + speed = units + dim = unitsuffix + elseif units < 1000000 then + speed = units/1000 + dim = 'K' .. unitsuffix + elseif units < 1000000000 then + speed = units/1000000 + dim = 'M' .. unitsuffix + elseif units < 1000000000000 then + speed = units/1000000000 + dim = 'G' .. unitsuffix + else + speed = tonumber(units) + dim = unitsuffix end return math.floor(speed + 0.5) .. dim end @@ -59,6 +66,7 @@ local function worker(user_args) local interface = args.interface or '*' local timeout = args.timeout or 1 local width = args.width or 100 + local bits_not_bytes = args.bits_not_bytes net_speed_widget = wibox.widget { { @@ -108,8 +116,8 @@ local function worker(user_args) local speed_rx = (cur_rx - prev_rx) / timeout local speed_tx = (cur_tx - prev_tx) / timeout - widget:set_rx_text(convert_to_h(speed_rx)) - widget:set_tx_text(convert_to_h(speed_tx)) + widget:set_rx_text(convert_to_h(speed_rx), bits_not_bytes) + widget:set_tx_text(convert_to_h(speed_tx), bits_not_bytes) prev_rx = cur_rx prev_tx = cur_tx |