Debian Codegraph @

vicious/widgets/notmuch_all.lua

raw symbols SCIP
1 -- notmuch_all - count messages that match a notmuch query
2 -- Copyright (C) 2019 Enric Morales <[email protected]>
3 --
4 -- This file is part of Vicious.
5 --
6 -- Vicious is free software: you can redistribute it and/or modify
7 -- it under the terms of the GNU General Public License as
8 -- published by the Free Software Foundation, either version 2 of the
9 -- License, or (at your option) any later version.
10 --
11 -- Vicious is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU Affero General Public License for more details.
15 --
16 -- You should have received a copy of the GNU Affero General Public License
17 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
18
19 local tonumber = tonumber
20 local helpers = require("vicious.helpers")
21 local spawn = require("vicious.spawn")
22
23
24 local notmuch = {}
25
26 local function parse(stdout, stderr, exitreason, exitcode)
27 local output = { count = "N/A" }
28 if exitcode == 0 then output.count = tonumber(stdout) end
29 return output
30 end
31
32 function notmuch.async(format, warg, callback)
33 local cmd = ("notmuch count '^%s'"):format(warg)
34
35 spawn.easy_async(cmd, function (...) callback(parse(...)) end)
36 end
37
38 return helpers.setasyncall(notmuch)