Conflicts:
	init.lua
	widgets/dio.lua
This commit is contained in:
Jörg Thalheim 2012-06-19 21:53:39 +02:00
commit fd9814112a
42 changed files with 213 additions and 164 deletions

3
README
View File

@ -35,7 +35,7 @@ your memory.
Then add the following to the top of your rc.lua:
require("vicious")
local vicious = require("vicious")
Once you create a widget (a textbox, graph or a progressbar) call
vicious.register() to register it with Vicious:
@ -559,3 +559,4 @@ Vicious contributors:
- Hiltjo Posthuma <hiltjo codemadness.org>
- Hagen Schink <troja84 googlemail.com>
- Jörg Thalheim <jthalheim gmail.com>
- Arvydas Sidorenko <asido4 gmail.com>

View File

@ -36,7 +36,7 @@ your memory.
Then add the following to the top of your rc.lua:
```Lua
require("vicious")
local vicious = require("vicious")
```
Once you create a widget (a textbox, graph or a progressbar) call
@ -607,4 +607,5 @@ Vicious contributors:
- Hiltjo Posthuma <hiltjo codemadness.org>
- Hagen Schink <troja84 googlemail.com>
- Jörg Thalheim <jthalheim gmail.com>
- Arvydas Sidorenko <asido4 gmail.com>

View File

@ -13,7 +13,8 @@ local string = { match = string.match }
-- Batacpi: provides state, charge, and remaining time for all batteries using acpitool
module("vicious.contrib.batacpi")
-- vicious.contrib.batacpi
local batacpi = {}
-- {{{ Battery widget type
@ -48,4 +49,4 @@ local function worker(format)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(batacpi, { __call = function(_, ...) return worker(...) end })

View File

@ -20,7 +20,8 @@ local string = {
-- Batpmu: provides state, charge and remaining time for a requested battery using PMU
module("vicious.contrib.batpmu")
-- vicious.contrib.batpmu
local batpmu = {}
-- {{{ Battery widget type
@ -75,4 +76,4 @@ local function worker(format, batid)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(batpmu, { __call = function(_, ...) return worker(...) end })

View File

@ -20,7 +20,8 @@ local string = {
-- Batproc: provides state, charge, and remaining time for a requested battery using procfs
module("vicious.contrib.batproc")
-- vicious.contrib.batproc
local batproc = {}
-- {{{ Battery widget type
@ -82,4 +83,4 @@ local function worker(format, batid)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(batproc, { __call = function(_, ...) return worker(...) end })

View File

@ -13,7 +13,8 @@ local helpers = require("vicious.helpers")
-- Disk I/O: provides I/O statistics for requested storage devices
module("vicious.contrib.dio")
-- vicious.contrib.dio
local dio = {}
-- Initialize function tables
@ -69,4 +70,4 @@ local function worker(format, disk)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(dio, { __call = function(_, ...) return worker(...) end })

View File

@ -10,8 +10,9 @@ local setmetatable = setmetatable
local wrequire = require("vicious.helpers").wrequire
-- Vicious: widgets for the awesome window manager
module("vicious.contrib")
-- vicious.contrib
local contrib = {}
-- }}}
-- Load modules at runtime as needed
setmetatable(_M, { __index = wrequire })
return setmetatable(contrib, { __index = wrequire })

View File

@ -14,7 +14,8 @@ local helpers = require("vicious.helpers")
-- Mpc: provides the currently playing song in MPD
module("vicious.contrib.mpc")
-- vicious.contrib.mpc
local mpc = {}
-- {{{ MPC widget type
@ -44,4 +45,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(mpc, { __call = function(_, ...) return worker(...) end })

View File

@ -17,7 +17,8 @@ local helpers = require("vicious.helpers")
-- Net: provides usage statistics for all network interfaces
module("vicious.contrib.net")
-- vicious.contrib.net
local net = {}
-- Initialise function tables
@ -135,4 +136,4 @@ local function worker(format, tignorelist)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(net, { __call = function(_, ...) return worker(...) end })

View File

@ -11,7 +11,8 @@ local table = { insert = table.insert }
-- Netcfg: provides active netcfg network profiles
module("vicious.contrib.netcfg")
-- vicious.contrib.netcfg
local netcfg = {}
-- {{{ Netcfg widget type
@ -31,4 +32,4 @@ local function worker(format)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(netcfg, { __call = function(_, ...) return worker(...) end })

View File

@ -12,7 +12,8 @@ local string = { match = string.match }
-- Ossvol: provides volume levels of requested OSS mixers
module("vicious.contrib.ossvol")
-- vicious.contrib.ossvol
local ossvol = {}
-- {{{ Volume widget type
@ -50,4 +51,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(ossvol, { __call = function(_, ...) return worker(...) end })

View File

@ -19,7 +19,8 @@ end)
-- POP: provides the count of new messages in a POP3 mailbox
module("vicious.contrib.pop")
-- vicious.contrib.pop
local pop = {}
-- {{{ POP3 count widget type
@ -51,4 +52,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(pop, { __call = function(_, ...) return worker(...) end })

View File

@ -24,7 +24,8 @@ local math = {
-- Pulse: provides volume levels of requested pulseaudio sinks and methods to change them
module("vicious.contrib.pulse")
-- vicious.contrib.pulse
local pulse = {}
-- {{{ Helper function
local function pacmd(args)
@ -79,7 +80,7 @@ end
-- }}}
-- {{{ Volume control helper
function add(percent, sink)
function pulse.add(percent, sink)
sink = get_sink_name(sink)
if sink == nil then return end
@ -96,7 +97,7 @@ function add(percent, sink)
return os.execute(cmd)
end
function toggle(sink)
function pulse.toggle(sink)
sink = get_sink_name(sink)
if sink == nil then return end
@ -111,4 +112,4 @@ function toggle(sink)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(pulse, { __call = function(_, ...) return worker(...) end })

View File

@ -14,7 +14,8 @@ local setmetatable = setmetatable
-- RSS: provides latest world news
module("vicious.contrib.rss")
-- vicious.contrib.rss
local rss = {}
-- {{{ RSS widget type
@ -64,4 +65,4 @@ local function worker(format, input)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(rss, { __call = function(_, ...) return worker(...) end })

View File

@ -16,7 +16,8 @@ local string = {
-- Sensors: provides access to lm_sensors data
module("vicious.contrib.sensors")
-- vicious.contrib.sensors
local sensors = {}
-- {{{ Split helper function
@ -65,4 +66,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(sensors, { __call = function(_, ...) return worker(...) end })

View File

@ -23,7 +23,8 @@ local string = {
-- Helpers: provides helper functions for vicious widgets
module("vicious.helpers")
-- vicious.helpers
local helpers = {}
-- {{{ Variable definitions
@ -32,14 +33,14 @@ local scroller = {}
-- {{{ Helper functions
-- {{{ Loader of vicious modules
function wrequire(table, key)
function helpers.wrequire(table, key)
local module = rawget(table, key)
return module or require(table._NAME .. "." .. key)
end
-- }}}
-- {{{ Expose path as a Lua table
function pathtotable(dir)
function helpers.pathtotable(dir)
return setmetatable({ _path = dir },
{ __index = function(table, index)
local path = table._path .. '/' .. index
@ -61,7 +62,7 @@ end
-- }}}
-- {{{ Format a string with args
function format(format, args)
function helpers.format(format, args)
for var, val in pairs(args) do
format = format:gsub("$" .. (tonumber(var) and var or
var:gsub("[-+?*]", function(i) return "%"..i end)),
@ -73,7 +74,7 @@ end
-- }}}
-- {{{ Format units to one decimal point
function uformat(array, key, value, unit)
function helpers.uformat(array, key, value, unit)
for u, v in pairs(unit) do
array["{"..key.."_"..u.."}"] = string.format("%.1f", value/v)
end
@ -83,7 +84,7 @@ end
-- }}}
-- {{{ Escape a string
function escape(text)
function helpers.escape(text)
local xml_entities = {
["\""] = "&quot;",
["&"] = "&amp;",
@ -97,7 +98,7 @@ end
-- }}}
-- {{{ Capitalize a string
function capitalize(text)
function helpers.capitalize(text)
return text and text:gsub("([%w])([%w]*)", function(c, s)
return string.upper(c) .. s
end)
@ -105,7 +106,7 @@ end
-- }}}
-- {{{ Truncate a string
function truncate(text, maxlen)
function helpers.truncate(text, maxlen)
local txtlen = text:len()
if txtlen > maxlen then
@ -117,7 +118,7 @@ end
-- }}}
-- {{{ Scroll through a string
function scroll(text, maxlen, widget)
function helpers.scroll(text, maxlen, widget)
if not scroller[widget] then
scroller[widget] = { i = 1, d = true }
end
@ -146,4 +147,7 @@ function scroll(text, maxlen, widget)
return text
end
-- }}}
return helpers
-- }}}

View File

@ -17,13 +17,11 @@ local table = {
remove = table.remove
}
require("vicious.helpers")
require("vicious.widgets")
require("vicious.contrib")
local helpers = require("vicious.helpers")
-- Vicious: widgets for the awesome window manager
module("vicious")
local vicious = {}
vicious.widgets = require("vicious.widgets")
-- Initialize tables
local timers = {}
@ -141,7 +139,7 @@ end
-- {{{ Global functions
-- {{{ Register a widget
function register(widget, wtype, format, timer, warg)
function vicious.register(widget, wtype, format, timer, warg)
local widget = widget
local reg = {
-- Set properties
@ -171,12 +169,12 @@ end
-- }}}
-- {{{ Unregister a widget
function unregister(widget, keep, reg)
function vicious.unregister(widget, keep, reg)
if reg == nil then
for w, i in pairs(registered) do
if w == widget then
for _, v in pairs(i) do
reg = unregister(w, keep, v)
reg = vicious.unregister(w, keep, v)
end
end
end
@ -207,7 +205,7 @@ end
-- }}}
-- {{{ Enable caching of a widget type
function cache(wtype)
function vicious.cache(wtype)
if wtype ~= nil then
if widget_cache[wtype] == nil then
widget_cache[wtype] = {}
@ -217,7 +215,7 @@ end
-- }}}
-- {{{ Force update of widgets
function force(wtable)
function vicious.force(wtable)
if type(wtable) == "table" then
for _, w in pairs(wtable) do
update(w, nil, true)
@ -227,17 +225,17 @@ end
-- }}}
-- {{{ Suspend all widgets
function suspend()
function vicious.suspend()
for w, i in pairs(registered) do
for _, v in pairs(i) do
unregister(w, true, v)
vicious.unregister(w, true, v)
end
end
end
-- }}}
-- {{{ Activate a widget
function activate(widget)
function vicious.activate(widget)
for w, i in pairs(registered) do
if widget == nil or w == widget then
for _, v in pairs(i) do
@ -247,4 +245,7 @@ function activate(widget)
end
end
-- }}}
return vicious
-- }}}

View File

@ -16,7 +16,8 @@ local math = {
-- Bat: provides state, charge, and remaining time for a requested battery
module("vicious.widgets.bat")
-- vicious.widgets.bat
local bat = {}
-- {{{ Battery widget type
@ -86,4 +87,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(bat, { __call = function(_, ...) return worker(...) end })

View File

@ -7,7 +7,7 @@
-- {{{ Grab environment
local ipairs = ipairs
local io = { lines = io.lines }
local io = { open = io.open }
local setmetatable = setmetatable
local math = { floor = math.floor }
local table = { insert = table.insert }
@ -19,7 +19,8 @@ local string = {
-- Cpu: provides CPU usage for all available CPUs/cores
module("vicious.widgets.cpu")
-- vicious.widgets.cpu
local cpu = {}
-- Initialize function tables
@ -32,7 +33,8 @@ local function worker(format)
local cpu_lines = {}
-- Get CPU stats
for line in io.lines("/proc/stat") do
local f = io.open("/proc/stat")
for line in f:lines() do
if string.sub(line, 1, 3) ~= "cpu" then break end
cpu_lines[#cpu_lines+1] = {}
@ -41,6 +43,7 @@ local function worker(format)
table.insert(cpu_lines[#cpu_lines], i)
end
end
f:close()
-- Ensure tables are initialized correctly
for i = #cpu_total + 1, #cpu_lines do
@ -74,4 +77,4 @@ local function worker(format)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(cpu, { __call = function(_, ...) return worker(...) end })

View File

@ -12,14 +12,15 @@ local helpers = require("vicious.helpers")
-- Cpufreq: provides freq, voltage and governor info for a requested CPU
module("vicious.widgets.cpufreq")
-- vicious.widgets.cpufreq
local cpufreq = {}
-- {{{ CPU frequency widget type
local function worker(format, warg)
if not warg then return end
local cpufreq = helpers.pathtotable("/sys/devices/system/cpu/"..warg.."/cpufreq")
local _cpufreq = helpers.pathtotable("/sys/devices/system/cpu/"..warg.."/cpufreq")
local governor_state = {
["ondemand\n"] = "",
["powersave\n"] = "",
@ -34,22 +35,22 @@ local function worker(format, warg)
}
-- Get the current frequency
local freq = tonumber(cpufreq.scaling_cur_freq)
local freq = tonumber(_cpufreq.scaling_cur_freq)
-- Calculate MHz and GHz
if freq then
freqv.mhz = freq / 1000
freqv.ghz = freqv.mhz / 1000
-- Get the current voltage
if cpufreq.scaling_voltages then
freqv.mv = tonumber(string.match(cpufreq.scaling_voltages, freq.."[%s]([%d]+)"))
if _cpufreq.scaling_voltages then
freqv.mv = tonumber(string.match(_cpufreq.scaling_voltages, freq.."[%s]([%d]+)"))
-- Calculate voltage from mV
freqv.v = freqv.mv / 1000
end
end
-- Get the current governor
local governor = cpufreq.scaling_governor
local governor = _cpufreq.scaling_governor
-- Represent the governor as a symbol
governor = governor_state[governor] or governor or "N/A"
@ -57,4 +58,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(cpufreq, { __call = function(_, ...) return worker(...) end })

View File

@ -12,7 +12,8 @@ local string = { gmatch = string.gmatch }
-- Cpuinf: provides speed and cache information for all available CPUs/cores
module("vicious.widgets.cpuinf")
-- vicious.widgets.cpuinf
local cpuinf = {}
-- {{{ CPU Information widget type
@ -40,4 +41,4 @@ local function worker(format)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(cpuinf, { __call = function(_, ...) return worker(...) end })

View File

@ -14,7 +14,8 @@ local os = {
-- Date: provides access to os.date with optional time formatting
module("vicious.widgets.date")
-- vicious.widgets.date
local date = {}
-- {{{ Date widget type
@ -23,4 +24,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(date, { __call = function(_, ...) return worker(...) end })

View File

@ -16,8 +16,9 @@ local os = {
-- }}}
-- Disk I/O: provides I/O statistics for storage devices/partitions (only linux >= 2.6 )
module("vicious.widgets.dio")
-- Disk I/O: provides I/O statistics for requested storage devices
-- vicious.widgets.dio
local dio = {}
-- Initialize function tables
@ -69,4 +70,4 @@ local function worker(format)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(dio, { __call = function(_, ...) return worker(...) end })

View File

@ -14,7 +14,8 @@ local helpers = require("vicious.helpers")
-- FS: provides file system disk space usage
module("vicious.widgets.fs")
-- vicious.widgets.fs
local fs = {}
-- Variable definitions
@ -48,4 +49,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(fs, { __call = function(_, ...) return worker(...) end })

View File

@ -17,7 +17,8 @@ local string = {
-- Gmail: provides count of new and subject of last e-mail on Gmail
module("vicious.widgets.gmail")
-- vicious.widgets.gmail
local gmail = {}
-- {{{ Variable definitions
@ -79,4 +80,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(gmail, { __call = function(_, ...) return worker(...) end })

View File

@ -12,7 +12,8 @@ local string = { gmatch = string.gmatch }
-- Hddtemp: provides hard drive temperatures using the hddtemp daemon
module("vicious.widgets.hddtemp")
-- vicious.widgets.hddtemp
local hddtemp = {}
-- {{{ HDD Temperature widget type
@ -34,4 +35,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(hddtemp, { __call = function(_, ...) return worker(...) end })

View File

@ -10,8 +10,9 @@ local setmetatable = setmetatable
local wrequire = require("vicious.helpers").wrequire
-- Vicious: widgets for the awesome window manager
module("vicious.widgets")
-- vicious.widgets
local widgets = { _NAME = "vicious.widgets" }
-- }}}
-- Load modules at runtime as needed
setmetatable(_M, { __index = wrequire })
return setmetatable(widgets, { __index = wrequire })

View File

@ -13,7 +13,8 @@ local helpers = require("vicious.helpers")
-- Mbox: provides the subject of last e-mail in a mbox file
module("vicious.widgets.mbox")
-- vicious.widgets.mbox
local mbox = {}
-- Initialize variables
@ -24,9 +25,9 @@ local function worker(format, warg)
if not warg then return end
-- mbox could be huge, get a 30kb chunk from EOF
if type(warg) ~= "table" then mbox = warg end
if type(warg) ~= "table" then _mbox = warg end
-- * attachment could be much bigger than 30kb
local f = io.open(mbox or warg[1])
local f = io.open(_mbox or warg[1])
f:seek("end", -30720)
local txt = f:read("*all")
f:close()
@ -49,4 +50,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(mbox, { __call = function(_, ...) return worker(...) end })

View File

@ -11,7 +11,8 @@ local string = { find = string.find }
-- Mboxc: provides the count of total, old and new messages in mbox files
module("vicious.widgets.mboxc")
-- vicious.widgets.mboxc
local mboxc = {}
-- {{{ Mbox count widget type
@ -54,4 +55,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(mbox, { __call = function(_, ...) return worker(...) end })

View File

@ -11,7 +11,8 @@ local setmetatable = setmetatable
-- Mdir: provides the number of new and unread messages in Maildir structures/dirs
module("vicious.widgets.mdir")
-- vicious.widgets.mdir
local mdir = {}
-- {{{ Maildir widget type
@ -37,4 +38,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(mdir, { __call = function(_, ...) return worker(...) end })

View File

@ -13,39 +13,40 @@ local string = { gmatch = string.gmatch }
-- Mem: provides RAM and Swap usage statistics
module("vicious.widgets.mem")
-- vicious.widgets.mem
local mem = {}
-- {{{ Memory widget type
local function worker(format)
local mem = { buf = {}, swp = {} }
local _mem = { buf = {}, swp = {} }
-- Get MEM info
for line in io.lines("/proc/meminfo") do
for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+") do
if k == "MemTotal" then mem.total = math.floor(v/1024)
elseif k == "MemFree" then mem.buf.f = math.floor(v/1024)
elseif k == "Buffers" then mem.buf.b = math.floor(v/1024)
elseif k == "Cached" then mem.buf.c = math.floor(v/1024)
elseif k == "SwapTotal" then mem.swp.t = math.floor(v/1024)
elseif k == "SwapFree" then mem.swp.f = math.floor(v/1024)
if k == "MemTotal" then _mem.total = math.floor(v/1024)
elseif k == "MemFree" then _mem.buf.f = math.floor(v/1024)
elseif k == "Buffers" then _mem.buf.b = math.floor(v/1024)
elseif k == "Cached" then _mem.buf.c = math.floor(v/1024)
elseif k == "SwapTotal" then _mem.swp.t = math.floor(v/1024)
elseif k == "SwapFree" then _mem.swp.f = math.floor(v/1024)
end
end
end
-- Calculate memory percentage
mem.free = mem.buf.f + mem.buf.b + mem.buf.c
mem.inuse = mem.total - mem.free
mem.bcuse = mem.total - mem.buf.f
mem.usep = math.floor(mem.inuse / mem.total * 100)
_mem.free = _mem.buf.f + _mem.buf.b + _mem.buf.c
_mem.inuse = _mem.total - _mem.free
_mem.bcuse = _mem.total - _mem.buf.f
_mem.usep = math.floor(_mem.inuse / _mem.total * 100)
-- Calculate swap percentage
mem.swp.inuse = mem.swp.t - mem.swp.f
mem.swp.usep = math.floor(mem.swp.inuse / mem.swp.t * 100)
_mem.swp.inuse = _mem.swp.t - _mem.swp.f
_mem.swp.usep = math.floor(_mem.swp.inuse / _mem.swp.t * 100)
return {mem.usep, mem.inuse, mem.total, mem.free,
mem.swp.usep, mem.swp.inuse, mem.swp.t, mem.swp.f,
mem.bcuse }
return {_mem.usep, _mem.inuse, _mem.total, _mem.free,
_mem.swp.usep, _mem.swp.inuse, _mem.swp.t, _mem.swp.f,
_mem.bcuse }
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(mem, { __call = function(_, ...) return worker(...) end })

View File

@ -13,7 +13,8 @@ local helpers = require("vicious.helpers")
-- Mpd: provides Music Player Daemon information
module("vicious.widgets.mpd")
-- vicious.widgets.mpd
local mpd = {}
-- {{{ MPD widget type
@ -60,4 +61,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })

View File

@ -15,7 +15,8 @@ local helpers = require("vicious.helpers")
-- Net: provides state and usage statistics of all network interfaces
module("vicious.widgets.net")
-- vicious.widgets.net
local net = {}
-- Initialize function tables
@ -76,4 +77,4 @@ local function worker(format)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(net, { __call = function(_, ...) return worker(...) end })

View File

@ -16,7 +16,8 @@ local os = {
-- Org: provides agenda statistics for Emacs org-mode
module("vicious.widgets.org")
-- vicious.widgets.org
local org = {}
-- {{{ OrgMode widget type
@ -58,4 +59,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(org, { __call = function(_, ...) return worker(...) end })

View File

@ -19,7 +19,8 @@ local string = {
-- OS: provides operating system information
module("vicious.widgets.os")
-- vicious.widgets.os
local os = {}
-- {{{ Operating system widget type
@ -69,4 +70,4 @@ local function worker(format)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(os, { __call = function(_, ...) return worker(...) end })

View File

@ -11,7 +11,8 @@ local setmetatable = setmetatable
-- Pkg: provides number of pending updates on UNIX systems
module("vicious.widgets.pkg")
-- vicious.widgets.pkg
local pkg = {}
-- {{{ Packages widget type
@ -31,16 +32,16 @@ local function worker(format, warg)
}
-- Check if updates are available
local pkg = manager[warg]
local f = io.popen(pkg.cmd)
local _pkg = manager[warg]
local f = io.popen(_pkg.cmd)
for line in f:lines() do
updates = updates + 1
end
f:close()
return {pkg.sub and math.max(updates-pkg.sub, 0) or updates}
return {_pkg.sub and math.max(updates-_pkg.sub, 0) or updates}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(pkg, { __call = function(_, ...) return worker(...) end })

View File

@ -4,7 +4,7 @@
-----------------------------------------------------
-- {{{ Grab environment
local io = { lines = io.lines }
local io = { open = io.open }
local setmetatable = setmetatable
local string = {
len = string.len,
@ -16,7 +16,8 @@ local string = {
-- Raid: provides state information for a requested RAID array
module("vicious.widgets.raid")
-- vicious.widgets.raid
local raid = {}
-- Initialize function tables
@ -32,7 +33,8 @@ local function worker(format, warg)
}
-- Linux manual page: md(4)
for line in io.lines("/proc/mdstat") do
local f = io.open("/proc/mdstat")
for line in f:lines() do
if mddev[warg]["found"] then
local updev = string.match(line, "%[[_U]+%]")
@ -49,9 +51,10 @@ local function worker(format, warg)
end
end
end
f:close()
return {mddev[warg]["assigned"], mddev[warg]["active"]}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(raid, { __call = function(_, ...) return worker(...) end })

View File

@ -13,7 +13,8 @@ local helpers = require("vicious.helpers")
-- Thermal: provides temperature levels of ACPI and coretemp thermal zones
module("vicious.widgets.thermal")
-- vicious.widgets.thermal
local thermal = {}
-- {{{ Thermal widget type
@ -28,9 +29,9 @@ local function worker(format, warg)
warg = type(warg) == "table" and warg or { warg, "sys" }
-- Get temperature from thermal zone
local thermal = helpers.pathtotable(zone[warg[2]][1] .. warg[1])
local _thermal = helpers.pathtotable(zone[warg[2]][1] .. warg[1])
local data = warg[3] and thermal[warg[3]] or thermal[zone[warg[2]].file]
local data = warg[3] and _thermal[warg[3]] or _thermal[zone[warg[2]].file]
if data then
if zone[warg[2]].div then
return {data / zone[warg[2]].div}
@ -43,4 +44,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(thermal, { __call = function(_, ...) return worker(...) end })

View File

@ -13,7 +13,8 @@ local helpers = require("vicious.helpers")
-- Uptime: provides system uptime and load information
module("vicious.widgets.uptime")
-- vicious.widgets.uptime
local uptime = {}
-- {{{ Uptime widget type
@ -32,4 +33,4 @@ local function worker(format)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
local setmetatable(uptime, { __call = function(_, ...) return worker(...) end })

View File

@ -12,7 +12,8 @@ local string = { match = string.match }
-- Volume: provides volume levels and state of requested ALSA mixers
module("vicious.widgets.volume")
-- vicious.widgets.volume
local volume = {}
-- {{{ Volume widget type
@ -49,4 +50,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(volume, { __call = function(_, ...) return worker(...) end })

View File

@ -14,11 +14,12 @@ local helpers = require("vicious.helpers")
-- Weather: provides weather information for a requested station
module("vicious.widgets.weather")
-- vicious.widgets.weather
local weather = {}
-- Initialize function tables
local weather = {
local _weather = {
["{city}"] = "N/A",
["{wind}"] = "N/A",
["{windmph}"] = "N/A",
@ -43,43 +44,43 @@ local function worker(format, warg)
f:close()
-- Check if there was a timeout or a problem with the station
if ws == nil then return weather end
if ws == nil then return _weather end
weather["{city}"] = -- City and/or area
string.match(ws, "^(.+)%,.*%([%u]+%)") or weather["{city}"]
weather["{wind}"] = -- Wind direction and degrees if available
string.match(ws, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or weather["{wind}"]
weather["{windmph}"] = -- Wind speed in MPH if available
string.match(ws, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or weather["{windmph}"]
weather["{sky}"] = -- Sky conditions if available
string.match(ws, "Sky[%s]conditions:[%s](.-)[%c]") or weather["{sky}"]
weather["{weather}"] = -- Weather conditions if available
string.match(ws, "Weather:[%s](.-)[%c]") or weather["{weather}"]
weather["{tempf}"] = -- Temperature in fahrenheit
string.match(ws, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or weather["{tempf}"]
weather["{humid}"] = -- Relative humidity in percent
string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or weather["{humid}"]
weather["{press}"] = -- Pressure in hPa
string.match(ws, "Pressure[%s].+%((.+)[%s]hPa%)") or weather["{press}"]
_weather["{city}"] = -- City and/or area
string.match(ws, "^(.+)%,.*%([%u]+%)") or _weather["{city}"]
_weather["{wind}"] = -- Wind direction and degrees if available
string.match(ws, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or _weather["{wind}"]
_weather["{windmph}"] = -- Wind speed in MPH if available
string.match(ws, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or _weather["{windmph}"]
_weather["{sky}"] = -- Sky conditions if available
string.match(ws, "Sky[%s]conditions:[%s](.-)[%c]") or _weather["{sky}"]
_weather["{weather}"] = -- Weather conditions if available
string.match(ws, "Weather:[%s](.-)[%c]") or _weather["{weather}"]
_weather["{tempf}"] = -- Temperature in fahrenheit
string.match(ws, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{tempf}"]
_weather["{humid}"] = -- Relative humidity in percent
string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or _weather["{humid}"]
_weather["{press}"] = -- Pressure in hPa
string.match(ws, "Pressure[%s].+%((.+)[%s]hPa%)") or _weather["{press}"]
-- Wind speed in km/h if MPH was available
if weather["{windmph}"] ~= "N/A" then
weather["{windmph}"] = tonumber(weather["{windmph}"])
weather["{windkmh}"] = math.ceil(weather["{windmph}"] * 1.6)
if _weather["{windmph}"] ~= "N/A" then
_weather["{windmph}"] = tonumber(_weather["{windmph}"])
_weather["{windkmh}"] = math.ceil(_weather["{windmph}"] * 1.6)
end -- Temperature in °C if °F was available
if weather["{tempf}"] ~= "N/A" then
weather["{tempf}"] = tonumber(weather["{tempf}"])
weather["{tempc}"] = math.ceil((weather["{tempf}"] - 32) * 5/9)
if _weather["{tempf}"] ~= "N/A" then
_weather["{tempf}"] = tonumber(_weather["{tempf}"])
_weather["{tempc}"] = math.ceil((_weather["{tempf}"] - 32) * 5/9)
end -- Capitalize some stats so they don't look so out of place
if weather["{sky}"] ~= "N/A" then
weather["{sky}"] = helpers.capitalize(weather["{sky}"])
if _weather["{sky}"] ~= "N/A" then
_weather["{sky}"] = helpers.capitalize(_weather["{sky}"])
end
if weather["{weather}"] ~= "N/A" then
weather["{weather}"] = helpers.capitalize(weather["{weather}"])
if _weather["{weather}"] ~= "N/A" then
_weather["{weather}"] = helpers.capitalize(_weather["{weather}"])
end
return weather
return _weather
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(weather, { __call = function(_, ...) return worker(...) end })

View File

@ -20,7 +20,8 @@ local string = {
-- Wifi: provides wireless information for a requested interface
module("vicious.widgets.wifi")
-- vicious.widgets.wifi
local wifi = {}
-- {{{ Wireless widget type
@ -77,4 +78,4 @@ local function worker(format, warg)
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
return setmetatable(wifi, { __call = function(_, ...) return worker(...) end })