conky-config/drawing/FileSystem.lua

112 lines
2.4 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 Line = require 'Line'
local TextColumn = require 'TextColumn'
local CompoundBar = require 'CompoundBar'
local Util = require 'Util'
local Common = require 'Common'
2017-07-19 00:36:15 -04:00
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 = Common.Header(
_G_INIT_DATA_.RIGHT_X,
_MODULE_Y_,
_G_INIT_DATA_.SECTION_WIDTH,
'FILE SYSTEMS'
)
2017-07-19 00:36:15 -04:00
local conky_used_perc = {}
for i, v in pairs(_FS_PATHS_) do
conky_used_perc[i] = '${fs_used_perc '..v..'}'
end
local smart = Common.initTextRow(
_G_INIT_DATA_.RIGHT_X,
header.bottom_y,
_G_INIT_DATA_.SECTION_WIDTH,
'SMART Daemon'
)
2021-02-02 18:21:32 -05:00
local _SEP_Y_ = header.bottom_y + _SEPARATOR_SPACING_
local separator = Common.initSeparator(
_G_INIT_DATA_.RIGHT_X,
_SEP_Y_,
_G_INIT_DATA_.SECTION_WIDTH
)
2021-02-02 18:21:32 -05:00
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,
critical_limit = 0.8,
indicator_pattern = Patterns.INDICATOR_FG_PRIMARY,
2021-07-06 18:56:24 -04:00
critical_pattern = Patterns.INDICATOR_FG_CRITICAL,
line_pattern = Patterns.INDICATOR_BG,
2017-07-19 00:36:15 -04:00
}
2021-02-02 18:21:32 -05:00
local labels = _G_Widget_.TextColumn{
x = _G_INIT_DATA_.RIGHT_X,
y = _BAR_Y_,
spacing = _SPACING_,
text_color = _G_Patterns_.INACTIVE_TEXT_FG,
2021-07-06 00:11:00 -04:00
font_spec = Common.normal_font_spec,
2021-02-02 18:21:32 -05:00
'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')
Common.text_row_set(smart, cr, (smart_pid == '') and 'Error' or 'Running')
2021-02-02 18:21:32 -05:00
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
2021-07-06 00:11:00 -04:00
M.draw_static = function(cr)
Common.drawHeader(cr, header)
Common.text_row_draw_static(smart, cr)
2021-02-02 18:21:32 -05:00
Line.draw(separator, cr)
TextColumn.draw(labels, cr)
CompoundBar.draw_static(bars, cr)
end
2021-07-06 00:11:00 -04:00
M.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
Common.text_row_draw_dynamic(smart, cr)
2021-02-02 18:21:32 -05:00
CompoundBar.draw_dynamic(bars, cr)
2017-07-19 00:36:15 -04:00
end
return M