Debian Codegraph @

vicious/widgets/mdir_all.lua

raw symbols SCIP
1 -- widget type providing number of new and unread Maildir messages
2 -- Copyright (C) 2010 Adrian C. <[email protected]>
3 -- Copyright (C) 2010 Fredrik Ax
4 -- Copyright (C) 2017 mutlusun <[email protected]>
5 -- Copyright (C) 2019 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
25 local helpers = require"vicious.helpers"
26 local spawn = require"vicious.spawn"
27 -- }}}
28
29 -- vicious.widgets.mdir
30 local mdir_all = {}
31
32 -- {{{ Maildir widget type
33 function mdir_all.async(format, warg, callback)
34 if type(warg) ~= "table" then return callback{} end
35 local starting_points = ""
36 for _,dir in ipairs(warg) do
37 starting_points = starting_points .. " " .. helpers.shellquote(dir)
38 end
39 if starting_points == "" then return callback{ 0, 0 } end
40
41 local new, cur = 0, 0
42 spawn.with_line_callback(
43 "find" .. starting_points .. " -type f -regex '.*/cur/.*2,[^S]*$'",
44 { stdout = function (filename) cur = cur + 1 end,
45 output_done = function ()
46 spawn.with_line_callback(
47 "find" .. starting_points .. " -type f -path '*/new/*'",
48 { stdout = function (filename) new = new + 1 end,
49 output_done = function () callback{ new, cur } end })
50 end })
51 end
52 -- }}}
53
54 return helpers.setasyncall(mdir_all)