REF make system module use setup framework

This commit is contained in:
Nathan Dwarshuis 2022-07-14 20:20:27 -04:00
parent 3f6047d05d
commit e9d6a0eeee
1 changed files with 33 additions and 31 deletions

View File

@ -1,4 +1,5 @@
local i_o = require 'i_o' local i_o = require 'i_o'
local pure = require 'pure'
local common = require 'common' local common = require 'common'
local geometry = require 'geometry' local geometry = require 'geometry'
@ -7,41 +8,42 @@ return function(point)
local __string_match = string.match local __string_match = string.match
local header = common.make_header( local mk_header = pure.partial(
point.x, common.mk_header,
point.y, 'SYSTEM',
geometry.SECTION_WIDTH, geometry.SECTION_WIDTH,
'SYSTEM' point.x
) )
local rows = common.make_text_rows( local mk_stats = function(y)
local obj = common.make_text_rows(
point.x, point.x,
header.bottom_y, y,
geometry.SECTION_WIDTH, geometry.SECTION_WIDTH,
TEXT_SPACING, TEXT_SPACING,
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'} {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
) )
local update = function(pacman_stats) local update = function(pacman_stats)
local last_update, last_sync = "N/A", "N/A" local last_update, last_sync
if pacman_stats then if pacman_stats then
last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*") last_update, last_sync = __string_match(pacman_stats, "^%d+%s+([^%s]+)%s+([^%s]+).*")
end end
-- TODO this doesn't need to be update every time -- TODO this doesn't need to be update every time
common.text_rows_set(rows, 1, i_o.conky('$kernel')) common.text_rows_set(obj, 1, i_o.conky('$kernel'))
common.text_rows_set(rows, 2, i_o.conky('$uptime')) common.text_rows_set(obj, 2, i_o.conky('$uptime'))
common.text_rows_set(rows, 3, last_update) common.text_rows_set(obj, 3, last_update)
common.text_rows_set(rows, 4, last_sync) common.text_rows_set(obj, 4, last_sync)
end
local static = pure.partial(common.text_rows_draw_static, obj)
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
return common.mk_acc(TEXT_SPACING * 3, update, static, dynamic)
end end
local draw_static = function(cr) return common.reduce_blocks_(
common.draw_header(cr, header) point.y,
common.text_rows_draw_static(rows, cr) {
end common.mk_block(mk_header, true, 0),
common.mk_block(mk_stats, true, 0),
local draw_dynamic = function(cr) }
common.text_rows_draw_dynamic(rows, cr) )
end
return {static = draw_static, dynamic = draw_dynamic, update = update}
end end