aboutsummaryrefslogtreecommitdiff
path: root/dio.lua
diff options
context:
space:
mode:
Diffstat (limited to 'dio.lua')
-rw-r--r--dio.lua22
1 files changed, 6 insertions, 16 deletions
diff --git a/dio.lua b/dio.lua
index 57b786d..c7f6dce 100644
--- a/dio.lua
+++ b/dio.lua
@@ -7,11 +7,8 @@
local ipairs = ipairs
local setmetatable = setmetatable
local table = { insert = table.insert }
+local string = { gmatch = string.gmatch }
local helpers = require("vicious.helpers")
-local string = {
- gmatch = string.gmatch,
- format = string.format
-}
-- }}}
@@ -22,15 +19,8 @@ module("vicious.dio")
-- Initialise function tables
local disk_usage = {}
local disk_total = {}
-
--- {{{ Helper functions
-local function uformat(array, key, value)
- array["{"..key.."_s}"] = string.format("%.1f", value)
- array["{"..key.."_kb}"] = string.format("%.1f", value/2)
- array["{"..key.."_mb}"] = string.format("%.1f", value/2/1024)
- return array
-end
--- }}}
+-- Variable definitions
+local unit = { ["s"] = 1, ["kb"] = 2, ["mb"] = 2048 }
-- {{{ Disk I/O widget type
local function worker(format, disk)
@@ -64,9 +54,9 @@ local function worker(format, disk)
end
-- Calculate and store I/O
- uformat(disk_usage[disk], "read", diff_total[disk][3])
- uformat(disk_usage[disk], "write", diff_total[disk][7])
- uformat(disk_usage[disk], "total", diff_total[disk][7] + diff_total[disk][3])
+ helpers.uformat(disk_usage[disk], "read", diff_total[disk][3], unit)
+ helpers.uformat(disk_usage[disk], "write", diff_total[disk][7], unit)
+ helpers.uformat(disk_usage[disk], "total", diff_total[disk][7] + diff_total[disk][3], unit)
return disk_usage[disk]
end