conky-config/drawing/Pacman.lua

74 lines
1.5 KiB
Lua
Raw Normal View History

local M = {}
2017-07-19 00:36:15 -04:00
local Text = require 'Text'
local Line = require 'Line'
local TextColumn = require 'TextColumn'
local Util = require 'Util'
2017-07-19 00:36:15 -04:00
local __string_match = string.match
local __string_gmatch = string.gmatch
local STATS_FILE = '/tmp/.conky_pacman'
2017-07-19 00:36:15 -04:00
local _TEXT_SPACING_ = 20
local header = _G_Widget_.Header{
2017-07-19 00:36:15 -04:00
x = _G_INIT_DATA_.RIGHT_X,
y = _G_INIT_DATA_.TOP_Y,
width = _G_INIT_DATA_.SECTION_WIDTH,
header = 'PACMAN'
}
local labels = _G_Widget_.TextColumn{
2017-07-19 00:36:15 -04:00
x = _G_INIT_DATA_.RIGHT_X,
y = header.bottom_y,
spacing = _TEXT_SPACING_,
'Total',
'Explicit',
'Outdated',
'Orphaned',
'Local'
}
local info = _G_Widget_.TextColumn{
2017-07-19 00:36:15 -04:00
x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = header.bottom_y,
spacing = _TEXT_SPACING_,
x_align = 'right',
text_color = _G_Patterns_.BLUE,
2017-07-19 00:36:15 -04:00
num_rows = 5
}
_TEXT_SPACING_ = nil
local update = function(cr)
local stats = __string_match(Util.read_file(STATS_FILE), '%d+%s+(.*)$')
if stats then
local i = 1
for v in __string_gmatch(stats, '[^%s]+') do
TextColumn.set(info, cr, i, v)
i = i + 1
end
else
for i=1,5 do
TextColumn.set(info, cr, i, 'N/A')
end
end
2017-07-19 00:36:15 -04:00
end
local draw_static = function(cr)
Text.draw(header.text, cr)
Line.draw(header.underline, cr)
TextColumn.draw(labels, cr)
end
local draw_dynamic = function(cr, log_is_changed)
2018-08-05 11:08:37 -04:00
if log_is_changed then update(cr) end
2018-08-05 11:08:37 -04:00
TextColumn.draw(info, cr)
2017-07-19 00:36:15 -04:00
end
M.draw_static = draw_static
M.draw_dynamic = draw_dynamic
return M