ENH put rest of configurable options in yaml file

This commit is contained in:
Nathan Dwarshuis 2022-07-19 00:54:46 -04:00
parent efa4319acd
commit bdca0c6511
7 changed files with 436 additions and 356 deletions

View File

@ -58,6 +58,18 @@ theme:
plot_label: 8 plot_label: 8
table: 11 table: 11
header: 15 header: 15
geometry:
plot:
seconds: 90
ticks: [9, 4]
table:
name_chars: 8
padding: [6, 15]
header_padding: 20
row_spacing: 13
header:
underline_offset: 26
padding: 19
patterns: patterns:
header: 0xefefef header: 0xefefef
panel: panel:

View File

@ -1,7 +1,6 @@
local geom = require 'geom' local geom = require 'geom'
local format = require 'format' local format = require 'format'
local color = require 'color' local color = require 'color'
-- local theme = require 'theme'
local dial = require 'dial' local dial = require 'dial'
local rect = require 'rect' local rect = require 'rect'
local fill_rect = require 'fill_rect' local fill_rect = require 'fill_rect'
@ -22,6 +21,7 @@ local pure = require 'pure'
local compile_patterns local compile_patterns
-- TODO move to color module
compile_patterns = function(patterns) compile_patterns = function(patterns)
local r = {} local r = {}
for k, v in pairs(patterns) do for k, v in pairs(patterns) do
@ -59,27 +59,24 @@ return function(config)
local font = config.theme.font local font = config.theme.font
local font_sizes = font.sizes local font_sizes = font.sizes
local font_family = font.family local font_family = font.family
local geometry = config.theme.geometry
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- constants -- constants
local HEADER_HEIGHT = 45 local CAP_ROUND = CAIRO_LINE_CAP_ROUND
local HEADER_UNDERLINE_CAP = CAIRO_LINE_CAP_ROUND local CAP_BUTT = CAIRO_LINE_CAP_BUTT
local HEADER_UNDERLINE_OFFSET = 26 local JOIN_MITER = CAIRO_LINE_JOIN_MITER
local FONT_BOLD = CAIRO_FONT_WEIGHT_BOLD
local FONT_NORMAL = CAIRO_FONT_WEIGHT_NORMAL
local HEADER_UNDERLINE_CAP = CAP_ROUND
local HEADER_UNDERLINE_THICKNESS = 3 local HEADER_UNDERLINE_THICKNESS = 3
local SEPARATOR_THICKNESS = 1 local SEPARATOR_THICKNESS = 1
local TABLE_BODY_FORMAT = 8
local TABLE_VERT_PAD = 15
local TABLE_HORZ_PAD = 5
local TABLE_HEADER_PAD = 20
local TABLE_LINE_THICKNESS = 1 local TABLE_LINE_THICKNESS = 1
local PLOT_NUM_POINTS = 90
local PLOT_GRID_X_N = 9
local PLOT_GRID_Y_N = 4
local ARC_WIDTH = 2 local ARC_WIDTH = 2
local DIAL_THETA0 = 90 local DIAL_THETA0 = 90
@ -99,16 +96,16 @@ return function(config)
return { return {
family = f, family = f,
size = size, size = size,
weight = bold and CAIRO_font_family_WEIGHT_BOLD or CAIRO_font_family_WEIGHT_NORMAL, weight = bold and FONT_BOLD or FONT_NORMAL,
slant = CAIRO_font_family_WEIGHT_NORMAL, slant = FONT_NORMAL,
} }
end end
local normal_font_spec = make_font_spec(font_family, font_sizes.normal, false) local normal_font_spec = make_font_spec(font_family, font_sizes.normal, false)
local label_font_spec = make_font_spec(font_family, font_sizes.plot_label, false) local label_font_spec = make_font_spec(font_family, font_sizes.plot_label, false)
local _text_row_style = function(x_align, color) local _text_row_style = function(x_align, _color)
return text.config(normal_font_spec, color, x_align, 'center') return text.config(normal_font_spec, _color, x_align, 'center')
end end
local _left_text_style = _text_row_style('left', patterns.text.inactive) local _left_text_style = _text_row_style('left', patterns.text.inactive)
@ -130,13 +127,13 @@ return function(config)
-- timeseries helper functions -- timeseries helper functions
local _default_grid_config = timeseries.grid_config( local _default_grid_config = timeseries.grid_config(
PLOT_GRID_X_N, geometry.plot.ticks[1],
PLOT_GRID_Y_N, geometry.plot.ticks[2],
patterns.plot.grid patterns.plot.grid
) )
local _default_plot_config = timeseries.config( local _default_plot_config = timeseries.config(
PLOT_NUM_POINTS, geometry.plot.seconds,
patterns.plot.outline, patterns.plot.outline,
patterns.plot.data.border, patterns.plot.data.border,
patterns.plot.data.fill, patterns.plot.data.fill,
@ -144,7 +141,7 @@ return function(config)
) )
local _format_percent_label = function(_) local _format_percent_label = function(_)
return function(z) return string.format('%i%%', z * 100) end return function(z) return string.format('%i%%', math.floor(z * 100)) end
end end
local _format_percent_maybe = function(z) local _format_percent_maybe = function(z)
@ -207,8 +204,8 @@ return function(config)
-- header -- header
M.make_header = function(x, y, w, _text) M.make_header = function(x, y, w, _text)
local bottom_y = y + HEADER_HEIGHT local underline_y = y + geometry.header.underline_offset
local underline_y = y + HEADER_UNDERLINE_OFFSET local bottom_y = underline_y + geometry.header.padding
return { return {
text = text.make_plain( text = text.make_plain(
geom.make_point(x, y), geom.make_point(x, y),
@ -329,7 +326,15 @@ return function(config)
_right_text_style, _right_text_style,
format_fun format_fun
), ),
plot = _make_scaled_timeseries(x, y + spacing, w, h, label_fun, min_domain, update_freq), plot = _make_scaled_timeseries(
x,
y + spacing,
w,
h,
label_fun,
min_domain,
update_freq
),
} }
end end
@ -371,7 +376,15 @@ return function(config)
_right_text_style, _right_text_style,
format_fun format_fun
), ),
plot = _make_scaled_timeseries(x, y + spacing, w, h, label_fun, min_domain, update_freq), plot = _make_scaled_timeseries(
x,
y + spacing,
w,
h,
label_fun,
min_domain,
update_freq
),
prev_value = init, prev_value = init,
derive = make_differential(update_freq), derive = make_differential(update_freq),
} }
@ -390,7 +403,7 @@ return function(config)
M.make_circle = function(x, y, r) M.make_circle = function(x, y, r)
return circle.make( return circle.make(
geom.make_circle(x, y, r), geom.make_circle(x, y, r),
circle.config(style.line(ARC_WIDTH, CAIRO_LINE_CAP_BUTT), patterns.border) circle.config(style.line(ARC_WIDTH, CAP_BUTT), patterns.border)
) )
end end
@ -437,7 +450,7 @@ return function(config)
return { return {
dial = dial.make( dial = dial.make(
geom.make_arc(x, y, radius, DIAL_THETA0, DIAL_THETA1), geom.make_arc(x, y, radius, DIAL_THETA0, DIAL_THETA1),
arc.config(style.line(thickness, CAIRO_LINE_CAP_BUTT), patterns.indicator.bg), arc.config(style.line(thickness, CAP_BUTT), patterns.indicator.bg),
threshold_indicator(threshold) threshold_indicator(threshold)
), ),
text_circle = M.make_text_circle(x, y, radius - thickness / 2 - 2, _format, threshold, pre_function), text_circle = M.make_text_circle(x, y, radius - thickness / 2 - 2, _format, threshold, pre_function),
@ -466,7 +479,7 @@ return function(config)
threshold, num_dials) threshold, num_dials)
return compound_dial.make( return compound_dial.make(
geom.make_arc(x, y, outer_radius, DIAL_THETA0, DIAL_THETA1), geom.make_arc(x, y, outer_radius, DIAL_THETA0, DIAL_THETA1),
arc.config(style.line(thickness, CAIRO_LINE_CAP_BUTT), patterns.indicator.bg), arc.config(style.line(thickness, CAP_BUTT), patterns.indicator.bg),
threshold_indicator(threshold), threshold_indicator(threshold),
inner_radius, inner_radius,
num_dials num_dials
@ -489,7 +502,7 @@ return function(config)
geom.make_point(x + pad, y), geom.make_point(x + pad, y),
w - pad, w - pad,
line.config( line.config(
style.line(thickness, CAIRO_LINE_CAP_BUTT), style.line(thickness, CAP_BUTT),
patterns.indicator.bg, patterns.indicator.bg,
true true
), ),
@ -521,7 +534,7 @@ return function(config)
return line.make( return line.make(
_make_horizontal_line(x, y, w), _make_horizontal_line(x, y, w),
line.config( line.config(
style.line(SEPARATOR_THICKNESS, CAIRO_LINE_CAP_BUTT), style.line(SEPARATOR_THICKNESS, CAP_BUTT),
patterns.border, patterns.border,
true true
) )
@ -579,7 +592,7 @@ return function(config)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- multiple text row separated by spacing -- multiple text row separated by spacing
M.make_text_rows_formatted = function(x, y, w, spacing, labels, format) M.make_text_rows_formatted = function(x, y, w, spacing, labels, _format)
return { return {
labels = text_column.make( labels = text_column.make(
geom.make_point(x, y), geom.make_point(x, y),
@ -592,7 +605,7 @@ return function(config)
geom.make_point(x + w, y), geom.make_point(x + w, y),
#labels, #labels,
_right_text_style, _right_text_style,
format, _format,
spacing, spacing,
0 0
) )
@ -625,43 +638,50 @@ return function(config)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- table -- table
local gtable = geometry.table
local padding = gtable.padding
local xpad = padding[1]
local ypad = padding[2]
local default_table_font_spec = make_font_spec(font_family, font_sizes.table, false) local default_table_font_spec = make_font_spec(font_family, font_sizes.table, false)
local col_fmt = gtable.name_chars > 0 and gtable.name_chars
local default_table_config = function(label) local default_table_config = function(label)
return tbl.config( return tbl.config(
rect.config( rect.config(
style.closed_poly(TABLE_LINE_THICKNESS, CAIRO_LINE_JOIN_MITER), style.closed_poly(TABLE_LINE_THICKNESS, JOIN_MITER),
patterns.border patterns.border
), ),
line.config( line.config(
style.line(TABLE_LINE_THICKNESS, CAIRO_LINE_CAP_BUTT), style.line(TABLE_LINE_THICKNESS, CAP_BUTT),
patterns.border, patterns.border,
true true
), ),
tbl.header_config( tbl.header_config(
default_table_font_spec, default_table_font_spec,
patterns.text.active, patterns.text.active,
TABLE_HEADER_PAD gtable.header_padding
), ),
tbl.body_config( tbl.body_config(
default_table_font_spec, default_table_font_spec,
patterns.text.inactive, patterns.text.inactive,
{ {
tbl.column_config('Name', TABLE_BODY_FORMAT), tbl.column_config('Name', col_fmt),
tbl.column_config('PID', false), tbl.column_config('PID', false),
tbl.column_config(label, false), tbl.column_config(label, false),
} }
), ),
tbl.padding( tbl.padding(xpad, ypad, xpad, ypad)
TABLE_HORZ_PAD,
TABLE_VERT_PAD,
TABLE_HORZ_PAD,
TABLE_VERT_PAD
)
) )
end end
M.make_text_table = function(x, y, w, h, n, label) M.table_height = function(n)
return ypad * 2 + gtable.header_padding + gtable.row_spacing * n
end
M.make_text_table = function(x, y, w, n, label)
local h = M.table_height(n)
return tbl.make( return tbl.make(
geom.make_box(x, y, w, h), geom.make_box(x, y, w, h),
n, n,
@ -669,10 +689,6 @@ return function(config)
) )
end end
M.table_height = function(n)
return TABLE_VERT_PAD * 2 + TABLE_HEADER_PAD + 13 * n
end
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- panel -- panel
@ -680,14 +696,13 @@ return function(config)
return fill_rect.make( return fill_rect.make(
geom.make_box(x, y, w, h), geom.make_box(x, y, w, h),
rect.config( rect.config(
style.closed_poly(thickness, CAIRO_LINE_JOIN_MITER), style.closed_poly(thickness, JOIN_MITER),
patterns.border patterns.border
), ),
patterns.panel.bg patterns.panel.bg
) )
end end
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- compile individual module -- compile individual module

View File

@ -179,7 +179,6 @@ return function(update_freq, config, common, width, point)
local mk_tbl = function(y) local mk_tbl = function(y)
local num_rows = config.table_rows local num_rows = config.table_rows
local table_height = common.table_height(num_rows)
local table_conky = pure.map_n( local table_conky = pure.map_n(
function(i) function(i)
return { return {
@ -193,7 +192,6 @@ return function(update_freq, config, common, width, point)
point.x, point.x,
y, y,
width, width,
table_height,
num_rows, num_rows,
'Mem (%)' 'Mem (%)'
) )
@ -206,7 +204,7 @@ return function(update_freq, config, common, width, point)
end end
return common.mk_acc( return common.mk_acc(
width, width,
table_height, common.table_height(num_rows),
update, update,
pure.partial(text_table.draw_static, obj), pure.partial(text_table.draw_static, obj),
pure.partial(text_table.draw_dynamic, obj) pure.partial(text_table.draw_dynamic, obj)

View File

@ -112,8 +112,7 @@ return function(update_freq, config, common, width, point)
set_state = nil, set_state = nil,
top = pure.concat( top = pure.concat(
pure.map(mk_rate_blockspec, config.rapl_specs), pure.map(mk_rate_blockspec, config.rapl_specs),
-- TODO what happens if this is nil? {{mk_bat, config.battery ~= '', 0}}
{{mk_bat, config.battery ~= nil, 0}}
) )
} }
end end

View File

@ -193,7 +193,6 @@ return function(update_freq, config, main_state, common, width, point)
local mk_tbl = function(y) local mk_tbl = function(y)
local num_rows = config.table_rows local num_rows = config.table_rows
local table_height = common.table_height(num_rows)
local table_conky = pure.map_n( local table_conky = pure.map_n(
function(i) return {pid = '${top pid '..i..'}', cpu = '${top cpu '..i..'}'} end, function(i) return {pid = '${top pid '..i..'}', cpu = '${top cpu '..i..'}'} end,
num_rows num_rows
@ -202,7 +201,6 @@ return function(update_freq, config, main_state, common, width, point)
point.x, point.x,
y, y,
width, width,
table_height,
num_rows, num_rows,
'CPU (%)' 'CPU (%)'
) )
@ -218,7 +216,7 @@ return function(update_freq, config, main_state, common, width, point)
end end
return common.mk_acc( return common.mk_acc(
width, width,
table_height, common.table_height(num_rows),
update, update,
pure.partial(text_table.draw_static, tbl), pure.partial(text_table.draw_static, tbl),
pure.partial(text_table.draw_dynamic, tbl) pure.partial(text_table.draw_dynamic, tbl)

View File

@ -14,6 +14,8 @@ return function(main_state, common, width, point)
TEXT_SPACING, TEXT_SPACING,
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'} {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
) )
-- just update this once
common.text_rows_set(obj, 1, i_o.conky('$kernel'))
local update = function() local update = function()
local last_update, last_sync local last_update, last_sync
if main_state.pacman_stats then if main_state.pacman_stats then
@ -22,8 +24,6 @@ return function(main_state, common, width, point)
"^%d+%s+([^%s]+)%s+([^%s]+).*" "^%d+%s+([^%s]+)%s+([^%s]+).*"
) )
end end
-- TODO this doesn't need to be updated every time
common.text_rows_set(obj, 1, i_o.conky('$kernel'))
common.text_rows_set(obj, 2, i_o.conky('$uptime')) common.text_rows_set(obj, 2, i_o.conky('$uptime'))
common.text_rows_set(obj, 3, last_update) common.text_rows_set(obj, 3, last_update)
common.text_rows_set(obj, 4, last_sync) common.text_rows_set(obj, 4, last_sync)

View File

@ -71,10 +71,8 @@ properties:
additionalProperties: false additionalProperties: false
properties: properties:
battery: battery:
description: the battery device to use (if applicable) description: the battery device to use (or blank if none)
anyOf: type: string
- type: string
- type: "null"
rapl_specs: rapl_specs:
description: the Intel RAPL specs for which plots should be made description: the Intel RAPL specs for which plots should be made
type: array type: array
@ -181,7 +179,7 @@ properties:
network|pacman|filesystem|power|memory$" network|pacman|filesystem|power|memory$"
theme: theme:
required: [font, patterns] required: [font, geometry, patterns]
additionalProperties: false additionalProperties: false
properties: properties:
font: font:
@ -200,6 +198,66 @@ properties:
plot_label: *font_size plot_label: *font_size
table: *font_size table: *font_size
header: *font_size header: *font_size
geometry:
required: [plot, table]
additionalProperties: false
properties:
plot:
required: [seconds, ticks]
additionalProperties: false
properties:
seconds:
description: the number of seconds on each timeseries plot
type: integer
minimum: 30
ticks:
description: the number of ticks on the x/y axes
type: array
minItems: 2
maxItems: 2
items:
type: integer
minimum: 2
table:
required: [name_chars, padding, header_padding]
additionalProperties: false
properties:
name_chars:
description: |
the length to which the name column should be trimmed (if any)
type: integer
minimum: 0
padding:
description: the x/y padding around the table
type: array
minItems: 2
maxItems: 2
items:
type: integer
minimum: 0
header_padding:
description: the padding beneath the column headers
type: integer
minimum: 0
row_spacing:
description: the distance between the center of each row
type: integer
minimum: 10
header:
required: [underline_offset, padding]
additionalProperties: false
properties:
underline_offset:
description: the offset of the underline (from top of header)
type: integer
minimum: 10
padding:
description: the padding beneath the underline
type: integer
minimum: 0
patterns: patterns:
required: [header, panel, text, border, plot, indicator] required: [header, panel, text, border, plot, indicator]
additionalProperties: false additionalProperties: false
@ -215,10 +273,10 @@ properties:
properties: properties:
color: color:
type: integer type: integer
alpha: alpha: &alpha
anyOf: type: number
- type: "null" minimum: 0
- &alpha {type: number, minimum: 0, maximum: 1} maximum: 1
gradient: gradient:
type: array type: array
minItems: 2 minItems: 2