<commit_before>local awful = require("awful")
local watch = require("awful.widget.watch")
local wibox = require("wibox")

local ramgraph_widget = wibox.widget {
    border_width = 0,
    colors = {
        '#74aeab', '#26403f'
    },
    display_labels = false,
    forced_width = 25,
    widget = wibox.widget.piechart
}

local total, used, free, shared, buff_cache, available

watch('bash -c "free | grep Mem"', 1,
    function(widget, stdout, stderr, exitreason, exitcode)
        total, used, free, shared, buff_cache, available = stdout:match('(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)')

        widget.data = {used, total-used}
    end,
    ramgraph_widget
)

local w = wibox {
    height = 200,
    width = 350,
    ontop = true,
    screen = mouse.screen,
    expand = true,
    bg = '#1e252c',
    max_widget_size = 500
}

w:setup {
    {
        border_width = 0,
        colors = {
            '#74aeab',
            '#6eaaa7',
            '#5ea19d',
            '#55918e',
            '#4b817e',
        },
        display_labels = false,
        forced_width = 25,
        id = 'pie',
        widget = wibox.widget.piechart
    },
    {
        text = 'Hello',
        widget = wibox.widget.textbox
    },
    id = 'popup',
    layout = wibox.layout.stack
}

local function getPercentage(value)
    return math.floor(value / total * 100 + 0.5) .. '%'
end

ramgraph_widget:buttons(
    awful.util.table.join(
        awful.button({}, 1, function()
            awful.placement.top_right(w, { margins = {top = 25, right = 10}})
            w.popup.pie.data_list = {
                {'used ' .. getPercentage(used), used},
                {'free ' .. getPercentage(free), free},
--                {'shared ' .. getPercentage(shared), shared},
                {'buff_cache ' .. getPercentage(buff_cache), buff_cache},
--                {'available ' .. getPercentage(available), available}
            }
            w.popup.pie.display_labels = true
            w.visible = true
        end),
        awful.button({}, 3, function()
            w.visible = false;
        end)
    )
)

return ramgraph_widget<commit_msg>few improvements<commit_after>local awful = require("awful")
local watch = require("awful.widget.watch")
local wibox = require("wibox")

--- Main ram widget shown on wibar
local ramgraph_widget = wibox.widget {
    border_width = 0,
    colors = {
        '#74aeab', '#26403f'
    },
    display_labels = false,
    forced_width = 25,
    widget = wibox.widget.piechart
}

--- Widget which is shown when user clicks on the ram widget
local w = wibox {
    height = 200,
    width = 400,
    ontop = true,
    screen = mouse.screen,
    expand = true,
    bg = '#1e252c',
    max_widget_size = 500
}

w:setup {
    border_width = 0,
    colors = {
--        '#74aeab',
--        '#6eaaa7',
        '#5ea19d',
        '#55918e',
        '#4b817e',
    },
    display_labels = false,
    forced_width = 25,
    id = 'pie',
    widget = wibox.widget.piechart
}

local total, used, free, shared, buff_cache, available

local function getPercentage(value)
    return math.floor(value / total * 100 + 0.5) .. '%'
end

watch('bash -c "free | grep Mem"', 1,
    function(widget, stdout, stderr, exitreason, exitcode)
        total, used, free, shared, buff_cache, available = stdout:match('(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)%s*(%d+)')
        widget.data = { used, total-used }

        if w.visible then
            w.pie.data_list = {
                {'used ' .. getPercentage(used), used},
                {'free ' .. getPercentage(free), free},
                {'buff_cache ' .. getPercentage(buff_cache), buff_cache}
            }
        end
    end,
    ramgraph_widget
)

ramgraph_widget:buttons(
    awful.util.table.join(
        awful.button({}, 1, function()
            awful.placement.top_right(w, { margins = {top = 25, right = 10}})
            w.pie.data_list = {
                {'used ' .. getPercentage(used), used},
                {'free ' .. getPercentage(free), free},
                {'buff_cache ' .. getPercentage(buff_cache), buff_cache}
            }
            w.pie.display_labels = true
            w.visible = not w.visible
        end)
    )
)

return ramgraph_widget
{'fraction_non_alphanumeric': 0.1478240302743614, 'fraction_numerical': 0.02530747398297067, 'mean_word_length': 2.055635838150289, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686753', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1397, 'n_words': 300}