aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README15
-rw-r--r--init.lua1
-rw-r--r--load.lua31
-rw-r--r--uptime.lua22
4 files changed, 18 insertions, 51 deletions
diff --git a/README b/README
index ec8d48f..1ebef10 100644
--- a/README
+++ b/README
@@ -152,16 +152,11 @@ vicious.widgets.thermal
- takes the thermal zone as an argument, i.e. "thermal_zone0"
- returns 1st value as temperature of requested thermal zone
-vicious.widgets.load
- - provides system load averages for the past 1, 5, and 15 minutes
- - returns 1st value as load average for past 1 minute, 2nd for 5
- minutes and 3rd for 15 minutes
-
vicious.widgets.uptime
- - provides system uptime information
- - returns 1st value as total uptime, 2nd as uptime in days, 3rd as
- uptime in hours, 4th as uptime in minutes and 5th as uptime in
- seconds
+ - provides system uptime and load information
+ - returns 1st value as uptime in days, 2nd as uptime in hours, 3rd
+ as uptime in minutes, 4th as load average for past 1 minute, 5th
+ for 5 minutes and 6th for 15 minutes
vicious.widgets.bat
- provides state, charge, and remaining time for a requested battery
@@ -375,7 +370,7 @@ Example
uptimewidget = widget({ type = 'textbox' })
vicious.register(uptimewidget, vicious.widgets.uptime,
function (widget, args)
- return string.format('Uptime: %2dd %02d:%02d ', args[2], args[3], args[4])
+ return string.format('Uptime: %2dd %02d:%02d ', args[1], args[2], args[3])
end, 61)
- uses string.format for padding uptime values to a minimum amount
diff --git a/init.lua b/init.lua
index eefae1f..020e7c0 100644
--- a/init.lua
+++ b/init.lua
@@ -25,7 +25,6 @@ require("vicious.cpu")
require("vicious.cpuinf")
require("vicious.cpufreq")
require("vicious.thermal")
-require("vicious.load")
require("vicious.uptime")
require("vicious.bat")
require("vicious.mem")
diff --git a/load.lua b/load.lua
deleted file mode 100644
index 7b5cb4d..0000000
--- a/load.lua
+++ /dev/null
@@ -1,31 +0,0 @@
----------------------------------------------------
--- Licensed under the GNU General Public License v2
--- * (c) 2009, Adrian C. <anrxc@sysphere.org>
----------------------------------------------------
-
--- {{{ Grab environment
-local tonumber = tonumber
-local io = { open = io.open }
-local setmetatable = setmetatable
-local string = { match = string.match }
--- }}}
-
-
--- Load: provides system load averages for the past 1, 5, and 15 minutes
-module("vicious.load")
-
-
--- {{{ Load widget type
-local function worker(format)
- local f = io.open('/proc/loadavg')
- local line = f:read("*line")
- f:close()
-
- local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes
- string.match(line, "([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)")
-
- return {tonumber(l1), tonumber(l5), tonumber(l15)}
-end
--- }}}
-
-setmetatable(_M, { __call = function(_, ...) return worker(...) end })
diff --git a/uptime.lua b/uptime.lua
index 1784985..c7082c1 100644
--- a/uptime.lua
+++ b/uptime.lua
@@ -5,31 +5,35 @@
---------------------------------------------------
-- {{{ Grab environment
-local io = { open = io.open }
local setmetatable = setmetatable
local math = { floor = math.floor }
local string = { match = string.match }
+local helpers = require("vicious.helpers")
-- }}}
--- Uptime: provides system uptime information
+-- Uptime: provides system uptime and load information
module("vicious.uptime")
-- {{{ Uptime widget type
local function worker(format)
- -- Get /proc/uptime
- local f = io.open("/proc/uptime")
- local line = f:read("*line")
- f:close()
+ local proc = setmetatable(
+ { _path = "/proc" },
+ helpers.pathtotable
+ )
- local up_t = math.floor(string.match(line, "[%d]+"))
+ -- Get system uptime
+ local up_t = math.floor(string.match(proc.uptime, "[%d]+"))
local up_d = math.floor(up_t / (3600 * 24))
local up_h = math.floor((up_t % (3600 * 24)) / 3600)
local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
- local up_s = math.floor(((up_t % (3600 * 24)) % 3600) % 60)
- return {up_t, up_d, up_h, up_m, up_s}
+ -- Get load averages
+ local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes
+ string.match(proc.loadavg, "([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)")
+
+ return {up_d, up_h, up_m, l1, l5, l15}
end
-- }}}