conky-config/module/System.lua

68 lines
1.6 KiB
Lua
Raw Normal View History

2016-08-11 23:25:56 -04:00
local Widget = require 'Widget'
local Text = require 'Text'
local Line = require 'Line'
local TextColumn = require 'TextColumn'
local util = require 'util'
local schema = require 'default_patterns'
2017-07-17 03:31:18 -04:00
local __string_match = string.match
2016-08-11 23:25:56 -04:00
2017-07-17 03:31:18 -04:00
local _TEXT_SPACING_ = 20
2016-08-11 23:25:56 -04:00
2017-07-17 03:39:58 -04:00
local extract_date = function(cmd)
local yyyy, mm_dd = __string_match(util.execute_cmd(cmd), '%[(%d-)%-(%d-%-%d-)%s')
return mm_dd..'-'..yyyy
end
2016-08-11 23:25:56 -04:00
local header = Widget.Header{
2017-07-16 14:50:33 -04:00
x = _G_INIT_DATA_.LEFT_X,
y = _G_INIT_DATA_.TOP_Y,
width = _G_INIT_DATA_.SECTION_WIDTH,
2017-07-17 03:31:18 -04:00
header = 'SYSTEM'
2016-08-11 23:25:56 -04:00
}
local labels = Widget.TextColumn{
2017-07-16 14:50:33 -04:00
x = _G_INIT_DATA_.LEFT_X,
2016-08-11 23:25:56 -04:00
y = header.bottom_y,
2017-07-17 03:31:18 -04:00
spacing = _TEXT_SPACING_,
2016-08-11 23:25:56 -04:00
'Kernel',
'Uptime',
'Last Upgrade',
'Last Sync'
}
local info = Widget.TextColumn{
2017-07-16 14:50:33 -04:00
x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH,
2016-08-11 23:25:56 -04:00
y = header.bottom_y,
2017-07-17 03:31:18 -04:00
spacing = _TEXT_SPACING_,
2016-08-11 23:25:56 -04:00
x_align = 'right',
text_color = schema.blue,
2017-07-17 03:39:58 -04:00
util.conky('$kernel'),
2017-07-17 23:30:34 -04:00
'<row2>',
'<row3>',
'<row4>'
2016-08-11 23:25:56 -04:00
}
Widget = nil
schema = nil
2017-07-17 03:31:18 -04:00
_TEXT_SPACING_ = nil
2016-08-11 23:25:56 -04:00
2017-07-17 23:30:34 -04:00
local draw = function(cr, current_interface, log_is_changed)
2017-07-17 03:39:58 -04:00
TextColumn.set(info, cr, 2, util.conky('$uptime'))
2017-07-17 23:30:34 -04:00
if log_is_changed then
2017-07-17 23:33:56 -04:00
TextColumn.set(info, cr, 3, extract_date("sed -n "..
"'/ starting full system upgrade/p' /var/log/pacman.log | tail -1"))
TextColumn.set(info, cr, 4, extract_date("sed -n "..
"'/ synchronizing package lists/p' /var/log/pacman.log | tail -1"))
2017-07-17 03:39:58 -04:00
end
2016-08-11 23:25:56 -04:00
if current_interface == 0 then
Text.draw(header.text, cr)
Line.draw(header.underline, cr)
TextColumn.draw(labels, cr)
TextColumn.draw(info, cr)
end
end
return draw