ENH use yaml theme instead of hardcoded theme
This commit is contained in:
parent
b657a60d1b
commit
0ae8e207f1
|
@ -69,8 +69,8 @@ theme:
|
|||
- {stop: 1, color: 0x1e90ff}
|
||||
fill:
|
||||
gradient_alpha:
|
||||
- {stop: 0.2, color: 0x003f7c, alpha: 0.5}
|
||||
- {stop: 1, color: 0x1e90ff, alpha: 1.0}
|
||||
- {stop: 0.2, color: 0x316ece, alpha: 0.5}
|
||||
- {stop: 1, color: 0x8cc7ff, alpha: 1.0}
|
||||
indicator:
|
||||
bg:
|
||||
gradient:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,218 @@
|
|||
local M = {}
|
||||
|
||||
local pure = require 'pure'
|
||||
local geom = require 'geom'
|
||||
local fill_rect = require 'fill_rect'
|
||||
local line = require 'line'
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- compile individual module
|
||||
|
||||
local _combine_blocks = function(acc, new)
|
||||
if new.active == true then
|
||||
local n = new.f(acc.next_y)
|
||||
table.insert(acc.objs, n.obj)
|
||||
acc.w = math.max(acc.w, n.w)
|
||||
acc.final_y = acc.next_y + n.h
|
||||
acc.next_y = acc.final_y + new.offset
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
||||
local non_false = function(xs)
|
||||
return pure.filter(function(x) return x ~= false end, xs)
|
||||
end
|
||||
|
||||
local mk_block = function(f, active, offset)
|
||||
return {f = f, active = active, offset = offset}
|
||||
end
|
||||
|
||||
local active_blocks = function(blockspecs)
|
||||
local bs = pure.filter(function(b) return b[2] end, blockspecs)
|
||||
return pure.map(function(b) return mk_block(table.unpack(b)) end, bs)
|
||||
end
|
||||
|
||||
local flatten_sections = function(top, ...)
|
||||
local f = function(acc, new)
|
||||
if #new.blocks == 0 then
|
||||
return acc
|
||||
elseif #acc == 0 then
|
||||
return new.blocks
|
||||
else
|
||||
return pure.flatten(
|
||||
{acc, {mk_block(new.sep_fun, true, new.top)}, new.blocks}
|
||||
)
|
||||
end
|
||||
end
|
||||
return pure.reduce(f, active_blocks(top), {...})
|
||||
end
|
||||
|
||||
M.mk_section = function(top, sep_fun, ...)
|
||||
return {
|
||||
top = top,
|
||||
sep_fun = sep_fun,
|
||||
blocks = active_blocks({...})
|
||||
}
|
||||
end
|
||||
|
||||
M.mk_seperator = function(common, width, x, y)
|
||||
local separator = common.make_separator(x, y, width)
|
||||
return M.mk_acc_static(width, 0, pure.partial(line.draw, separator))
|
||||
end
|
||||
|
||||
M.mk_acc = function(w, h, u, s, d)
|
||||
return {w = w, h = h, obj = {u, s, d}}
|
||||
end
|
||||
|
||||
M.mk_acc_static = function(w, h, s)
|
||||
return M.mk_acc(w, h, false, s, false)
|
||||
end
|
||||
|
||||
M.compile_module = function(common, header, point, width, top_blocks, ...)
|
||||
local mk_header = function(y)
|
||||
local obj = common.make_header(point.x, y, width, header)
|
||||
return M.mk_acc_static(
|
||||
width,
|
||||
obj.bottom_y - y,
|
||||
function(cr) common.draw_header(cr, obj) end
|
||||
)
|
||||
end
|
||||
local blocks = flatten_sections(top_blocks, ...)
|
||||
local r = pure.reduce(
|
||||
_combine_blocks,
|
||||
{w = 0, next_y = point.y, final_y = point.y, objs = {}},
|
||||
{mk_block(mk_header, true, 0), table.unpack(blocks)}
|
||||
)
|
||||
local us, ss, ds = table.unpack(pure.unzip(r.objs))
|
||||
return {
|
||||
next_x = point.x + r.w,
|
||||
next_y = r.final_y,
|
||||
update = pure.sequence(table.unpack(non_false(us))),
|
||||
static = pure.sequence(table.unpack(ss)),
|
||||
dynamic = pure.sequence(table.unpack(non_false(ds)))
|
||||
}
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- compile entire layout
|
||||
|
||||
local reduce_modules_y = function(common, modlist, init_x, width, acc, new)
|
||||
if type(new) == "number" then
|
||||
acc.next_y = acc.next_y + new
|
||||
else
|
||||
print(new)
|
||||
local r = modlist[new](common, width, geom.make_point(init_x, acc.next_y))
|
||||
table.insert(acc.fgroups, {update = r.update, static = r.static, dynamic = r.dynamic})
|
||||
acc.next_x = math.max(acc.next_x, r.next_x)
|
||||
acc.next_y = r.next_y
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
||||
local reduce_modules_x = function(common, modlist, init_y, acc, x_mods)
|
||||
if type(x_mods) == "number" then
|
||||
acc.next_x = acc.next_x + x_mods
|
||||
else
|
||||
local r = pure.reduce(
|
||||
pure.partial(reduce_modules_y, common, modlist, acc.next_x, x_mods.width),
|
||||
{next_x = acc.next_x, next_y = init_y, fgroups = acc.fgroups},
|
||||
x_mods.blocks
|
||||
)
|
||||
acc.fgroups = r.fgroups
|
||||
acc.next_x = r.next_x
|
||||
acc.next_y = math.max(acc.next_y, r.next_y)
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
||||
local arrange_panel_modules = function(common, modlist, point, mods)
|
||||
local r = pure.reduce(
|
||||
pure.partial(reduce_modules_x, common, modlist, point.y),
|
||||
{next_x = point.x, next_y = point.y, fgroups = {}},
|
||||
mods
|
||||
)
|
||||
return {
|
||||
point_ul = point,
|
||||
width = r.next_x - point.x,
|
||||
height = r.next_y - point.y,
|
||||
update = pure.map_keys('update', r.fgroups),
|
||||
static = pure.map_keys('static', r.fgroups),
|
||||
dynamic = pure.map_keys('dynamic', r.fgroups),
|
||||
}
|
||||
end
|
||||
|
||||
local build_surface = function(common, box, fs)
|
||||
local panel_line_thickness = 1
|
||||
-- move over by half a pixel so the lines don't need to be antialiased
|
||||
local _x = box.corner.x + 0.5
|
||||
local _y = box.corner.y + 0.5
|
||||
local panel = common.make_panel(_x, _y, box.width, box.height, panel_line_thickness)
|
||||
local cs_x = _x - panel_line_thickness * 0.5
|
||||
local cs_y = _y - panel_line_thickness * 0.5
|
||||
local cs_w = box.width + panel_line_thickness
|
||||
local cs_h = box.height + panel_line_thickness
|
||||
|
||||
local cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
|
||||
local cr = cairo_create(cs)
|
||||
|
||||
cairo_translate(cr, -cs_x, -cs_y)
|
||||
|
||||
fill_rect.draw(panel, cr)
|
||||
for i = 1, #fs do
|
||||
fs[i](cr)
|
||||
end
|
||||
cairo_destroy(cr)
|
||||
return {x = cs_x, y = cs_y, s = cs}
|
||||
end
|
||||
|
||||
local reduce_static = function(common, mods, y, acc, panel_mods)
|
||||
if type(panel_mods) == "number" then
|
||||
acc.next_x = acc.next_x + panel_mods
|
||||
else
|
||||
local margins = panel_mods.margins
|
||||
local margin_x = margins[1]
|
||||
local margin_y = margins[2]
|
||||
local mpoint = geom.make_point(acc.next_x + margin_x, y + margin_y)
|
||||
local r = arrange_panel_modules(common, mods, mpoint, panel_mods.columns)
|
||||
local w = r.width + margin_x * 2
|
||||
local h = r.height + margin_y * 2
|
||||
local pbox = geom.make_box(acc.next_x, y, w, h)
|
||||
acc.next_x = acc.next_x + w
|
||||
acc.static = pure.flatten({acc.static, {build_surface(common, pbox, r.static)}})
|
||||
acc.update = pure.flatten({acc.update, r.update})
|
||||
acc.dynamic = pure.flatten({acc.dynamic, r.dynamic})
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
||||
M.compile_layout = function(common, point, mods, module_sets)
|
||||
local __cairo_set_source_surface = cairo_set_source_surface
|
||||
local __cairo_paint = cairo_paint
|
||||
|
||||
local r = pure.reduce(
|
||||
pure.partial(
|
||||
reduce_static,
|
||||
common,
|
||||
mods,
|
||||
point.y
|
||||
),
|
||||
{next_x = point.x, static = {}, update = {}, dynamic = {}},
|
||||
module_sets
|
||||
)
|
||||
|
||||
local cs = r.static
|
||||
|
||||
return {
|
||||
static = function(cr)
|
||||
for i = 1, #cs do
|
||||
local c = cs[i]
|
||||
__cairo_set_source_surface(cr, c.s, c.x, c.y)
|
||||
__cairo_paint(cr)
|
||||
end
|
||||
end,
|
||||
update = pure.sequence(table.unpack(r.update)),
|
||||
dynamic = pure.sequence(table.unpack(r.dynamic)),
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
|
@ -1,10 +1,9 @@
|
|||
local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local compile = require 'compile'
|
||||
local pure = require 'pure'
|
||||
local impure = require 'impure'
|
||||
|
||||
-- ASSUME pathspecs will be at least 1 long
|
||||
return function(config, main_state, width, point)
|
||||
return function(config, main_state, common, width, point)
|
||||
local SPACING = 20
|
||||
local BAR_PAD = 100
|
||||
local SEPARATOR_SPACING = 20
|
||||
|
@ -20,7 +19,7 @@ return function(config, main_state, width, point)
|
|||
common.text_row_set(obj, (pid == '') and 'Error' or 'Running')
|
||||
end
|
||||
end
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
0,
|
||||
update,
|
||||
|
@ -29,7 +28,7 @@ return function(config, main_state, width, point)
|
|||
)
|
||||
end
|
||||
|
||||
local mk_sep = pure.partial(common.mk_seperator, width, point.x)
|
||||
local mk_sep = pure.partial(compile.mk_seperator, common, width, point.x)
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- filesystem bar chart
|
||||
|
@ -37,7 +36,6 @@ return function(config, main_state, width, point)
|
|||
local mk_bars = function(y)
|
||||
local paths = pure.map_keys('path', config.fs_paths)
|
||||
local names = pure.map_keys('name', config.fs_paths)
|
||||
-- local paths, names = table.unpack(pure.unzip(config.fs_paths))
|
||||
local CONKY_CMDS = pure.map(
|
||||
pure.partial(string.format, '${fs_used_perc %s}', true),
|
||||
paths
|
||||
|
@ -60,7 +58,7 @@ return function(config, main_state, width, point)
|
|||
impure.ieach(read_fs, CONKY_CMDS)
|
||||
end
|
||||
end
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
(#config.fs_paths - 1) * SPACING,
|
||||
update,
|
||||
|
@ -72,11 +70,12 @@ return function(config, main_state, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main functions
|
||||
|
||||
return common.reduce_blocks_(
|
||||
return compile.compile_module(
|
||||
common,
|
||||
'FILE SYSTEMS',
|
||||
point,
|
||||
width,
|
||||
{{mk_smart, config.show_smart, SEPARATOR_SPACING}},
|
||||
common.mk_section(SEPARATOR_SPACING, mk_sep, {mk_bars, true, 0})
|
||||
compile.mk_section(SEPARATOR_SPACING, mk_sep, {mk_bars, true, 0})
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
local pure = require 'pure'
|
||||
local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local compile = require 'compile'
|
||||
|
||||
return function(update_freq, config, width, point)
|
||||
return function(update_freq, config, common, width, point)
|
||||
local SEPARATOR_SPACING = 20
|
||||
local TEXT_SPACING = 20
|
||||
local PLOT_SEC_BREAK = 20
|
||||
|
@ -41,7 +41,7 @@ return function(update_freq, config, width, point)
|
|||
)
|
||||
local static = pure.partial(common.tagged_percent_timeseries_draw_static, obj)
|
||||
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, obj)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||
update,
|
||||
|
@ -69,11 +69,12 @@ return function(update_freq, config, width, point)
|
|||
end
|
||||
local static = pure.partial(common.text_row_draw_static, obj)
|
||||
local dynamic = pure.partial(common.text_row_draw_dynamic, obj)
|
||||
return common.mk_acc(width, 0, update, static, dynamic)
|
||||
return compile.mk_acc(width, 0, update, static, dynamic)
|
||||
end
|
||||
|
||||
local mk_sep = pure.partial(
|
||||
common.mk_seperator,
|
||||
compile.mk_seperator,
|
||||
common,
|
||||
width,
|
||||
point.x
|
||||
)
|
||||
|
@ -99,7 +100,7 @@ return function(update_freq, config, width, point)
|
|||
)
|
||||
local static = pure.partial(common.threshold_text_row_draw_static, obj)
|
||||
local dynamic = pure.partial(common.threshold_text_row_draw_dynamic, obj)
|
||||
return common.mk_acc(width, 0, update, static, dynamic)
|
||||
return compile.mk_acc(width, 0, update, static, dynamic)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -124,7 +125,7 @@ return function(update_freq, config, width, point)
|
|||
end
|
||||
local static = pure.partial(common.text_rows_draw_static, obj)
|
||||
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
|
||||
return common.mk_acc(width, TEXT_SPACING, update, static, dynamic)
|
||||
return compile.mk_acc(width, TEXT_SPACING, update, static, dynamic)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -216,22 +217,23 @@ return function(update_freq, config, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main drawing functions
|
||||
|
||||
local rbs = common.reduce_blocks_(
|
||||
local rbs = compile.compile_module(
|
||||
common,
|
||||
'NVIDIA GRAPHICS',
|
||||
point,
|
||||
width,
|
||||
{{mk_status, true, SEPARATOR_SPACING}},
|
||||
common.mk_section(
|
||||
compile.mk_section(
|
||||
SEPARATOR_SPACING,
|
||||
mk_sep,
|
||||
{mk_temp, config.show_temp, SEPARATOR_SPACING}
|
||||
),
|
||||
common.mk_section(
|
||||
compile.mk_section(
|
||||
SEPARATOR_SPACING,
|
||||
mk_sep,
|
||||
{mk_clock, config.show_clock, SEPARATOR_SPACING}
|
||||
),
|
||||
common.mk_section(
|
||||
compile.mk_section(
|
||||
SEPARATOR_SPACING,
|
||||
mk_sep,
|
||||
{mk_gpu_util, config.show_gpu_util, PLOT_SEC_BREAK},
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
local timeseries = require 'timeseries'
|
||||
local text_table = require 'text_table'
|
||||
local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local pure = require 'pure'
|
||||
local compile = require 'compile'
|
||||
|
||||
return function(update_freq, config, width, point)
|
||||
return function(update_freq, config, common, width, point)
|
||||
local DIAL_THICKNESS = 8
|
||||
local DIAL_RADIUS = 32
|
||||
local DIAL_SPACING = 40
|
||||
|
@ -78,7 +78,7 @@ return function(update_freq, config, width, point)
|
|||
common.dial_draw_dynamic(swap, cr)
|
||||
common.text_rows_draw_dynamic(cache, cr)
|
||||
end
|
||||
return common.mk_acc(width, DIAL_DIAMETER, update, static, dynamic)
|
||||
return compile.mk_acc(width, DIAL_DIAMETER, update, static, dynamic)
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
@ -92,7 +92,7 @@ return function(update_freq, config, width, point)
|
|||
PLOT_HEIGHT,
|
||||
update_freq
|
||||
)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
PLOT_HEIGHT,
|
||||
function(s) timeseries.update(obj, s.mem.used_percent) end,
|
||||
|
@ -130,7 +130,7 @@ return function(update_freq, config, width, point)
|
|||
text_table.set(obj, 3, r, i_o.conky(TABLE_CONKY[r].mem))
|
||||
end
|
||||
end
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
TABLE_HEIGHT,
|
||||
update,
|
||||
|
@ -179,7 +179,8 @@ return function(update_freq, config, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main functions
|
||||
|
||||
local rbs = common.reduce_blocks_(
|
||||
local rbs = compile.compile_module(
|
||||
common,
|
||||
'MEMORY',
|
||||
point,
|
||||
width,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
local format = require 'format'
|
||||
local pure = require 'pure'
|
||||
local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local sys = require 'sys'
|
||||
local compile = require 'compile'
|
||||
|
||||
return function(update_freq, width, point)
|
||||
return function(update_freq, common, width, point)
|
||||
local PLOT_SEC_BREAK = 20
|
||||
local PLOT_HEIGHT = 56
|
||||
local INTERFACE_PATHS = sys.get_net_interface_paths()
|
||||
|
@ -51,7 +51,7 @@ return function(update_freq, width, point)
|
|||
update_freq,
|
||||
state[key]
|
||||
)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||
function(s) common.update_rate_timeseries(obj, s[key]) end,
|
||||
|
@ -66,7 +66,8 @@ return function(update_freq, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main drawing functions
|
||||
|
||||
local rbs = common.reduce_blocks_(
|
||||
local rbs = compile.compile_module(
|
||||
common,
|
||||
'NETWORK',
|
||||
point,
|
||||
width,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
local common = require 'common'
|
||||
local compile = require 'compile'
|
||||
local pure = require 'pure'
|
||||
|
||||
return function(main_state, width, point)
|
||||
return function(main_state, common, width, point)
|
||||
local TEXT_SPACING = 20
|
||||
|
||||
local __string_match = string.match
|
||||
|
@ -32,7 +32,7 @@ return function(main_state, width, point)
|
|||
end
|
||||
end
|
||||
end
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
TEXT_SPACING * 4,
|
||||
update,
|
||||
|
@ -41,7 +41,8 @@ return function(main_state, width, point)
|
|||
)
|
||||
end
|
||||
|
||||
return common.reduce_blocks_(
|
||||
return compile.compile_module(
|
||||
common,
|
||||
'PACMAN',
|
||||
point,
|
||||
width,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
local format = require 'format'
|
||||
local pure = require 'pure'
|
||||
local common = require 'common'
|
||||
local compile = require 'compile'
|
||||
local sys = require 'sys'
|
||||
|
||||
return function(update_freq, config, width, point)
|
||||
return function(update_freq, config, common, width, point)
|
||||
local TEXT_SPACING = 20
|
||||
local PLOT_SEC_BREAK = 20
|
||||
local PLOT_HEIGHT = 56
|
||||
|
@ -40,7 +40,7 @@ return function(update_freq, config, width, point)
|
|||
update_freq,
|
||||
read_joules()
|
||||
)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||
function(_) common.update_rate_timeseries(obj, read_joules()) end,
|
||||
|
@ -89,7 +89,7 @@ return function(update_freq, config, width, point)
|
|||
0,
|
||||
update_freq
|
||||
)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||
function()
|
||||
|
@ -106,7 +106,8 @@ return function(update_freq, config, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main functions
|
||||
|
||||
return common.reduce_blocks_(
|
||||
return compile.compile_module(
|
||||
common,
|
||||
'POWER',
|
||||
point,
|
||||
width,
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
local compound_dial = require 'compound_dial'
|
||||
local text_table = require 'text_table'
|
||||
local i_o = require 'i_o'
|
||||
local common = require 'common'
|
||||
local compile = require 'compile'
|
||||
local cpu = require 'sys'
|
||||
local pure = require 'pure'
|
||||
|
||||
local __math_floor = math.floor
|
||||
|
||||
return function(update_freq, config, main_state, width, point)
|
||||
return function(update_freq, config, main_state, common, width, point)
|
||||
local DIAL_INNER_RADIUS = 30
|
||||
local DIAL_OUTER_RADIUS = 42
|
||||
local DIAL_THICKNESS = 5.5
|
||||
|
@ -91,7 +91,7 @@ return function(update_freq, config, main_state, width, point)
|
|||
compound_dial.draw_dynamic(cores[i].loads, cr)
|
||||
end
|
||||
end
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
DIAL_OUTER_RADIUS * 2,
|
||||
update,
|
||||
|
@ -123,7 +123,7 @@ return function(update_freq, config, main_state, width, point)
|
|||
end
|
||||
local static = pure.partial(common.text_rows_draw_static, cpu_status)
|
||||
local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
TEXT_SPACING,
|
||||
update,
|
||||
|
@ -136,7 +136,8 @@ return function(update_freq, config, main_state, width, point)
|
|||
-- frequency
|
||||
|
||||
local mk_sep = pure.partial(
|
||||
common.mk_seperator,
|
||||
compile.mk_seperator,
|
||||
common,
|
||||
width,
|
||||
point.x
|
||||
)
|
||||
|
@ -163,7 +164,7 @@ return function(update_freq, config, main_state, width, point)
|
|||
end
|
||||
local static = pure.partial(common.tagged_percent_timeseries_draw_static, total_load)
|
||||
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, total_load)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
PLOT_HEIGHT + PLOT_SECTION_BREAK,
|
||||
update,
|
||||
|
@ -202,7 +203,7 @@ return function(update_freq, config, main_state, width, point)
|
|||
end
|
||||
local static = pure.partial(text_table.draw_static, tbl)
|
||||
local dynamic = pure.partial(text_table.draw_dynamic, tbl)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
TABLE_HEIGHT,
|
||||
update,
|
||||
|
@ -214,7 +215,8 @@ return function(update_freq, config, main_state, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main functions
|
||||
|
||||
local rbs = common.reduce_blocks_(
|
||||
local rbs = compile.compile_module(
|
||||
common,
|
||||
'PROCESSOR',
|
||||
point,
|
||||
width,
|
||||
|
@ -222,7 +224,7 @@ return function(update_freq, config, main_state, width, point)
|
|||
{mk_cores, config.show_cores, TEXT_SPACING},
|
||||
{mk_hwp_freq, config.show_stats, SEPARATOR_SPACING},
|
||||
},
|
||||
common.mk_section(
|
||||
compile.mk_section(
|
||||
SEPARATOR_SPACING,
|
||||
mk_sep,
|
||||
{mk_load_plot, config.show_plot, TABLE_SECTION_BREAK},
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
local format = require 'format'
|
||||
local pure = require 'pure'
|
||||
local common = require 'common'
|
||||
local compile = require 'compile'
|
||||
local sys = require 'sys'
|
||||
|
||||
return function(update_freq, config, width, point)
|
||||
return function(update_freq, config, common, width, point)
|
||||
local PLOT_SEC_BREAK = 20
|
||||
local PLOT_HEIGHT = 56
|
||||
-- TODO currently this will find any block device
|
||||
|
@ -34,7 +34,7 @@ return function(update_freq, config, width, point)
|
|||
update_freq,
|
||||
state[key]
|
||||
)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
-- TODO construct this more sanely without referring to hardcoded vars
|
||||
width,
|
||||
PLOT_HEIGHT + PLOT_SEC_BREAK,
|
||||
|
@ -50,7 +50,8 @@ return function(update_freq, config, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main drawing functions
|
||||
|
||||
local rbs = common.reduce_blocks_(
|
||||
local rbs = compile.compile_module(
|
||||
common,
|
||||
'INPUT / OUTPUT',
|
||||
point,
|
||||
width,
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
local common = require 'common'
|
||||
local pure = require 'pure'
|
||||
local geom = require 'geom'
|
||||
local fill_rect = require 'fill_rect'
|
||||
|
||||
local reduce_modules_y = function(modlist, init_x, width, acc, new)
|
||||
if type(new) == "number" then
|
||||
acc.next_y = acc.next_y + new
|
||||
else
|
||||
local r = modlist[new](width, geom.make_point(init_x, acc.next_y))
|
||||
table.insert(acc.fgroups, {update = r.update, static = r.static, dynamic = r.dynamic})
|
||||
acc.next_x = math.max(acc.next_x, r.next_x)
|
||||
acc.next_y = r.next_y
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
||||
local reduce_modules_x = function(modlist, init_y, acc, x_mods)
|
||||
if type(x_mods) == "number" then
|
||||
acc.next_x = acc.next_x + x_mods
|
||||
else
|
||||
local r = pure.reduce(
|
||||
pure.partial(reduce_modules_y, modlist, acc.next_x, x_mods.width),
|
||||
{next_x = acc.next_x, next_y = init_y, fgroups = acc.fgroups},
|
||||
x_mods.blocks
|
||||
)
|
||||
acc.fgroups = r.fgroups
|
||||
acc.next_x = r.next_x
|
||||
acc.next_y = math.max(acc.next_y, r.next_y)
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
||||
local arrange_panel_modules = function(modlist, point, mods)
|
||||
local r = pure.reduce(
|
||||
pure.partial(reduce_modules_x, modlist, point.y),
|
||||
{next_x = point.x, next_y = point.y, fgroups = {}},
|
||||
mods
|
||||
)
|
||||
return {
|
||||
point_ul = point,
|
||||
width = r.next_x - point.x,
|
||||
height = r.next_y - point.y,
|
||||
update = pure.map_keys('update', r.fgroups),
|
||||
static = pure.map_keys('static', r.fgroups),
|
||||
dynamic = pure.map_keys('dynamic', r.fgroups),
|
||||
}
|
||||
end
|
||||
|
||||
local build_surface = function(box, fs)
|
||||
local panel_line_thickness = 1
|
||||
-- move over by half a pixel so the lines don't need to be antialiased
|
||||
local _x = box.corner.x + 0.5
|
||||
local _y = box.corner.y + 0.5
|
||||
local panel = common.make_panel(_x, _y, box.width, box.height, panel_line_thickness)
|
||||
local cs_x = _x - panel_line_thickness * 0.5
|
||||
local cs_y = _y - panel_line_thickness * 0.5
|
||||
local cs_w = box.width + panel_line_thickness
|
||||
local cs_h = box.height + panel_line_thickness
|
||||
|
||||
local cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, cs_w, cs_h)
|
||||
local cr = cairo_create(cs)
|
||||
|
||||
cairo_translate(cr, -cs_x, -cs_y)
|
||||
|
||||
fill_rect.draw(panel, cr)
|
||||
for i = 1, #fs do
|
||||
fs[i](cr)
|
||||
end
|
||||
cairo_destroy(cr)
|
||||
return {x = cs_x, y = cs_y, s = cs}
|
||||
end
|
||||
|
||||
local reduce_static = function(mods, y, acc, panel_mods)
|
||||
if type(panel_mods) == "number" then
|
||||
acc.next_x = acc.next_x + panel_mods
|
||||
else
|
||||
local margins = panel_mods.margins
|
||||
local margin_x = margins[1]
|
||||
local margin_y = margins[2]
|
||||
local mpoint = geom.make_point(acc.next_x + margin_x, y + margin_y)
|
||||
local r = arrange_panel_modules(mods, mpoint, panel_mods.columns)
|
||||
local w = r.width + margin_x * 2
|
||||
local h = r.height + margin_y * 2
|
||||
local pbox = geom.make_box(acc.next_x, y, w, h)
|
||||
acc.next_x = acc.next_x + w
|
||||
acc.static = pure.flatten({acc.static, {build_surface(pbox, r.static)}})
|
||||
acc.update = pure.flatten({acc.update, r.update})
|
||||
acc.dynamic = pure.flatten({acc.dynamic, r.dynamic})
|
||||
end
|
||||
return acc
|
||||
end
|
||||
|
||||
return function(point, mods, module_sets)
|
||||
local __cairo_set_source_surface = cairo_set_source_surface
|
||||
local __cairo_paint = cairo_paint
|
||||
|
||||
local r = pure.reduce(
|
||||
pure.partial(
|
||||
reduce_static,
|
||||
mods,
|
||||
point.y
|
||||
),
|
||||
{next_x = point.x, static = {}, update = {}, dynamic = {}},
|
||||
module_sets
|
||||
)
|
||||
|
||||
local cs = r.static
|
||||
|
||||
return {
|
||||
static = function(cr)
|
||||
for i = 1, #cs do
|
||||
local c = cs[i]
|
||||
__cairo_set_source_surface(cr, c.s, c.x, c.y)
|
||||
__cairo_paint(cr)
|
||||
end
|
||||
end,
|
||||
update = pure.sequence(table.unpack(r.update)),
|
||||
dynamic = pure.sequence(table.unpack(r.dynamic)),
|
||||
}
|
||||
end
|
|
@ -1,8 +1,8 @@
|
|||
local i_o = require 'i_o'
|
||||
local pure = require 'pure'
|
||||
local common = require 'common'
|
||||
local compile = require 'compile'
|
||||
|
||||
return function(main_state, width, point)
|
||||
return function(main_state, common, width, point)
|
||||
local TEXT_SPACING = 20
|
||||
|
||||
local __string_match = string.match
|
||||
|
@ -23,7 +23,7 @@ return function(main_state, width, point)
|
|||
"^%d+%s+([^%s]+)%s+([^%s]+).*"
|
||||
)
|
||||
end
|
||||
-- TODO this doesn't need to be update every time
|
||||
-- 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)
|
||||
|
@ -31,7 +31,7 @@ return function(main_state, width, point)
|
|||
end
|
||||
local static = pure.partial(common.text_rows_draw_static, obj)
|
||||
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
|
||||
return common.mk_acc(
|
||||
return compile.mk_acc(
|
||||
width,
|
||||
TEXT_SPACING * 3,
|
||||
update,
|
||||
|
@ -40,10 +40,5 @@ return function(main_state, width, point)
|
|||
)
|
||||
end
|
||||
|
||||
return common.reduce_blocks_(
|
||||
'SYSTEM',
|
||||
point,
|
||||
width,
|
||||
{{mk_stats, true, 0}}
|
||||
)
|
||||
return compile.compile_module(common, 'SYSTEM', point, width, {{mk_stats, true, 0}})
|
||||
end
|
||||
|
|
23
main.lua
23
main.lua
|
@ -32,21 +32,19 @@ local power = require 'power'
|
|||
local readwrite = require 'readwrite'
|
||||
local graphics = require 'graphics'
|
||||
local memory = require 'memory'
|
||||
local static = require 'static'
|
||||
local compile = require 'compile'
|
||||
local common = require 'common'
|
||||
local yaml = require 'lyaml'
|
||||
|
||||
local draw_dynamic
|
||||
|
||||
function conky_start(update_interval)
|
||||
conky_set_update_interval(update_interval)
|
||||
|
||||
local build_main = function(update_interval, config_path)
|
||||
local update_freq = 1 / update_interval
|
||||
local config = yaml.load(i_o.read_file(config_path))
|
||||
local cmods = config.modules
|
||||
|
||||
local main_state = {}
|
||||
|
||||
local config = yaml.load(i_o.read_file(ABS_PATH..'config.yml'))
|
||||
local cmods = config.modules
|
||||
|
||||
local mods = {
|
||||
memory = pure.partial(memory, update_freq, cmods.memory),
|
||||
readwrite = pure.partial(readwrite, update_freq, cmods.readwrite),
|
||||
|
@ -59,7 +57,8 @@ function conky_start(update_interval)
|
|||
pacman = pure.partial(pacman, main_state)
|
||||
}
|
||||
|
||||
local compiled = static(
|
||||
local compiled = compile.compile_layout(
|
||||
common(config),
|
||||
geom.make_point(table.unpack(config.layout.anchor)),
|
||||
mods,
|
||||
config.layout.panels
|
||||
|
@ -67,7 +66,7 @@ function conky_start(update_interval)
|
|||
|
||||
local STATS_FILE = '/tmp/.conky_pacman'
|
||||
|
||||
draw_dynamic = function(cr, _updates)
|
||||
return function(cr, _updates)
|
||||
main_state.trigger10 = _updates % (update_freq * 10)
|
||||
main_state.pacman_stats = i_o.read_file(STATS_FILE)
|
||||
|
||||
|
@ -77,6 +76,12 @@ function conky_start(update_interval)
|
|||
end
|
||||
end
|
||||
|
||||
function conky_start(update_interval)
|
||||
conky_set_update_interval(update_interval)
|
||||
|
||||
draw_dynamic = build_main(update_interval, ABS_PATH..'config.yml')
|
||||
end
|
||||
|
||||
local updates = -2 -- this accounts for the first few spazzy iterations
|
||||
|
||||
function conky_main()
|
||||
|
|
Loading…
Reference in New Issue