All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010-2012, Peter Hofmann
7 * (c) 2010, Adrian C. <anrxc@sysphere.org>
8 * (c) 2009, Lucas de Vries <lucas@glacicle.com>
12 local newtimer = require("lain.helpers").newtimer
14 local wibox = require("wibox")
16 local io = { lines = io.lines }
17 local math = { floor = math.floor }
18 local string = { format = string.format,
19 gmatch = string.gmatch,
22 local setmetatable = setmetatable
24 -- Memory usage (ignoring caches)
29 local args = args or {}
30 local timeout = args.timeout or 3
31 local settings = args.settings or function() end
33 widget = wibox.widget.textbox('')
37 for line in io.lines("/proc/meminfo")
39 for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+")
41 if k == "MemTotal" then mem.total = math.floor(v / 1024)
42 elseif k == "MemFree" then mem.free = math.floor(v / 1024)
43 elseif k == "Buffers" then mem.buf = math.floor(v / 1024)
44 elseif k == "Cached" then mem.cache = math.floor(v / 1024)
45 elseif k == "SwapTotal" then mem.swap = math.floor(v / 1024)
46 elseif k == "SwapFree" then mem.swapf = math.floor(v / 1024)
51 used = mem.total - (mem.free + mem.buf + mem.cache)
52 swapused = mem.swap - mem.swapf
57 newtimer("mem", timeout, update)
62 return setmetatable(mem, { __call = function(_, ...) return worker(...) end })