diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-11-03 01:28:37 +0100 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-11-03 01:28:37 +0100 |
commit | 9e91408ccb962edd2673d093fddd733b36306c35 (patch) | |
tree | 531f20f6c0c22058ede9aa3670658f3815551acf | |
parent | 5ff8927b4b3099c1d25f86e67b1826e1dd5322e6 (diff) | |
download | vicious-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.
-rw-r--r-- | mbox.lua | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -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 -- }}} |