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 markup = require("lain.util.markup")
13 local run_in_terminal = require("lain.helpers").run_in_terminal
15 local beautiful = require("beautiful")
16 local wibox = require("wibox")
18 local io = { lines = io.lines }
19 local math = { floor = math.floor }
20 local string = { format = string.format,
21 gmatch = string.gmatch,
24 local setmetatable = setmetatable
26 -- Memory usage (ignoring caches)
31 local args = args or {}
32 local refresh_timeout = args.refresh_timeout or 10
33 local show_swap = args.show_swap or false
34 local show_total = args.show_total or false
35 local header = args.header or " Mem "
36 local header_color = args.header or beautiful.fg_normal or "#FFFFFF"
37 local color = args.color or beautiful.fg_focus or "#FFFFFF"
38 local footer = args.footer or "MB"
40 local widg = wibox.widget.textbox()
42 local upd = function()
44 for line in io.lines("/proc/meminfo")
46 for k, v in string.gmatch(line, "([%a]+):[%s]+([%d]+).+")
48 if k == "MemTotal" then mem.total = math.floor(v / 1024)
49 elseif k == "MemFree" then mem.free = math.floor(v / 1024)
50 elseif k == "Buffers" then mem.buf = math.floor(v / 1024)
51 elseif k == "Cached" then mem.cache = math.floor(v / 1024)
52 elseif k == "SwapTotal" then mem.swap = math.floor(v / 1024)
53 elseif k == "SwapFree" then mem.swapf = math.floor(v / 1024)
58 used = mem.total - (mem.free + mem.buf + mem.cache)
59 swapused = mem.swap - mem.swapf
63 local fmt = "%" .. string.len(mem.total) .. ".0f/%.0f"
64 widg:set_markup(markup(header_color, header) ..
65 markup(color, string.format(fmt, used, mem.total) .. footer .. " "))
67 widg:set_markup(markup(header_color, header) ..
68 markup(color, used .. footer .. " "))
73 widg:set_markup(widg._layout.text .. ' ('
74 .. string.format('%.0f '.. footer, swapused)
79 local tmr = timer({ timeout = refresh_timeout })
80 tmr:connect_signal("timeout", upd)
82 tmr:emit_signal("timeout")
87 return setmetatable(mem, { __call = function(_, ...) return worker(...) end })