conky-config/drawing/FileSystem.lua

126 lines
2.7 KiB
Lua
Raw Normal View History

local M = {}
2021-02-02 18:21:32 -05:00
local Patterns = require 'Patterns'
2017-07-19 00:36:15 -04:00
local Text = require 'Text'
local Line = require 'Line'
local TextColumn = require 'TextColumn'
local CompoundBar = require 'CompoundBar'
local Util = require 'Util'
2017-07-19 00:36:15 -04:00
local __string_match = string.match
2021-05-12 12:54:58 -04:00
local _FS_PATHS_ = {'/', '/boot', '/home', '/mnt/data', '/mnt/dcache', "/tmp"}
2018-08-05 18:04:22 -04:00
local _MODULE_Y_ = 170
2021-02-01 03:02:52 -05:00
local _SPACING_ = 20
2017-07-19 00:36:15 -04:00
local _BAR_PAD_ = 100
2021-02-02 18:21:32 -05:00
local _SEPARATOR_SPACING_ = 20
2017-07-19 00:36:15 -04:00
local FS_NUM = #_FS_PATHS_
local header = _G_Widget_.Header{
2017-07-19 00:36:15 -04:00
x = _G_INIT_DATA_.RIGHT_X,
y = _MODULE_Y_,
width = _G_INIT_DATA_.SECTION_WIDTH,
header = 'FILE SYSTEMS'
}
local conky_used_perc = {}
for i, v in pairs(_FS_PATHS_) do
conky_used_perc[i] = '${fs_used_perc '..v..'}'
end
2021-02-02 18:21:32 -05:00
local smart = {
label = _G_Widget_.Text{
x = _G_INIT_DATA_.RIGHT_X,
y = header.bottom_y,
text = 'SMART Daemon'
},
value = _G_Widget_.Text{
x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = header.bottom_y,
x_align = 'right',
2021-07-04 19:50:55 -04:00
text_color = Patterns.PRIMARY_FG,
2021-02-02 18:21:32 -05:00
text = '<smartd>',
}
}
local _SEP_Y_ = header.bottom_y + _SEPARATOR_SPACING_
local separator = _G_Widget_.Line{
p1 = {
x = _G_INIT_DATA_.RIGHT_X,
y = _SEP_Y_,
},
p2 = {
x = _G_INIT_DATA_.RIGHT_X + _G_INIT_DATA_.SECTION_WIDTH,
y = _SEP_Y_,
}
}
local _BAR_Y_ = _SEP_Y_ + _SEPARATOR_SPACING_
local bars = _G_Widget_.CompoundBar{
2017-07-19 00:36:15 -04:00
x = _G_INIT_DATA_.RIGHT_X + _BAR_PAD_,
2021-02-02 18:21:32 -05:00
y = _BAR_Y_,
2017-07-19 00:36:15 -04:00
length = _G_INIT_DATA_.SECTION_WIDTH - _BAR_PAD_,
spacing = _SPACING_,
num_bars = FS_NUM,
2021-02-01 03:02:52 -05:00
-- thickness = 12,
2017-07-19 00:36:15 -04:00
critical_limit = '>0.8'
}
2021-02-02 18:21:32 -05:00
local labels = _G_Widget_.TextColumn{
x = _G_INIT_DATA_.RIGHT_X,
y = _BAR_Y_,
spacing = _SPACING_,
'root',
'boot',
'home',
'data',
'dcache',
2021-05-12 12:54:58 -04:00
'tmpfs',
2021-02-02 18:21:32 -05:00
}
2017-07-19 00:36:15 -04:00
_SPACING_ = nil
_BAR_PAD_ = nil
_FS_PATHS_ = nil
2021-02-02 18:21:32 -05:00
_SEPARATOR_SPACING_ = nil
_BAR_Y_ = nil
_SEPARATOR_SPACING_ = nil
_SEP_Y_ = nil
2017-07-19 00:36:15 -04:00
local update = function(cr)
2021-02-02 18:21:32 -05:00
local smart_pid = Util.execute_cmd('pidof smartd', nil, '*n')
Text.set(smart.value, cr, (smart_pid == '') and 'Error' or 'Running')
for i = 1, FS_NUM do
local percent = Util.conky_numeric(conky_used_perc[i])
CompoundBar.set(bars, i, percent * 0.01)
end
2017-07-19 00:36:15 -04:00
end
local draw_static = function(cr)
Text.draw(header.text, cr)
Line.draw(header.underline, cr)
2021-02-02 18:21:32 -05:00
Text.draw(smart.label, cr)
Line.draw(separator, cr)
TextColumn.draw(labels, cr)
CompoundBar.draw_static(bars, cr)
end
local draw_dynamic = function(cr, trigger)
2018-08-05 11:08:37 -04:00
if trigger == 0 then update(cr) end
2017-07-19 00:36:15 -04:00
2021-02-02 18:21:32 -05:00
Text.draw(smart.value, cr)
CompoundBar.draw_dynamic(bars, cr)
2017-07-19 00:36:15 -04:00
end
M.draw_static = draw_static
M.draw_dynamic = draw_dynamic
return M