Padding removed, along with deprecated helper functions.
If you have any use for it then continue using an older vicious tag, or keep maintaining it in your local vicious copy.
This commit is contained in:
parent
2d4efa6893
commit
4c74de711f
17
README
17
README
|
@ -22,7 +22,7 @@ init.lua to comment out all the widgets you don't need, from the
|
|||
textbox, graph or a progressbar) call vicious.register() to register
|
||||
it with vicious:
|
||||
|
||||
vicious.register(widget, type, format, interval, field, argument or padding)
|
||||
vicious.register(widget, type, format, interval, field, warg)
|
||||
|
||||
widget - widget created with widget()
|
||||
type - one of the available widget types (see below for a list)
|
||||
|
@ -34,9 +34,7 @@ format - a string argument or a function
|
|||
data returned by the widget type, more below
|
||||
interval - number of seconds between updates of the widget
|
||||
field - used to feed graphs or progressbars, by their name
|
||||
padding - minimum amount of numbers the widget will output, if
|
||||
available for that widget type
|
||||
argument - some widgets require an argument to be passed, like the
|
||||
warg - some widgets require an argument to be passed, like the
|
||||
battery ID
|
||||
|
||||
|
||||
|
@ -76,9 +74,9 @@ Widget types
|
|||
------------
|
||||
|
||||
Widget types consist of worker functions that take the "format"
|
||||
argument given to vicious.register as the first argument, "padding" or
|
||||
"argument" the as the second, and return a table of values to insert
|
||||
in the format string.
|
||||
argument given to vicious.register as the first argument, "warg" as
|
||||
the second, and return a table of values to insert in the format
|
||||
string.
|
||||
|
||||
vicious.widgets.cpu
|
||||
- provides CPU usage for all available CPUs/cores
|
||||
|
@ -212,10 +210,9 @@ MPD widget
|
|||
|
||||
Memory widget
|
||||
memwidget = widget({type = 'textbox',name = 'memwidget'})
|
||||
vicious.register(memwidget,vicious.widgets.mem,'$1 ($2MB/$3MB)',1,nil,{2, 4, 4})
|
||||
vicious.register(memwidget,vicious.widgets.mem,'$1 ($2MB/$3MB)',1)
|
||||
|
||||
- executed every second, appends "MB" to 2nd and 3rd argument, uses
|
||||
padding
|
||||
- executed every second, appends "MB" to 2nd and 3rd argument
|
||||
|
||||
File system widget
|
||||
fswidget = widget({type = 'progressbar',name = 'fswidget'})
|
||||
|
|
17
cpu.lua
17
cpu.lua
|
@ -4,14 +4,11 @@
|
|||
----------------------------------------------------------
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
local io = { open = io.open }
|
||||
local setmetatable = setmetatable
|
||||
local math = { floor = math.floor }
|
||||
local table = { insert = table.insert }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -25,7 +22,7 @@ local cpu_total = {}
|
|||
local cpu_active = {}
|
||||
|
||||
-- {{{ CPU widget type
|
||||
function worker(format, padding)
|
||||
function worker(format)
|
||||
-- Get /proc/stat
|
||||
local f = io.open("/proc/stat")
|
||||
local cpu_lines = {}
|
||||
|
@ -79,18 +76,6 @@ function worker(format, padding)
|
|||
cpu_active[i] = active_new[i]
|
||||
end
|
||||
|
||||
if padding ~= nil then
|
||||
for k, v in pairs(cpu_usage) do
|
||||
if type(padding) == "table" then
|
||||
p = padding[k]
|
||||
else
|
||||
p = padding
|
||||
end
|
||||
|
||||
cpu_usage[k] = helpers.padd(cpu_usage[k], p)
|
||||
end
|
||||
end
|
||||
|
||||
return cpu_usage
|
||||
end
|
||||
-- }}}
|
||||
|
|
18
fs.lua
18
fs.lua
|
@ -4,10 +4,8 @@
|
|||
----------------------------------------------------------
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local io = { popen = io.popen }
|
||||
local setmetatable = setmetatable
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -16,7 +14,7 @@ module("vicious.fs")
|
|||
|
||||
|
||||
-- {{{ Filesystem widget type
|
||||
function worker(format, padding)
|
||||
function worker(format)
|
||||
-- Get data from df
|
||||
local f = io.popen("df -hP")
|
||||
local args = {}
|
||||
|
@ -30,20 +28,6 @@ function worker(format, padding)
|
|||
-- Instead match all at once, including network file systems
|
||||
line:match("^[%w/-:%.]+[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d]+)%%[%s]+([-/%w]+)$")
|
||||
|
||||
if padding then
|
||||
if type(padding) == "table" then
|
||||
size = helpers.padd(size, padding[1])
|
||||
used = helpers.padd(used, padding[2])
|
||||
avail = helpers.padd(avail, padding[3])
|
||||
usep = helpers.padd(usep, padding[4])
|
||||
else
|
||||
size = helpers.padd(size, padding)
|
||||
used = helpers.padd(used, padding)
|
||||
avail = helpers.padd(avail, padding)
|
||||
usep = helpers.padd(usep, padding)
|
||||
end
|
||||
end
|
||||
|
||||
args["{"..mount.." size}"] = size
|
||||
args["{"..mount.." used}"] = used
|
||||
args["{"..mount.." avail}"] = avail
|
||||
|
|
76
helpers.lua
76
helpers.lua
|
@ -5,18 +5,7 @@
|
|||
|
||||
-- {{{ Grab environment
|
||||
local pairs = pairs
|
||||
local tonumber = tonumber
|
||||
local tostring = tostring
|
||||
local table = { insert = table.insert }
|
||||
local math = {
|
||||
pow = math.pow,
|
||||
floor = math.floor
|
||||
}
|
||||
local string = {
|
||||
sub = string.sub,
|
||||
gsub = string.gsub,
|
||||
find = string.find
|
||||
}
|
||||
local string = { gsub = string.gsub }
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -27,78 +16,15 @@ module("vicious.helpers")
|
|||
-- {{{ Helper functions
|
||||
-- {{{ Format a string with args
|
||||
function format(format, args)
|
||||
-- Todo: Find a more efficient way to do this
|
||||
|
||||
-- Format a string
|
||||
for var, val in pairs(args) do
|
||||
format = string.gsub(format, "$" .. var, val)
|
||||
end
|
||||
|
||||
-- Return formatted string
|
||||
return format
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Padd a number to a minimum amount of digits
|
||||
function padd(number, padding)
|
||||
s = tostring(number)
|
||||
|
||||
if padding == nil then
|
||||
return s
|
||||
end
|
||||
|
||||
for i=1, padding do
|
||||
if math.floor(number/math.pow(10,(i-1))) == 0 then
|
||||
s = "0" .. s
|
||||
end
|
||||
end
|
||||
|
||||
if number == 0 then
|
||||
s = s:sub(2)
|
||||
end
|
||||
|
||||
return s
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Convert amount of bytes to string
|
||||
function bytes_to_string(bytes, sec, padding)
|
||||
if bytes == nil or tonumber(bytes) == nil then
|
||||
return ""
|
||||
end
|
||||
|
||||
bytes = tonumber(bytes)
|
||||
|
||||
local signs = {}
|
||||
signs[1] = " b"
|
||||
signs[2] = "KiB"
|
||||
signs[3] = "MiB"
|
||||
signs[4] = "GiB"
|
||||
signs[5] = "TiB"
|
||||
|
||||
sign = 1
|
||||
|
||||
while bytes/1024 > 1 and signs[sign+1] ~= nil do
|
||||
bytes = bytes/1024
|
||||
sign = sign+1
|
||||
end
|
||||
|
||||
bytes = bytes*10
|
||||
bytes = math.floor(bytes)/10
|
||||
|
||||
if padding then
|
||||
bytes = padd(bytes*10, padding+1)
|
||||
bytes = bytes:sub(1, bytes:len()-1) .. "." .. bytes:sub(bytes:len())
|
||||
end
|
||||
|
||||
if sec then
|
||||
return tostring(bytes) .. signs[sign] .. "ps"
|
||||
else
|
||||
return tostring(bytes) .. signs[sign]
|
||||
end
|
||||
end
|
||||
-- }}}
|
||||
|
||||
--{{{ Escape a string
|
||||
function escape(text)
|
||||
local xml_entities = {
|
||||
|
|
8
init.lua
8
init.lua
|
@ -88,7 +88,7 @@ end
|
|||
|
||||
-- {{{ Main functions
|
||||
-- {{{ Register widget
|
||||
function register(widget, wtype, format, timer, field, padd)
|
||||
function register(widget, wtype, format, timer, field, warg)
|
||||
local reg = {}
|
||||
local widget = widget
|
||||
|
||||
|
@ -97,7 +97,7 @@ function register(widget, wtype, format, timer, field, padd)
|
|||
reg.format = format
|
||||
reg.timer = timer
|
||||
reg.field = field
|
||||
reg.padd = padd
|
||||
reg.warg = warg
|
||||
reg.widget = widget
|
||||
|
||||
-- Update function
|
||||
|
@ -242,12 +242,12 @@ function update(widget, reg, disablecache)
|
|||
|
||||
if c.time == nil or c.time <= t - reg.timer or disablecache then
|
||||
c.time = t
|
||||
c.data = reg.type(reg.format, reg.padd)
|
||||
c.data = reg.type(reg.format, reg.warg)
|
||||
end
|
||||
|
||||
data = c.data
|
||||
else
|
||||
data = reg.type(reg.format, reg.padd)
|
||||
data = reg.type(reg.format, reg.warg)
|
||||
end
|
||||
|
||||
if type(data) == "table" then
|
||||
|
|
26
mem.lua
26
mem.lua
|
@ -4,12 +4,10 @@
|
|||
----------------------------------------------------------
|
||||
|
||||
-- {{{ Grab environment
|
||||
local type = type
|
||||
local tonumber = tonumber
|
||||
local io = { open = io.open }
|
||||
local setmetatable = setmetatable
|
||||
local math = { floor = math.floor }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -18,7 +16,7 @@ module("vicious.mem")
|
|||
|
||||
|
||||
-- {{{ Memory widget type
|
||||
function worker(format, padding)
|
||||
function worker(format)
|
||||
-- Get meminfo
|
||||
local f = io.open("/proc/meminfo")
|
||||
|
||||
|
@ -49,28 +47,6 @@ function worker(format, padding)
|
|||
swap_inuse = swap_total - swap_free
|
||||
swap_usepercent = math.floor(swap_inuse/swap_total*100)
|
||||
|
||||
if padding then
|
||||
if type(padding) == "table" then
|
||||
mem_usepercent = helpers.padd(mem_usepercent, padding[1])
|
||||
mem_inuse = helpers.padd(mem_inuse, padding[2])
|
||||
mem_total = helpers.padd(mem_total, padding[3])
|
||||
mem_free = helpers.padd(mem_free, padding[4])
|
||||
swap_usepercent = helpers.padd(swap_usepercent, padding[1])
|
||||
swap_inuse = helpers.padd(swap_inuse, padding[2])
|
||||
swap_total = helpers.padd(swap_total, padding[3])
|
||||
swap_free = helpers.padd(swap_free, padding[4])
|
||||
else
|
||||
mem_usepercent = helpers.padd(mem_usepercent, padding)
|
||||
mem_inuse = helpers.padd(mem_inuse, padding)
|
||||
mem_total = helpers.padd(mem_total, padding)
|
||||
mem_free = helpers.padd(mem_free, padding)
|
||||
swap_usepercent = helpers.padd(swap_usepercent, padding)
|
||||
swap_inuse = helpers.padd(swap_inuse, padding)
|
||||
swap_total = helpers.padd(swap_total, padding)
|
||||
swap_free = helpers.padd(swap_free, padding)
|
||||
end
|
||||
end
|
||||
|
||||
return {mem_usepercent, mem_inuse, mem_total, mem_free,
|
||||
swap_usepercent, swap_inuse, swap_total, swap_free}
|
||||
end
|
||||
|
|
19
net.lua
19
net.lua
|
@ -9,7 +9,6 @@ local os = { time = os.time }
|
|||
local io = { open = io.open }
|
||||
local setmetatable = setmetatable
|
||||
local math = { floor = math.floor }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -21,7 +20,7 @@ module("vicious.net")
|
|||
local nets = {}
|
||||
|
||||
-- {{{ Net widget type
|
||||
function worker(format, padding)
|
||||
function worker(format)
|
||||
-- Get /proc/net/dev
|
||||
local f = io.open("/proc/net/dev")
|
||||
local args = {}
|
||||
|
@ -36,14 +35,6 @@ function worker(format, padding)
|
|||
-- Transmited bytes, 7 fields from end of the line
|
||||
send = tonumber(line:match("([%d]+)%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d$"))
|
||||
|
||||
if padding then
|
||||
args["{"..name.." rx}"] = helpers.bytes_to_string(recv, nil, padding)
|
||||
args["{"..name.." tx}"] = helpers.bytes_to_string(send, nil, padding)
|
||||
else
|
||||
args["{"..name.." rx}"] = helpers.bytes_to_string(recv)
|
||||
args["{"..name.." tx}"] = helpers.bytes_to_string(send)
|
||||
end
|
||||
|
||||
args["{"..name.." rx_b}"] = math.floor(recv*10)/10
|
||||
args["{"..name.." tx_b}"] = math.floor(send*10)/10
|
||||
|
||||
|
@ -83,14 +74,6 @@ function worker(format, padding)
|
|||
down = (recv - nets[name][1])/interval
|
||||
up = (send - nets[name][2])/interval
|
||||
|
||||
if padding then
|
||||
args["{"..name.." down}"] = helpers.bytes_to_string(down, true, padding)
|
||||
args["{"..name.." up}"] = helpers.bytes_to_string(up, true, padding)
|
||||
else
|
||||
args["{"..name.." down}"] = helpers.bytes_to_string(down, true)
|
||||
args["{"..name.." up}"] = helpers.bytes_to_string(up, true)
|
||||
end
|
||||
|
||||
args["{"..name.." down_b}"] = math.floor(down*10)/10
|
||||
args["{"..name.." up_b}"] = math.floor(up*10)/10
|
||||
|
||||
|
|
19
uptime.lua
19
uptime.lua
|
@ -8,7 +8,6 @@ local tonumber = tonumber
|
|||
local io = { open = io.open }
|
||||
local setmetatable = setmetatable
|
||||
local math = { floor = math.floor }
|
||||
local helpers = require("vicious.helpers")
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -17,7 +16,7 @@ module("vicious.uptime")
|
|||
|
||||
|
||||
-- {{{ Uptime widget type
|
||||
function worker(format, padding)
|
||||
function worker(format)
|
||||
-- Get /proc/uptime
|
||||
local f = io.open("/proc/uptime")
|
||||
local line = f:read("*line")
|
||||
|
@ -31,22 +30,6 @@ function worker(format, padding)
|
|||
local uptime_minutes = math.floor(((total_uptime % (3600 * 24)) % 3600) / 60)
|
||||
local uptime_seconds = math.floor(((total_uptime % (3600 * 24)) % 3600) % 60)
|
||||
|
||||
if padding then
|
||||
if type(padding) == "table" then
|
||||
total_uptime = helpers.padd(total_uptime, padding[1])
|
||||
uptime_days = helpers.padd(uptime_days, padding[2])
|
||||
uptime_hours = helpers.padd(uptime_hours, padding[3])
|
||||
uptime_minutes = helpers.padd(uptime_minutes, padding[4])
|
||||
uptime_seconds = helpers.padd(uptime_seconds, padding[5])
|
||||
else
|
||||
total_uptime = helpers.padd(total_uptime, padding)
|
||||
uptime_days = helpers.padd(uptime_days, padding)
|
||||
uptime_hours = helpers.padd(uptime_hours, padding)
|
||||
uptime_minutes = helpers.padd(uptime_minutes, padding)
|
||||
uptime_seconds = helpers.padd(uptime_seconds, padding)
|
||||
end
|
||||
end
|
||||
|
||||
return {total_uptime, uptime_days, uptime_hours, uptime_minutes, uptime_seconds}
|
||||
end
|
||||
-- }}}
|
||||
|
|
Loading…
Reference in New Issue