aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArvydas Sidorenko <asido4@gmail.com>2012-06-15 17:34:25 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2012-06-18 01:26:24 +0200
commitb6b52900930ddb2a5b958a6d314766b455358164 (patch)
tree462746dac9357edca9a9216827529db557002ebe
parent0741531efd4bec3bd6836f8ea535e14daf5e2146 (diff)
downloadvicious-legacy-b6b52900930ddb2a5b958a6d314766b455358164.tar.xz
Ported vicious module to lua 5.2
Signed-off-by: Arvydas Sidorenko <asido4@gmail.com> Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
-rw-r--r--helpers.lua22
-rw-r--r--init.lua28
2 files changed, 28 insertions, 22 deletions
diff --git a/helpers.lua b/helpers.lua
index 223c5f1..93a701b 100644
--- a/helpers.lua
+++ b/helpers.lua
@@ -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
+
-- }}}
diff --git a/init.lua b/init.lua
index a7fdac0..fa57ea7 100644
--- a/init.lua
+++ b/init.lua
@@ -16,13 +16,12 @@ local table = {
insert = table.insert,
remove = table.remove
}
-require("vicious.helpers")
-require("vicious.widgets")
---require("vicious.contrib")
--- Vicious: widgets for the awesome window manager
-module("vicious")
+local helpers = require("vicious.helpers")
+-- Vicious: widgets for the awesome window manager
+local vicious = {}
+vicious.widgets = require("vicious.widgets")
-- Initialize tables
local timers = {}
@@ -140,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
@@ -170,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
@@ -206,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] = {}
@@ -216,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)
@@ -226,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
@@ -246,4 +245,7 @@ function activate(widget)
end
end
-- }}}
+
+return vicious
+
-- }}}