Debian Codegraph @

vicious/widgets/uptime_linux.lua

raw symbols SCIP
1 -- uptime widget type for GNU/Linux
2 -- Copyright (C) 2009 Lucas de Vries <[email protected]>
3 -- Copyright (C) 2010 Adrian C. <[email protected]>
4 -- Copyright (C) 2017 mutlusun <[email protected]>
5 --
6 -- This file is part of Vicious.
7 --
8 -- Vicious is free software: you can redistribute it and/or modify
9 -- it under the terms of the GNU General Public License as
10 -- published by the Free Software Foundation, either version 2 of the
11 -- License, or (at your option) any later version.
12 --
13 -- Vicious is distributed in the hope that it will be useful,
14 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
15 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 -- GNU General Public License for more details.
17 --
18 -- You should have received a copy of the GNU General Public License
19 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
20
21 -- {{{ Grab environment
22 local math = { floor = math.floor }
23 local string = { match = string.match }
24 local helpers = require("vicious.helpers")
25 -- }}}
26
27 -- {{{ Uptime widget type
28 return helpers.setcall(function ()
29 local proc = helpers.pathtotable("/proc")
30
31 -- Get system uptime
32 local up_t = math.floor(string.match(proc.uptime, "[%d]+"))
33 local up_d = math.floor(up_t / (3600 * 24))
34 local up_h = math.floor((up_t % (3600 * 24)) / 3600)
35 local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60)
36
37 local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes
38 string.match(proc.loadavg, "([%d%.]+)[%s]([%d%.]+)[%s]([%d%.]+)")
39 return {up_d, up_h, up_m, l1, l5, l15}
40 end)
41 -- }}}