From 9e91408ccb962edd2673d093fddd733b36306c35 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Tue, 3 Nov 2009 01:28:37 +0100 Subject: 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. --- mbox.lua | 21 +++++++++++++-------- 1 file 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 -- }}} -- cgit v1.2.3