Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
----------------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License version 2
|
|
|
|
-- * Copyright (C) 2009 Adrian C. <anrxc_sysphere_org>
|
|
|
|
----------------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ 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
|
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Helpers: provides helper functions for vicious widgets
|
|
|
|
module("vicious.helpers")
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ Helper functions
|
|
|
|
-- {{{ Format a string with args
|
|
|
|
function format(format, args)
|
2009-07-29 23:40:50 +02:00
|
|
|
-- Todo: Find a more efficient way to do this
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
|
|
|
-- Format a string
|
|
|
|
for var, val in pairs(args) do
|
2009-08-03 04:29:06 +02:00
|
|
|
format = string.gsub(format, "$" .. var, val)
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
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
|
2009-08-03 04:29:06 +02:00
|
|
|
s = "0" .. s
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
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)
|
2009-08-03 04:29:06 +02:00
|
|
|
bytes = bytes:sub(1, bytes:len()-1) .. "." .. bytes:sub(bytes:len())
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if sec then
|
2009-08-03 04:29:06 +02:00
|
|
|
return tostring(bytes) .. signs[sign] .. "ps"
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
else
|
2009-08-03 04:29:06 +02:00
|
|
|
return tostring(bytes) .. signs[sign]
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
--{{{ Escape a string
|
|
|
|
function escape(text)
|
2009-08-03 04:29:06 +02:00
|
|
|
local xml_entities = {
|
|
|
|
["\""] = """,
|
|
|
|
["&"] = "&",
|
|
|
|
["'"] = "'",
|
|
|
|
["<"] = "<",
|
|
|
|
[">"] = ">"
|
|
|
|
}
|
|
|
|
|
|
|
|
return text and text:gsub("[\"&'<>]", xml_entities)
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
-- }}}
|