Debian Codegraph @

vicious/widgets/volume_freebsd.lua

raw symbols SCIP
1 -- volume widget type for FreeBSD
2 -- Copyright (C) 2017,2019 mutlusun <[email protected]>
3 -- Copyright (C) 2019 Nguyễn Gia Phong <[email protected]m>
4 --
5 -- This file is part of Vicious.
6 --
7 -- Vicious is free software: you can redistribute it and/or modify
8 -- it under the terms of the GNU General Public License as
9 -- published by the Free Software Foundation, either version 2 of the
10 -- License, or (at your option) any later version.
11 --
12 -- Vicious is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 -- GNU General Public License for more details.
16 --
17 -- You should have received a copy of the GNU General Public License
18 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
19
20 -- {{{ Grab environment
21 local tonumber = tonumber
22 local string = { match = string.match }
23 local helpers = require("vicious.helpers")
24 local spawn = require("vicious.spawn")
25 -- }}}
26
27 -- Volume: provides volume levels and state of requested mixer
28 -- vicious.widgets.volume_freebsd
29 local volume_freebsd = {}
30
31 -- {{{ Volume widget type
32 local STATE = { on = '🔉', off = '🔈' }
33
34 local function parse(stdout, stderr, exitreason, exitcode)
35 -- Capture mixer control state, e.g. 42 : 42
36 local voll, volr = string.match(stdout, "([%d]+):([%d]+)\n$")
37 if voll == "0" and volr == "0" then return { 0, 0, STATE.off } end
38 return { tonumber(voll), tonumber(volr), STATE.on }
39 end
40
41 function volume_freebsd.async(format, warg, callback)
42 if not warg then return callback{} end
43 spawn.easy_async("mixer " .. helpers.shellquote(warg),
44 function (...) callback(parse(...)) end)
45 end
46 -- }}}
47
48 return helpers.setasyncall(volume_freebsd)