From 5ff8927b4b3099c1d25f86e67b1826e1dd5322e6 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Tue, 3 Nov 2009 01:19:37 +0100 Subject: [PATCH] mpd: add scrolling support and truncate control Widget takes an optional argument that controls truncate and scrolling. In case of a number truncate is used, it represents the maximum lenght of widget text. In case of a table scrolling is used, 1st field is maximum lenght, and 2nd is widget name. An example: {24, "mpdwidget"} --- mpd.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/mpd.lua b/mpd.lua index 350858f..0d3336b 100644 --- a/mpd.lua +++ b/mpd.lua @@ -5,10 +5,11 @@ --------------------------------------------------- -- {{{ Grab environment +local type = type local io = { popen = io.popen } local setmetatable = setmetatable -local helpers = require("vicious.helpers") local string = { find = string.find } +local helpers = require("vicious.helpers") -- }}} @@ -17,25 +18,29 @@ module("vicious.mpd") -- {{{ MPD widget type -local function worker(format) +local function worker(format, warg) -- Get data from mpc local f = io.popen("mpc") local np = f:read("*line") f:close() -- Check if it's stopped, off or not installed - if np == nil - or (string.find(np, "MPD_HOST") or string.find(np, "volume:")) then + if np == nil or + (string.find(np, "MPD_HOST") or string.find(np, "volume:")) + then return {"Stopped"} end - -- Sanitize the song name - local nowplaying = helpers.escape(np) + -- Check if we should scroll, or maybe truncate + if warg then + if type(warg) == "table" then + np = helpers.scroll(np, warg[1], warg[2]) + else + np = helpers.truncate(np, warg) + end + end - -- Don't abuse the wibox, truncate - nowplaying = helpers.truncate(nowplaying, 30) - - return {nowplaying} + return {helpers.escape(np)} end -- }}}