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
|
textbox, graph or a progressbar) call vicious.register() to register
|
||||||
it with vicious:
|
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()
|
widget - widget created with widget()
|
||||||
type - one of the available widget types (see below for a list)
|
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
|
data returned by the widget type, more below
|
||||||
interval - number of seconds between updates of the widget
|
interval - number of seconds between updates of the widget
|
||||||
field - used to feed graphs or progressbars, by their name
|
field - used to feed graphs or progressbars, by their name
|
||||||
padding - minimum amount of numbers the widget will output, if
|
warg - some widgets require an argument to be passed, like the
|
||||||
available for that widget type
|
|
||||||
argument - some widgets require an argument to be passed, like the
|
|
||||||
battery ID
|
battery ID
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,9 +74,9 @@ Widget types
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Widget types consist of worker functions that take the "format"
|
Widget types consist of worker functions that take the "format"
|
||||||
argument given to vicious.register as the first argument, "padding" or
|
argument given to vicious.register as the first argument, "warg" as
|
||||||
"argument" the as the second, and return a table of values to insert
|
the second, and return a table of values to insert in the format
|
||||||
in the format string.
|
string.
|
||||||
|
|
||||||
vicious.widgets.cpu
|
vicious.widgets.cpu
|
||||||
- provides CPU usage for all available CPUs/cores
|
- provides CPU usage for all available CPUs/cores
|
||||||
|
@ -212,10 +210,9 @@ MPD widget
|
||||||
|
|
||||||
Memory widget
|
Memory widget
|
||||||
memwidget = widget({type = 'textbox',name = 'memwidget'})
|
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
|
- executed every second, appends "MB" to 2nd and 3rd argument
|
||||||
padding
|
|
||||||
|
|
||||||
File system widget
|
File system widget
|
||||||
fswidget = widget({type = 'progressbar',name = 'fswidget'})
|
fswidget = widget({type = 'progressbar',name = 'fswidget'})
|
||||||
|
|
17
cpu.lua
17
cpu.lua
|
@ -4,14 +4,11 @@
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local type = type
|
|
||||||
local pairs = pairs
|
|
||||||
local ipairs = ipairs
|
local ipairs = ipairs
|
||||||
local io = { open = io.open }
|
local io = { open = io.open }
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local table = { insert = table.insert }
|
local table = { insert = table.insert }
|
||||||
local helpers = require("vicious.helpers")
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +22,7 @@ local cpu_total = {}
|
||||||
local cpu_active = {}
|
local cpu_active = {}
|
||||||
|
|
||||||
-- {{{ CPU widget type
|
-- {{{ CPU widget type
|
||||||
function worker(format, padding)
|
function worker(format)
|
||||||
-- Get /proc/stat
|
-- Get /proc/stat
|
||||||
local f = io.open("/proc/stat")
|
local f = io.open("/proc/stat")
|
||||||
local cpu_lines = {}
|
local cpu_lines = {}
|
||||||
|
@ -79,18 +76,6 @@ function worker(format, padding)
|
||||||
cpu_active[i] = active_new[i]
|
cpu_active[i] = active_new[i]
|
||||||
end
|
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
|
return cpu_usage
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
18
fs.lua
18
fs.lua
|
@ -4,10 +4,8 @@
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local type = type
|
|
||||||
local io = { popen = io.popen }
|
local io = { popen = io.popen }
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local helpers = require("vicious.helpers")
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +14,7 @@ module("vicious.fs")
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Filesystem widget type
|
-- {{{ Filesystem widget type
|
||||||
function worker(format, padding)
|
function worker(format)
|
||||||
-- Get data from df
|
-- Get data from df
|
||||||
local f = io.popen("df -hP")
|
local f = io.popen("df -hP")
|
||||||
local args = {}
|
local args = {}
|
||||||
|
@ -30,20 +28,6 @@ function worker(format, padding)
|
||||||
-- Instead match all at once, including network file systems
|
-- 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]+)$")
|
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.." size}"] = size
|
||||||
args["{"..mount.." used}"] = used
|
args["{"..mount.." used}"] = used
|
||||||
args["{"..mount.." avail}"] = avail
|
args["{"..mount.." avail}"] = avail
|
||||||
|
|
76
helpers.lua
76
helpers.lua
|
@ -5,18 +5,7 @@
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local tonumber = tonumber
|
local string = { gsub = string.gsub }
|
||||||
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
|
|
||||||
}
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,78 +16,15 @@ module("vicious.helpers")
|
||||||
-- {{{ Helper functions
|
-- {{{ Helper functions
|
||||||
-- {{{ Format a string with args
|
-- {{{ Format a string with args
|
||||||
function format(format, args)
|
function format(format, args)
|
||||||
-- Todo: Find a more efficient way to do this
|
|
||||||
|
|
||||||
-- Format a string
|
-- Format a string
|
||||||
for var, val in pairs(args) do
|
for var, val in pairs(args) do
|
||||||
format = string.gsub(format, "$" .. var, val)
|
format = string.gsub(format, "$" .. var, val)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return formatted string
|
|
||||||
return format
|
return format
|
||||||
end
|
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
|
--{{{ Escape a string
|
||||||
function escape(text)
|
function escape(text)
|
||||||
local xml_entities = {
|
local xml_entities = {
|
||||||
|
|
8
init.lua
8
init.lua
|
@ -88,7 +88,7 @@ end
|
||||||
|
|
||||||
-- {{{ Main functions
|
-- {{{ Main functions
|
||||||
-- {{{ Register widget
|
-- {{{ Register widget
|
||||||
function register(widget, wtype, format, timer, field, padd)
|
function register(widget, wtype, format, timer, field, warg)
|
||||||
local reg = {}
|
local reg = {}
|
||||||
local widget = widget
|
local widget = widget
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ function register(widget, wtype, format, timer, field, padd)
|
||||||
reg.format = format
|
reg.format = format
|
||||||
reg.timer = timer
|
reg.timer = timer
|
||||||
reg.field = field
|
reg.field = field
|
||||||
reg.padd = padd
|
reg.warg = warg
|
||||||
reg.widget = widget
|
reg.widget = widget
|
||||||
|
|
||||||
-- Update function
|
-- Update function
|
||||||
|
@ -242,12 +242,12 @@ function update(widget, reg, disablecache)
|
||||||
|
|
||||||
if c.time == nil or c.time <= t - reg.timer or disablecache then
|
if c.time == nil or c.time <= t - reg.timer or disablecache then
|
||||||
c.time = t
|
c.time = t
|
||||||
c.data = reg.type(reg.format, reg.padd)
|
c.data = reg.type(reg.format, reg.warg)
|
||||||
end
|
end
|
||||||
|
|
||||||
data = c.data
|
data = c.data
|
||||||
else
|
else
|
||||||
data = reg.type(reg.format, reg.padd)
|
data = reg.type(reg.format, reg.warg)
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(data) == "table" then
|
if type(data) == "table" then
|
||||||
|
|
26
mem.lua
26
mem.lua
|
@ -4,12 +4,10 @@
|
||||||
----------------------------------------------------------
|
----------------------------------------------------------
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local type = type
|
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local io = { open = io.open }
|
local io = { open = io.open }
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local helpers = require("vicious.helpers")
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +16,7 @@ module("vicious.mem")
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Memory widget type
|
-- {{{ Memory widget type
|
||||||
function worker(format, padding)
|
function worker(format)
|
||||||
-- Get meminfo
|
-- Get meminfo
|
||||||
local f = io.open("/proc/meminfo")
|
local f = io.open("/proc/meminfo")
|
||||||
|
|
||||||
|
@ -49,28 +47,6 @@ function worker(format, padding)
|
||||||
swap_inuse = swap_total - swap_free
|
swap_inuse = swap_total - swap_free
|
||||||
swap_usepercent = math.floor(swap_inuse/swap_total*100)
|
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,
|
return {mem_usepercent, mem_inuse, mem_total, mem_free,
|
||||||
swap_usepercent, swap_inuse, swap_total, swap_free}
|
swap_usepercent, swap_inuse, swap_total, swap_free}
|
||||||
end
|
end
|
||||||
|
|
19
net.lua
19
net.lua
|
@ -9,7 +9,6 @@ local os = { time = os.time }
|
||||||
local io = { open = io.open }
|
local io = { open = io.open }
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local helpers = require("vicious.helpers")
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +20,7 @@ module("vicious.net")
|
||||||
local nets = {}
|
local nets = {}
|
||||||
|
|
||||||
-- {{{ Net widget type
|
-- {{{ Net widget type
|
||||||
function worker(format, padding)
|
function worker(format)
|
||||||
-- Get /proc/net/dev
|
-- Get /proc/net/dev
|
||||||
local f = io.open("/proc/net/dev")
|
local f = io.open("/proc/net/dev")
|
||||||
local args = {}
|
local args = {}
|
||||||
|
@ -36,14 +35,6 @@ function worker(format, padding)
|
||||||
-- Transmited bytes, 7 fields from end of the line
|
-- 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$"))
|
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.." rx_b}"] = math.floor(recv*10)/10
|
||||||
args["{"..name.." tx_b}"] = math.floor(send*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
|
down = (recv - nets[name][1])/interval
|
||||||
up = (send - nets[name][2])/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.." down_b}"] = math.floor(down*10)/10
|
||||||
args["{"..name.." up_b}"] = math.floor(up*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 io = { open = io.open }
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
local math = { floor = math.floor }
|
local math = { floor = math.floor }
|
||||||
local helpers = require("vicious.helpers")
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ module("vicious.uptime")
|
||||||
|
|
||||||
|
|
||||||
-- {{{ Uptime widget type
|
-- {{{ Uptime widget type
|
||||||
function worker(format, padding)
|
function worker(format)
|
||||||
-- Get /proc/uptime
|
-- Get /proc/uptime
|
||||||
local f = io.open("/proc/uptime")
|
local f = io.open("/proc/uptime")
|
||||||
local line = f:read("*line")
|
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_minutes = math.floor(((total_uptime % (3600 * 24)) % 3600) / 60)
|
||||||
local uptime_seconds = 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}
|
return {total_uptime, uptime_days, uptime_hours, uptime_minutes, uptime_seconds}
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
Loading…
Reference in New Issue