aboutsummaryrefslogtreecommitdiff
path: root/mpd.lua
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-03 01:19:37 +0100
committerAdrian C. (anrxc) <anrxc@sysphere.org>2009-11-03 01:19:37 +0100
commit5ff8927b4b3099c1d25f86e67b1826e1dd5322e6 (patch)
treea95c0de0224144c652524ca07ca413fff3566308 /mpd.lua
parent589feb1ce937ae166695bb2ec2b0c85398cf1b5b (diff)
downloadvicious-legacy-5ff8927b4b3099c1d25f86e67b1826e1dd5322e6.tar.xz
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"}
Diffstat (limited to 'mpd.lua')
-rw-r--r--mpd.lua25
1 files 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)
-
- -- Don't abuse the wibox, truncate
- nowplaying = helpers.truncate(nowplaying, 30)
+ -- 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
- return {nowplaying}
+ return {helpers.escape(np)}
end
-- }}}