ENH put rest of configurable options in yaml file
This commit is contained in:
parent
efa4319acd
commit
bdca0c6511
12
config.yml
12
config.yml
|
@ -58,6 +58,18 @@ theme:
|
|||
plot_label: 8
|
||||
table: 11
|
||||
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:
|
||||
header: 0xefefef
|
||||
panel:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
local geom = require 'geom'
|
||||
local format = require 'format'
|
||||
local color = require 'color'
|
||||
-- local theme = require 'theme'
|
||||
local dial = require 'dial'
|
||||
local rect = require 'rect'
|
||||
local fill_rect = require 'fill_rect'
|
||||
|
@ -22,6 +21,7 @@ local pure = require 'pure'
|
|||
|
||||
local compile_patterns
|
||||
|
||||
-- TODO move to color module
|
||||
compile_patterns = function(patterns)
|
||||
local r = {}
|
||||
for k, v in pairs(patterns) do
|
||||
|
@ -59,27 +59,24 @@ return function(config)
|
|||
local font = config.theme.font
|
||||
local font_sizes = font.sizes
|
||||
local font_family = font.family
|
||||
local geometry = config.theme.geometry
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- constants
|
||||
|
||||
local HEADER_HEIGHT = 45
|
||||
local HEADER_UNDERLINE_CAP = CAIRO_LINE_CAP_ROUND
|
||||
local HEADER_UNDERLINE_OFFSET = 26
|
||||
local CAP_ROUND = CAIRO_LINE_CAP_ROUND
|
||||
local CAP_BUTT = CAIRO_LINE_CAP_BUTT
|
||||
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 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 PLOT_NUM_POINTS = 90
|
||||
local PLOT_GRID_X_N = 9
|
||||
local PLOT_GRID_Y_N = 4
|
||||
|
||||
local ARC_WIDTH = 2
|
||||
|
||||
local DIAL_THETA0 = 90
|
||||
|
@ -99,16 +96,16 @@ return function(config)
|
|||
return {
|
||||
family = f,
|
||||
size = size,
|
||||
weight = bold and CAIRO_font_family_WEIGHT_BOLD or CAIRO_font_family_WEIGHT_NORMAL,
|
||||
slant = CAIRO_font_family_WEIGHT_NORMAL,
|
||||
weight = bold and FONT_BOLD or FONT_NORMAL,
|
||||
slant = FONT_NORMAL,
|
||||
}
|
||||
end
|
||||
|
||||
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 _text_row_style = function(x_align, color)
|
||||
return text.config(normal_font_spec, color, x_align, 'center')
|
||||
local _text_row_style = function(x_align, _color)
|
||||
return text.config(normal_font_spec, _color, x_align, 'center')
|
||||
end
|
||||
|
||||
local _left_text_style = _text_row_style('left', patterns.text.inactive)
|
||||
|
@ -130,13 +127,13 @@ return function(config)
|
|||
-- timeseries helper functions
|
||||
|
||||
local _default_grid_config = timeseries.grid_config(
|
||||
PLOT_GRID_X_N,
|
||||
PLOT_GRID_Y_N,
|
||||
geometry.plot.ticks[1],
|
||||
geometry.plot.ticks[2],
|
||||
patterns.plot.grid
|
||||
)
|
||||
|
||||
local _default_plot_config = timeseries.config(
|
||||
PLOT_NUM_POINTS,
|
||||
geometry.plot.seconds,
|
||||
patterns.plot.outline,
|
||||
patterns.plot.data.border,
|
||||
patterns.plot.data.fill,
|
||||
|
@ -144,7 +141,7 @@ return function(config)
|
|||
)
|
||||
|
||||
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
|
||||
|
||||
local _format_percent_maybe = function(z)
|
||||
|
@ -207,8 +204,8 @@ return function(config)
|
|||
-- header
|
||||
|
||||
M.make_header = function(x, y, w, _text)
|
||||
local bottom_y = y + HEADER_HEIGHT
|
||||
local underline_y = y + HEADER_UNDERLINE_OFFSET
|
||||
local underline_y = y + geometry.header.underline_offset
|
||||
local bottom_y = underline_y + geometry.header.padding
|
||||
return {
|
||||
text = text.make_plain(
|
||||
geom.make_point(x, y),
|
||||
|
@ -329,7 +326,15 @@ return function(config)
|
|||
_right_text_style,
|
||||
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
|
||||
|
||||
|
@ -371,7 +376,15 @@ return function(config)
|
|||
_right_text_style,
|
||||
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,
|
||||
derive = make_differential(update_freq),
|
||||
}
|
||||
|
@ -390,7 +403,7 @@ return function(config)
|
|||
M.make_circle = function(x, y, r)
|
||||
return circle.make(
|
||||
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
|
||||
|
||||
|
@ -437,7 +450,7 @@ return function(config)
|
|||
return {
|
||||
dial = dial.make(
|
||||
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)
|
||||
),
|
||||
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)
|
||||
return compound_dial.make(
|
||||
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),
|
||||
inner_radius,
|
||||
num_dials
|
||||
|
@ -489,7 +502,7 @@ return function(config)
|
|||
geom.make_point(x + pad, y),
|
||||
w - pad,
|
||||
line.config(
|
||||
style.line(thickness, CAIRO_LINE_CAP_BUTT),
|
||||
style.line(thickness, CAP_BUTT),
|
||||
patterns.indicator.bg,
|
||||
true
|
||||
),
|
||||
|
@ -521,7 +534,7 @@ return function(config)
|
|||
return line.make(
|
||||
_make_horizontal_line(x, y, w),
|
||||
line.config(
|
||||
style.line(SEPARATOR_THICKNESS, CAIRO_LINE_CAP_BUTT),
|
||||
style.line(SEPARATOR_THICKNESS, CAP_BUTT),
|
||||
patterns.border,
|
||||
true
|
||||
)
|
||||
|
@ -579,7 +592,7 @@ return function(config)
|
|||
-----------------------------------------------------------------------------
|
||||
-- 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 {
|
||||
labels = text_column.make(
|
||||
geom.make_point(x, y),
|
||||
|
@ -592,7 +605,7 @@ return function(config)
|
|||
geom.make_point(x + w, y),
|
||||
#labels,
|
||||
_right_text_style,
|
||||
format,
|
||||
_format,
|
||||
spacing,
|
||||
0
|
||||
)
|
||||
|
@ -625,43 +638,50 @@ return function(config)
|
|||
-----------------------------------------------------------------------------
|
||||
-- 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 col_fmt = gtable.name_chars > 0 and gtable.name_chars
|
||||
|
||||
local default_table_config = function(label)
|
||||
return tbl.config(
|
||||
rect.config(
|
||||
style.closed_poly(TABLE_LINE_THICKNESS, CAIRO_LINE_JOIN_MITER),
|
||||
style.closed_poly(TABLE_LINE_THICKNESS, JOIN_MITER),
|
||||
patterns.border
|
||||
),
|
||||
line.config(
|
||||
style.line(TABLE_LINE_THICKNESS, CAIRO_LINE_CAP_BUTT),
|
||||
style.line(TABLE_LINE_THICKNESS, CAP_BUTT),
|
||||
patterns.border,
|
||||
true
|
||||
),
|
||||
tbl.header_config(
|
||||
default_table_font_spec,
|
||||
patterns.text.active,
|
||||
TABLE_HEADER_PAD
|
||||
gtable.header_padding
|
||||
),
|
||||
tbl.body_config(
|
||||
default_table_font_spec,
|
||||
patterns.text.inactive,
|
||||
{
|
||||
tbl.column_config('Name', TABLE_BODY_FORMAT),
|
||||
tbl.column_config('Name', col_fmt),
|
||||
tbl.column_config('PID', false),
|
||||
tbl.column_config(label, false),
|
||||
}
|
||||
),
|
||||
tbl.padding(
|
||||
TABLE_HORZ_PAD,
|
||||
TABLE_VERT_PAD,
|
||||
TABLE_HORZ_PAD,
|
||||
TABLE_VERT_PAD
|
||||
)
|
||||
tbl.padding(xpad, ypad, xpad, ypad)
|
||||
)
|
||||
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(
|
||||
geom.make_box(x, y, w, h),
|
||||
n,
|
||||
|
@ -669,10 +689,6 @@ return function(config)
|
|||
)
|
||||
end
|
||||
|
||||
M.table_height = function(n)
|
||||
return TABLE_VERT_PAD * 2 + TABLE_HEADER_PAD + 13 * n
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- panel
|
||||
|
||||
|
@ -680,14 +696,13 @@ return function(config)
|
|||
return fill_rect.make(
|
||||
geom.make_box(x, y, w, h),
|
||||
rect.config(
|
||||
style.closed_poly(thickness, CAIRO_LINE_JOIN_MITER),
|
||||
style.closed_poly(thickness, JOIN_MITER),
|
||||
patterns.border
|
||||
),
|
||||
patterns.panel.bg
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- compile individual module
|
||||
|
||||
|
|
|
@ -179,7 +179,6 @@ return function(update_freq, config, common, width, point)
|
|||
|
||||
local mk_tbl = function(y)
|
||||
local num_rows = config.table_rows
|
||||
local table_height = common.table_height(num_rows)
|
||||
local table_conky = pure.map_n(
|
||||
function(i)
|
||||
return {
|
||||
|
@ -193,7 +192,6 @@ return function(update_freq, config, common, width, point)
|
|||
point.x,
|
||||
y,
|
||||
width,
|
||||
table_height,
|
||||
num_rows,
|
||||
'Mem (%)'
|
||||
)
|
||||
|
@ -206,7 +204,7 @@ return function(update_freq, config, common, width, point)
|
|||
end
|
||||
return common.mk_acc(
|
||||
width,
|
||||
table_height,
|
||||
common.table_height(num_rows),
|
||||
update,
|
||||
pure.partial(text_table.draw_static, obj),
|
||||
pure.partial(text_table.draw_dynamic, obj)
|
||||
|
|
|
@ -112,8 +112,7 @@ return function(update_freq, config, common, width, point)
|
|||
set_state = nil,
|
||||
top = pure.concat(
|
||||
pure.map(mk_rate_blockspec, config.rapl_specs),
|
||||
-- TODO what happens if this is nil?
|
||||
{{mk_bat, config.battery ~= nil, 0}}
|
||||
{{mk_bat, config.battery ~= '', 0}}
|
||||
)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -193,7 +193,6 @@ return function(update_freq, config, main_state, common, width, point)
|
|||
|
||||
local mk_tbl = function(y)
|
||||
local num_rows = config.table_rows
|
||||
local table_height = common.table_height(num_rows)
|
||||
local table_conky = pure.map_n(
|
||||
function(i) return {pid = '${top pid '..i..'}', cpu = '${top cpu '..i..'}'} end,
|
||||
num_rows
|
||||
|
@ -202,7 +201,6 @@ return function(update_freq, config, main_state, common, width, point)
|
|||
point.x,
|
||||
y,
|
||||
width,
|
||||
table_height,
|
||||
num_rows,
|
||||
'CPU (%)'
|
||||
)
|
||||
|
@ -218,7 +216,7 @@ return function(update_freq, config, main_state, common, width, point)
|
|||
end
|
||||
return common.mk_acc(
|
||||
width,
|
||||
table_height,
|
||||
common.table_height(num_rows),
|
||||
update,
|
||||
pure.partial(text_table.draw_static, tbl),
|
||||
pure.partial(text_table.draw_dynamic, tbl)
|
||||
|
|
|
@ -14,6 +14,8 @@ return function(main_state, common, width, point)
|
|||
TEXT_SPACING,
|
||||
{'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
|
||||
)
|
||||
-- just update this once
|
||||
common.text_rows_set(obj, 1, i_o.conky('$kernel'))
|
||||
local update = function()
|
||||
local last_update, last_sync
|
||||
if main_state.pacman_stats then
|
||||
|
@ -22,8 +24,6 @@ return function(main_state, common, width, point)
|
|||
"^%d+%s+([^%s]+)%s+([^%s]+).*"
|
||||
)
|
||||
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, 3, last_update)
|
||||
common.text_rows_set(obj, 4, last_sync)
|
||||
|
|
76
schema.yml
76
schema.yml
|
@ -71,10 +71,8 @@ properties:
|
|||
additionalProperties: false
|
||||
properties:
|
||||
battery:
|
||||
description: the battery device to use (if applicable)
|
||||
anyOf:
|
||||
- type: string
|
||||
- type: "null"
|
||||
description: the battery device to use (or blank if none)
|
||||
type: string
|
||||
rapl_specs:
|
||||
description: the Intel RAPL specs for which plots should be made
|
||||
type: array
|
||||
|
@ -181,7 +179,7 @@ properties:
|
|||
network|pacman|filesystem|power|memory$"
|
||||
|
||||
theme:
|
||||
required: [font, patterns]
|
||||
required: [font, geometry, patterns]
|
||||
additionalProperties: false
|
||||
properties:
|
||||
font:
|
||||
|
@ -200,6 +198,66 @@ properties:
|
|||
plot_label: *font_size
|
||||
table: *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:
|
||||
required: [header, panel, text, border, plot, indicator]
|
||||
additionalProperties: false
|
||||
|
@ -215,10 +273,10 @@ properties:
|
|||
properties:
|
||||
color:
|
||||
type: integer
|
||||
alpha:
|
||||
anyOf:
|
||||
- type: "null"
|
||||
- &alpha {type: number, minimum: 0, maximum: 1}
|
||||
alpha: &alpha
|
||||
type: number
|
||||
minimum: 0
|
||||
maximum: 1
|
||||
gradient:
|
||||
type: array
|
||||
minItems: 2
|
||||
|
|
Loading…
Reference in New Issue