REF make filesytem module pretty

This commit is contained in:
Nathan Dwarshuis 2021-07-17 23:12:59 -04:00
parent f7a145cae6
commit d4a29b362f
1 changed files with 85 additions and 82 deletions

View File

@ -3,85 +3,88 @@ local Util = require 'Util'
local Common = require 'Common' local Common = require 'Common'
local Geometry = require 'Geometry' local Geometry = require 'Geometry'
local _FS_PATHS_ = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"} return function()
local _MODULE_Y_ = 170 local FS_PATHS = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"}
local _SPACING_ = 20 local MODULE_Y = 170
local _BAR_PAD_ = 100 local SPACING = 20
local _SEPARATOR_SPACING_ = 20 local BAR_PAD = 100
local SEPARATOR_SPACING = 20
local FS_NUM = #_FS_PATHS_ -----------------------------------------------------------------------------
-- header
local header = Common.Header( local header = Common.Header(
Geometry.RIGHT_X, Geometry.RIGHT_X,
_MODULE_Y_, MODULE_Y,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
'FILE SYSTEMS' 'FILE SYSTEMS'
) )
local conky_used_perc = {} -----------------------------------------------------------------------------
-- smartd
for i, v in pairs(_FS_PATHS_) do local smart = Common.initTextRow(
conky_used_perc[i] = '${fs_used_perc '..v..'}'
end
local smart = Common.initTextRow(
Geometry.RIGHT_X, Geometry.RIGHT_X,
header.bottom_y, header.bottom_y,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
'SMART Daemon' 'SMART Daemon'
) )
local _SEP_Y_ = header.bottom_y + _SEPARATOR_SPACING_ local SEP_Y = header.bottom_y + SEPARATOR_SPACING
local separator = Common.initSeparator( local separator = Common.initSeparator(
Geometry.RIGHT_X, Geometry.RIGHT_X,
_SEP_Y_, SEP_Y,
Geometry.SECTION_WIDTH Geometry.SECTION_WIDTH
) )
local _BAR_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_ -----------------------------------------------------------------------------
-- filesystem bar chart
local fs = Common.compound_bar( local BAR_Y = SEP_Y + SEPARATOR_SPACING
local fs = Common.compound_bar(
Geometry.RIGHT_X, Geometry.RIGHT_X,
_BAR_Y_, BAR_Y,
Geometry.SECTION_WIDTH, Geometry.SECTION_WIDTH,
_BAR_PAD_, BAR_PAD,
{'root', 'boot', 'home', 'data', 'dcache', 'tmpfs'}, {'root', 'boot', 'home', 'data', 'dcache', 'tmpfs'},
_SPACING_, SPACING,
12, 12,
0.8 0.8
) )
_SPACING_ = nil local FS_NUM = #FS_PATHS
_BAR_PAD_ = nil local CONKY_USED_PERC = {}
_FS_PATHS_ = nil for i, v in pairs(FS_PATHS) do
_SEPARATOR_SPACING_ = nil CONKY_USED_PERC[i] = '${fs_used_perc '..v..'}'
_BAR_Y_ = nil end
_SEP_Y_ = nil
local update = function(cr) -----------------------------------------------------------------------------
-- main functions
local update = function(cr)
local smart_pid = Util.execute_cmd('pidof smartd', nil, '*n') local smart_pid = Util.execute_cmd('pidof smartd', nil, '*n')
Common.text_row_set(smart, cr, (smart_pid == '') and 'Error' or 'Running') Common.text_row_set(smart, cr, (smart_pid == '') and 'Error' or 'Running')
for i = 1, FS_NUM do for i = 1, FS_NUM do
local percent = Util.conky_numeric(conky_used_perc[i]) local percent = Util.conky_numeric(CONKY_USED_PERC[i])
Common.compound_bar_set(fs, i, percent * 0.01) Common.compound_bar_set(fs, i, percent * 0.01)
end end
end end
local draw_static = function(cr) local draw_static = function(cr)
Common.drawHeader(cr, header) Common.drawHeader(cr, header)
Common.text_row_draw_static(smart, cr) Common.text_row_draw_static(smart, cr)
Line.draw(separator, cr) Line.draw(separator, cr)
Common.compound_bar_draw_static(fs, cr) Common.compound_bar_draw_static(fs, cr)
end end
local draw_dynamic = function(cr, trigger) local draw_dynamic = function(cr, trigger)
if trigger == 0 then update(cr) end if trigger == 0 then update(cr) end
Common.text_row_draw_dynamic(smart, cr) Common.text_row_draw_dynamic(smart, cr)
Common.compound_bar_draw_dynamic(fs, cr) Common.compound_bar_draw_dynamic(fs, cr)
end end
return function()
return {static = draw_static, dynamic = draw_dynamic} return {static = draw_static, dynamic = draw_dynamic}
end end