conky-config/drawing/FileSystem.lua

122 lines
2.5 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(
2021-07-10 23:07:27 -04:00
_G_Widget_.make_point(
_G_INIT_DATA_.RIGHT_X + _BAR_PAD_,
_BAR_Y_
),
_G_INIT_DATA_.SECTION_WIDTH - _BAR_PAD_,
_G_Widget_.line_style(
12,
Patterns.INDICATOR_BG,
CAIRO_LINE_JOIN_MITER
),
2021-07-10 23:33:25 -04:00
_G_Widget_.threshold_style(
Patterns.INDICATOR_FG_PRIMARY,
Patterns.INDICATOR_FG_CRITICAL,
0.8
),
2021-07-10 23:07:27 -04:00
_SPACING_,
FS_NUM,
2021-07-10 23:33:25 -04:00
false
)
2017-07-19 00:36:15 -04:00
2021-07-09 22:22:49 -04:00
local labels = _G_Widget_.TextColumn(
2021-07-09 23:53:21 -04:00
_G_Widget_.make_point(
_G_INIT_DATA_.RIGHT_X,
_BAR_Y_
),
2021-07-10 17:13:17 -04:00
{'root', 'boot', 'home', 'data', 'dcache', 'tmpfs'},
_G_Widget_.text_style(
Common.normal_font_spec,
_G_Patterns_.INACTIVE_TEXT_FG,
'left',
'center'
2021-07-10 17:13:17 -04:00
),
nil,
2021-07-10 17:13:17 -04:00
_SPACING_
2021-07-09 22:22:49 -04:00
)
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