local awful = require("awful")
local watch = awful.widget.watch
local beautiful = require("beautiful")
local xresources = require("beautiful.xresources")
local dpi = xresources.apply_dpi
local wibox = require("wibox")
local helpers = require("helpers")
local icons = require("icons")



local function ram()
	local stats = widget(icons.ram)

	watch('bash -c "free | grep -z Mem.*Swap.*"', 10, function(_, stdout)
		local total, used, free, shared, buff_cache, available, total_swap, used_swap, free_swap = stdout:match(
			"(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*Swap:%s*(%d+)%s*(%d+)%s*(%d+)"
		)
		stats:set_value(used / total * 100)
		collectgarbage("collect")
	end)

	return stats
end

return function(s)
    local accent_color = beautiful.xforeground
    local ram = wibox.widget({
		widget = wibox.widget.textbox
		align = "center",
		valign = "center",
		font = beautiful.font_name .. "Medium 12",
        text = ram()
	})