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 = { format = string.format,
17 gmatch = string.gmatch,
20 local setmetatable = setmetatable
22 -- Memory usage (ignoring caches)
26 local function worker(args)
27 local args = args or {}
28 local timeout = args.timeout or 3
29 local settings = args.settings or function() end
31 mem.widget = wibox.widget.textbox('')
35 for line in io.lines("/proc/meminfo")
37 for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+")
39 if k == "MemTotal" then mem_now.total = math.floor(v / 1024)
40 elseif k == "MemFree" then mem_now.free = math.floor(v / 1024)
41 elseif k == "Buffers" then mem_now.buf = math.floor(v / 1024)
42 elseif k == "Cached" then mem_now.cache = math.floor(v / 1024)
43 elseif k == "SwapTotal" then mem_now.swap = math.floor(v / 1024)
44 elseif k == "SwapFree" then mem_now.swapf = math.floor(v / 1024)
49 mem_now.used = mem_now.total - (mem_now.free + mem_now.buf + mem_now.cache)
50 mem_now.swapused = mem_now.swap - mem_now.swapf
56 newtimer("mem", timeout, update)
61 return setmetatable(mem, { __call = function(_, ...) return worker(...) end })