From e29ea6288a04100850efad7f1aa0cd747b82dc78 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Sat, 20 Feb 2010 03:24:42 +0100 Subject: helpers: uformat helper replaces formatting done by widgets --- dio.lua | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'dio.lua') 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 -- cgit v1.2.3