aboutsummaryrefslogtreecommitdiff
path: root/mbox.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-03 01:28:37 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-03 01:28:37 +0100
commit9e91408ccb962edd2673d093fddd733b36306c35 (patch)
tree531f20f6c0c22058ede9aa3670658f3815551acf /mbox.lua
parent5ff8927b4b3099c1d25f86e67b1826e1dd5322e6 (diff)
downloadvicious-legacy-9e91408ccb962edd2673d093fddd733b36306c35.tar.xz
mbox: add scrolling support and truncate control
Widget argument can now be a string (full path to the mbox) or a table. In case of a table 1st field is full path to the mbox and 2nd is maximum text lenght after which it will be truncated. If there is a third field scrolling will be used - if so, 3rd field should be the widget name.
Diffstat (limited to 'mbox.lua')
-rw-r--r--mbox.lua21
1 files changed, 13 insertions, 8 deletions
diff --git a/mbox.lua b/mbox.lua
index d3079ed..543efab 100644
--- a/mbox.lua
+++ b/mbox.lua
@@ -4,6 +4,7 @@
---------------------------------------------------
-- {{{ Grab environment
+local type = type
local io = { open = io.open }
local setmetatable = setmetatable
local string = { gfind = string.gfind }
@@ -16,10 +17,11 @@ module("vicious.mbox")
-- {{{ Mailbox widget type
-local function worker(format, mbox)
+local function worker(format, warg)
+ if type(warg) ~= "table" then mbox = warg end
-- mbox could be huge, get a 30kb chunk from EOF
-- * attachments could be much bigger than this
- local f = io.open(mbox)
+ local f = io.open(mbox or warg[1])
f:seek("end", -30720)
local txt = f:read("*all")
f:close()
@@ -32,13 +34,16 @@ local function worker(format, mbox)
subject = i
end
- -- Spam sanitize only the last subject
- subject = helpers.escape(subject)
-
- -- Don't abuse the wibox, truncate
- subject = helpers.truncate(subject, 22)
+ -- Check if we should scroll, or maybe truncate
+ if type(warg) == "table" then
+ if warg[3] ~= nil then
+ subject = helpers.scroll(subject, warg[2], warg[3])
+ else
+ subject = helpers.truncate(subject, warg[2])
+ end
+ end
- return {subject}
+ return {helpers.escape(subject)}
end
-- }}}