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
10 local newtimer = require("lain.helpers").newtimer
12 local wibox = require("wibox")
14 local io = { lines = io.lines }
15 local math = { floor = math.floor }
16 local string = { gmatch = string.gmatch }
18 local setmetatable = setmetatable
20 -- Memory usage (ignoring caches)
24 local function worker(args)
25 local args = args or {}
26 local timeout = args.timeout or 3
27 local settings = args.settings or function() end
29 mem.widget = wibox.widget.textbox('')
33 for line in io.lines("/proc/meminfo")
35 for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+")
37 if k == "MemTotal" then mem_now.total = math.floor(v / 1024)
38 elseif k == "MemFree" then mem_now.free = math.floor(v / 1024)
39 elseif k == "Buffers" then mem_now.buf = math.floor(v / 1024)
40 elseif k == "Cached" then mem_now.cache = math.floor(v / 1024)
41 elseif k == "SwapTotal" then mem_now.swap = math.floor(v / 1024)
42 elseif k == "SwapFree" then mem_now.swapf = math.floor(v / 1024)
47 mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache)
48 mem_now.swapused = mem_now.swap - mem_now.swapf
54 newtimer("mem", timeout, update)
59 return setmetatable(mem, { __call = function(_, ...) return worker(...) end })