Debian Codegraph @

vicious/contrib/mpc_all.lua

raw symbols SCIP
1 -- contrib/mpc_all.lua
2 -- Copyright (C) 2009 Lucas de Vries <[email protected]>
3 -- Copyright (C) 2010 Adrian C. <[email protected]>
4 -- Copyright (C) 2017 Jörg Thalheim <[email protected]>
5 -- Copyright (C) 2018 Nguyễn Gia Phong <[email protected]m>
6 --
7 -- This file is part of Vicious.
8 --
9 -- Vicious is free software: you can redistribute it and/or modify
10 -- it under the terms of the GNU General Public License as
11 -- published by the Free Software Foundation, either version 2 of the
12 -- License, or (at your option) any later version.
13 --
14 -- Vicious is distributed in the hope that it will be useful,
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 -- GNU General Public License for more details.
18 --
19 -- You should have received a copy of the GNU General Public License
20 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
21
22 -- {{{ Grab environment
23 local type = type
24 local io = { popen = io.popen }
25 local setmetatable = setmetatable
26 local string = { find = string.find }
27 local helpers = require("vicious.helpers")
28 -- }}}
29
30
31 -- Mpc: provides the currently playing song in MPD
32 -- vicious.contrib.mpc
33 local mpc_all = {}
34
35
36 -- {{{ MPC widget type
37 local function worker(format, warg)
38 -- Get data from mpd
39 local f = io.popen("mpc")
40 local np = f:read("*line")
41 f:close()
42
43 -- Not installed,
44 if np == nil or -- off or stoppped.
45 (string.find(np, "MPD_HOST") or string.find(np, "volume:"))
46 then
47 return {"Stopped"}
48 end
49
50 -- Check if we should scroll, or maybe truncate
51 if warg then
52 if type(warg) == "table" then
53 np = helpers.scroll(np, warg[1], warg[2])
54 else
55 np = helpers.truncate(np, warg)
56 end
57 end
58
59 return {np}
60 end
61 -- }}}
62
63 return setmetatable(mpc_all, { __call = function(_, ...) return worker(...) end })