clean up System.lua

This commit is contained in:
petrucci4prez 2017-07-17 03:31:18 -04:00
parent abe52a3ab2
commit b25c5dfc31
1 changed files with 13 additions and 14 deletions

View File

@ -6,27 +6,26 @@ local TextColumn = require 'TextColumn'
local util = require 'util' local util = require 'util'
local schema = require 'default_patterns' local schema = require 'default_patterns'
local _STRING_MATCH = string.match local __string_match = string.match
local DATE_REGEX = '%[(%d-)%-(%d-%-%d-)%s' local DATE_REGEX = '%[(%d-)%-(%d-%-%d-)%s'
local UPGRADE_CMD = "sed -n '/ starting full system upgrade/p' /var/log/pacman.log | tail -1" local UPGRADE_CMD = "sed -n '/ starting full system upgrade/p' /var/log/pacman.log | tail -1"
local SYNC_CMD = "sed -n '/ synchronizing package lists/p' /var/log/pacman.log | tail -1" local SYNC_CMD = "sed -n '/ synchronizing package lists/p' /var/log/pacman.log | tail -1"
--construction params local _TEXT_SPACING_ = 20
local TEXT_SPACING = 20
local header = Widget.Header{ local header = Widget.Header{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = _G_INIT_DATA_.TOP_Y, y = _G_INIT_DATA_.TOP_Y,
width = _G_INIT_DATA_.SECTION_WIDTH, width = _G_INIT_DATA_.SECTION_WIDTH,
header = "SYSTEM" header = 'SYSTEM'
} }
local labels = Widget.TextColumn{ local labels = Widget.TextColumn{
x = _G_INIT_DATA_.LEFT_X, x = _G_INIT_DATA_.LEFT_X,
y = header.bottom_y, y = header.bottom_y,
spacing = TEXT_SPACING, spacing = _TEXT_SPACING_,
'Kernel', 'Kernel',
'Uptime', 'Uptime',
'Last Upgrade', 'Last Upgrade',
@ -35,7 +34,7 @@ local labels = Widget.TextColumn{
local info = Widget.TextColumn{ local info = Widget.TextColumn{
x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH, x = _G_INIT_DATA_.LEFT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = header.bottom_y, y = header.bottom_y,
spacing = TEXT_SPACING, spacing = _TEXT_SPACING_,
x_align = 'right', x_align = 'right',
text_color = schema.blue, text_color = schema.blue,
num_rows = 4, num_rows = 4,
@ -43,28 +42,28 @@ local info = Widget.TextColumn{
TextColumn.set(info, _CR, 1, util.conky('$kernel')) TextColumn.set(info, _CR, 1, util.conky('$kernel'))
local __update_dates = function(cr) local update_dates = function(cr)
local yyyy, mm_dd = _STRING_MATCH(util.execute_cmd(UPGRADE_CMD), DATE_REGEX) local yyyy, mm_dd = __string_match(util.execute_cmd(UPGRADE_CMD), DATE_REGEX)
TextColumn.set(info, cr, 3, mm_dd..'-'..yyyy) TextColumn.set(info, cr, 3, mm_dd..'-'..yyyy)
yyyy, mm_dd = _STRING_MATCH(util.execute_cmd(SYNC_CMD), DATE_REGEX) yyyy, mm_dd = __string_match(util.execute_cmd(SYNC_CMD), DATE_REGEX)
TextColumn.set(info, cr, 4, mm_dd..'-'..yyyy) TextColumn.set(info, cr, 4, mm_dd..'-'..yyyy)
end end
local __update_uptime = function(cr) local update_uptime = function(cr)
TextColumn.set(info, cr, 2, util.conky('$uptime')) TextColumn.set(info, cr, 2, util.conky('$uptime'))
end end
__update_dates(_CR) update_dates(_CR)
Widget = nil Widget = nil
schema = nil schema = nil
TEXT_SPACING = nil _TEXT_SPACING_ = nil
_CR = nil _CR = nil
local draw = function(cr, current_interface, trigger) local draw = function(cr, current_interface, trigger)
__update_uptime(cr) update_uptime(cr)
if trigger == 0 then __update_dates(cr) end if trigger == 0 then update_dates(cr) end
if current_interface == 0 then if current_interface == 0 then
Text.draw(header.text, cr) Text.draw(header.text, cr)