conky-config/drawing/filesystem.lua

100 lines
2.6 KiB
Lua
Raw Normal View History

2021-08-08 15:58:53 -04:00
local i_o = require 'i_o'
local common = require 'common'
local geometry = require 'geometry'
2021-08-08 19:12:31 -04:00
local pure = require 'pure'
local impure = require 'impure'
2017-07-19 00:36:15 -04:00
return function(pathspecs, point)
2021-07-17 23:12:59 -04:00
local SPACING = 20
local BAR_PAD = 100
local SEPARATOR_SPACING = 20
-----------------------------------------------------------------------------
-- header
2022-07-14 18:20:08 -04:00
local mk_header = pure.partial(
common.mk_header,
'FILE SYSTEMS',
geometry.SECTION_WIDTH,
point.x
2021-07-17 23:12:59 -04:00
)
-----------------------------------------------------------------------------
-- smartd
2022-07-14 18:20:08 -04:00
local mk_smart = function(y)
local obj = common.make_text_row(
point.x,
2022-07-14 18:20:08 -04:00
y,
geometry.SECTION_WIDTH,
'SMART Daemon'
)
local update = function(trigger)
if trigger == 0 then
local pid = i_o.execute_cmd('pidof smartd', nil, '*n')
common.text_row_set(obj, (pid == '') and 'Error' or 'Running')
end
end
return common.mk_acc(
0,
update,
pure.partial(common.text_row_draw_static, obj),
pure.partial(common.text_row_draw_dynamic, obj)
)
end
2021-07-17 23:12:59 -04:00
2022-07-14 18:20:08 -04:00
local mk_sep = pure.partial(
common.mk_seperator,
geometry.SECTION_WIDTH,
point.x
2021-07-17 23:12:59 -04:00
)
-----------------------------------------------------------------------------
-- filesystem bar chart
2022-07-14 18:20:08 -04:00
local mk_bars = function(y)
local paths, names = table.unpack(pure.unzip(pathspecs))
local CONKY_CMDS = pure.map(
pure.partial(string.format, '${fs_used_perc %s}', true),
paths
)
local obj = common.make_compound_bar(
point.x,
2022-07-14 18:20:08 -04:00
y,
geometry.SECTION_WIDTH,
BAR_PAD,
names,
SPACING,
12,
80
)
local read_fs = function(index, cmd)
common.compound_bar_set(obj, index, i_o.conky_numeric(cmd))
end
local update = function(trigger)
if trigger == 0 then
impure.ieach(read_fs, CONKY_CMDS)
end
end
return common.mk_acc(
(#pathspecs - 1) * SPACING,
update,
pure.partial(common.compound_bar_draw_static, obj),
pure.partial(common.compound_bar_draw_dynamic, obj)
)
2021-07-17 23:12:59 -04:00
end
2017-07-19 00:36:15 -04:00
2021-07-17 23:12:59 -04:00
-----------------------------------------------------------------------------
-- main functions
2017-07-19 00:36:15 -04:00
return common.reduce_blocks_(
point.y,
2022-07-14 18:20:08 -04:00
{
common.mk_block(mk_header, true, 0),
common.mk_block(mk_smart, true, 0),
common.mk_block(mk_sep, true, SEPARATOR_SPACING),
common.mk_block(mk_bars, true, SEPARATOR_SPACING),
}
)
end