conky-config/module/FileSystem.lua

119 lines
2.8 KiB
Lua
Raw Normal View History

2016-08-11 23:25:56 -04:00
local _CR = require 'CR'
local Widget = require 'Widget'
local Text = require 'Text'
local CriticalText = require 'CriticalText'
local Line = require 'Line'
local TextColumn = require 'TextColumn'
local CompoundBar = require 'CompoundBar'
local util = require 'util'
local schema = require 'default_patterns'
local _PAIRS = pairs
local _STRING_MATCH = string.match
local FS_PATHS = {'/', '/boot', '/var', '/home', '/mnt/data', '/usr/local/opt'}
local FS_NUM = #FS_PATHS
local FS_REGEX = '^([%d%p]-)(%a+)'
--construction params
2017-07-15 20:08:39 -04:00
local MODULE_Y = 165
2016-08-11 23:25:56 -04:00
local SPACING = 20
2017-07-15 20:08:39 -04:00
--~ local TEXT_WIDTH = 220
local BAR_PAD = 100
2016-08-11 23:25:56 -04:00
local header = Widget.Header{
2017-07-16 14:50:33 -04:00
x = _G_INIT_DATA_.RIGHT_X,
2017-07-15 20:08:39 -04:00
y = MODULE_Y,
2017-07-16 14:50:33 -04:00
width = _G_INIT_DATA_.SECTION_WIDTH,
2017-07-15 20:08:39 -04:00
header = 'FILE SYSTEMS'
2016-08-11 23:25:56 -04:00
}
local HEADER_BOTTOM_Y = header.bottom_y
local labels = Widget.TextColumn{
2017-07-16 14:50:33 -04:00
x = _G_INIT_DATA_.RIGHT_X,
2016-08-11 23:25:56 -04:00
y = HEADER_BOTTOM_Y,
spacing = SPACING,
'root',
'boot',
'var',
'home',
'data',
'lopt'
}
2017-07-15 20:08:39 -04:00
--~ local totals = {}
2016-08-11 23:25:56 -04:00
2017-07-15 20:08:39 -04:00
--~ for i = 1, FS_NUM do
--~ totals[i] = Widget.CriticalText{
2017-07-16 14:50:33 -04:00
--~ x = _G_INIT_DATA_.RIGHT_X + TEXT_WIDTH,
2017-07-15 20:08:39 -04:00
--~ y = HEADER_BOTTOM_Y + (i - 1) * SPACING,
--~ x_align = 'right',
--~ text_color = schema.blue,
--~ }
--~ end
2016-08-11 23:25:56 -04:00
2017-07-15 20:08:39 -04:00
--~ local units = {}
--~ local conky_used = {}
2016-08-11 23:25:56 -04:00
local conky_used_perc = {}
for i, v in _PAIRS(FS_PATHS) do
2017-07-15 20:08:39 -04:00
--~ local size, unit = _STRING_MATCH(util.conky('${fs_size '..v..'}'), FS_REGEX)
--~ totals[i].append_end = ' / '..size..' ('..unit..')'
--~ units[i] = unit
--~ conky_used[i] = '${fs_used '..v..'}'
2016-08-11 23:25:56 -04:00
conky_used_perc[i] = '${fs_used_perc '..v..'}'
end
local bars = Widget.CompoundBar{
2017-07-16 14:50:33 -04:00
--~ x = _G_INIT_DATA_.RIGHT_X + TEXT_WIDTH + BAR_PAD,
x = _G_INIT_DATA_.RIGHT_X + BAR_PAD,
2016-08-11 23:25:56 -04:00
y = HEADER_BOTTOM_Y,
2017-07-16 14:50:33 -04:00
--~ length = _G_INIT_DATA_.SECTION_WIDTH - (TEXT_WIDTH + BAR_PAD),
length = _G_INIT_DATA_.SECTION_WIDTH - BAR_PAD,
2016-08-11 23:25:56 -04:00
spacing = SPACING,
num_bars = FS_NUM,
critical_limit = '>0.8'
}
Widget = nil
_PAIRS = nil
schema = nil
SPACING = nil
TEXT_WIDTH = nil
BAR_PAD = nil
FS_PATHS = nil
HEADER_BOTTOM_Y = nil
local __update = function(cr)
for i = 1, FS_NUM do
2017-07-15 20:08:39 -04:00
--~ local value, unit = _STRING_MATCH(util.conky(conky_used[i]), FS_REGEX)
2016-08-11 23:25:56 -04:00
local percent = util.conky_numeric(conky_used_perc[i])
2017-07-15 20:08:39 -04:00
--~ local force = 1
--~ if percent > 80 then force = 0 end
--~ CriticalText.set(totals[i], cr, util.precision_convert_bytes(value, unit, units[i], 3), force)
2016-08-11 23:25:56 -04:00
CompoundBar.set(bars, i, percent * 0.01)
end
end
__update(_CR)
_CR = nil
local draw = function(cr, current_interface, trigger)
if trigger == 0 then __update(cr) end
if current_interface == 0 then
Text.draw(header.text, cr)
Line.draw(header.underline, cr)
TextColumn.draw(labels, cr)
2017-07-15 20:08:39 -04:00
--~ for i = 1, FS_NUM do
--~ CriticalText.draw(totals[i], cr)
--~ end
2016-08-11 23:25:56 -04:00
CompoundBar.draw(bars, cr)
end
end
return draw