REF don't use compile in modules

This commit is contained in:
Nathan Dwarshuis 2022-07-17 18:54:23 -04:00
parent 0ae8e207f1
commit 4094d754f1
11 changed files with 125 additions and 143 deletions

View File

@ -687,5 +687,94 @@ return function(config)
) )
end end
----------------------------------------------------------------------------
-- 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(width, x, y)
local separator = M.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(header, point, width, top_blocks, ...)
local mk_header = function(y)
local obj = M.make_header(point.x, y, width, header)
return M.mk_acc_static(
width,
obj.bottom_y - y,
function(cr) M.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
return M return M
end end

View File

@ -5,94 +5,6 @@ local geom = require 'geom'
local fill_rect = require 'fill_rect' local fill_rect = require 'fill_rect'
local line = require 'line' 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 -- compile entire layout

View File

@ -1,5 +1,4 @@
local i_o = require 'i_o' local i_o = require 'i_o'
local compile = require 'compile'
local pure = require 'pure' local pure = require 'pure'
local impure = require 'impure' local impure = require 'impure'
@ -19,7 +18,7 @@ return function(config, main_state, common, width, point)
common.text_row_set(obj, (pid == '') and 'Error' or 'Running') common.text_row_set(obj, (pid == '') and 'Error' or 'Running')
end end
end end
return compile.mk_acc( return common.mk_acc(
width, width,
0, 0,
update, update,
@ -28,7 +27,7 @@ return function(config, main_state, common, width, point)
) )
end end
local mk_sep = pure.partial(compile.mk_seperator, common, width, point.x) local mk_sep = pure.partial(common.mk_seperator, width, point.x)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- filesystem bar chart -- filesystem bar chart
@ -58,7 +57,7 @@ return function(config, main_state, common, width, point)
impure.ieach(read_fs, CONKY_CMDS) impure.ieach(read_fs, CONKY_CMDS)
end end
end end
return compile.mk_acc( return common.mk_acc(
width, width,
(#config.fs_paths - 1) * SPACING, (#config.fs_paths - 1) * SPACING,
update, update,
@ -70,12 +69,11 @@ return function(config, main_state, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
return compile.compile_module( return common.compile_module(
common,
'FILE SYSTEMS', 'FILE SYSTEMS',
point, point,
width, width,
{{mk_smart, config.show_smart, SEPARATOR_SPACING}}, {{mk_smart, config.show_smart, SEPARATOR_SPACING}},
compile.mk_section(SEPARATOR_SPACING, mk_sep, {mk_bars, true, 0}) common.mk_section(SEPARATOR_SPACING, mk_sep, {mk_bars, true, 0})
) )
end end

View File

@ -1,6 +1,5 @@
local pure = require 'pure' local pure = require 'pure'
local i_o = require 'i_o' local i_o = require 'i_o'
local compile = require 'compile'
return function(update_freq, config, common, width, point) return function(update_freq, config, common, width, point)
local SEPARATOR_SPACING = 20 local SEPARATOR_SPACING = 20
@ -41,7 +40,7 @@ return function(update_freq, config, common, width, point)
) )
local static = pure.partial(common.tagged_percent_timeseries_draw_static, obj) local static = pure.partial(common.tagged_percent_timeseries_draw_static, obj)
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, obj) local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, obj)
return compile.mk_acc( return common.mk_acc(
width, width,
PLOT_HEIGHT + PLOT_SEC_BREAK, PLOT_HEIGHT + PLOT_SEC_BREAK,
update, update,
@ -69,12 +68,11 @@ return function(update_freq, config, common, width, point)
end end
local static = pure.partial(common.text_row_draw_static, obj) local static = pure.partial(common.text_row_draw_static, obj)
local dynamic = pure.partial(common.text_row_draw_dynamic, obj) local dynamic = pure.partial(common.text_row_draw_dynamic, obj)
return compile.mk_acc(width, 0, update, static, dynamic) return common.mk_acc(width, 0, update, static, dynamic)
end end
local mk_sep = pure.partial( local mk_sep = pure.partial(
compile.mk_seperator, common.mk_seperator,
common,
width, width,
point.x point.x
) )
@ -100,7 +98,7 @@ return function(update_freq, config, common, width, point)
) )
local static = pure.partial(common.threshold_text_row_draw_static, obj) local static = pure.partial(common.threshold_text_row_draw_static, obj)
local dynamic = pure.partial(common.threshold_text_row_draw_dynamic, obj) local dynamic = pure.partial(common.threshold_text_row_draw_dynamic, obj)
return compile.mk_acc(width, 0, update, static, dynamic) return common.mk_acc(width, 0, update, static, dynamic)
end end
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@ -125,7 +123,7 @@ return function(update_freq, config, common, width, point)
end end
local static = pure.partial(common.text_rows_draw_static, obj) local static = pure.partial(common.text_rows_draw_static, obj)
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj) local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
return compile.mk_acc(width, TEXT_SPACING, update, static, dynamic) return common.mk_acc(width, TEXT_SPACING, update, static, dynamic)
end end
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@ -217,23 +215,22 @@ return function(update_freq, config, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main drawing functions -- main drawing functions
local rbs = compile.compile_module( local rbs = common.compile_module(
common,
'NVIDIA GRAPHICS', 'NVIDIA GRAPHICS',
point, point,
width, width,
{{mk_status, true, SEPARATOR_SPACING}}, {{mk_status, true, SEPARATOR_SPACING}},
compile.mk_section( common.mk_section(
SEPARATOR_SPACING, SEPARATOR_SPACING,
mk_sep, mk_sep,
{mk_temp, config.show_temp, SEPARATOR_SPACING} {mk_temp, config.show_temp, SEPARATOR_SPACING}
), ),
compile.mk_section( common.mk_section(
SEPARATOR_SPACING, SEPARATOR_SPACING,
mk_sep, mk_sep,
{mk_clock, config.show_clock, SEPARATOR_SPACING} {mk_clock, config.show_clock, SEPARATOR_SPACING}
), ),
compile.mk_section( common.mk_section(
SEPARATOR_SPACING, SEPARATOR_SPACING,
mk_sep, mk_sep,
{mk_gpu_util, config.show_gpu_util, PLOT_SEC_BREAK}, {mk_gpu_util, config.show_gpu_util, PLOT_SEC_BREAK},

View File

@ -2,7 +2,6 @@ local timeseries = require 'timeseries'
local text_table = require 'text_table' local text_table = require 'text_table'
local i_o = require 'i_o' local i_o = require 'i_o'
local pure = require 'pure' local pure = require 'pure'
local compile = require 'compile'
return function(update_freq, config, common, width, point) return function(update_freq, config, common, width, point)
local DIAL_THICKNESS = 8 local DIAL_THICKNESS = 8
@ -78,7 +77,7 @@ return function(update_freq, config, common, width, point)
common.dial_draw_dynamic(swap, cr) common.dial_draw_dynamic(swap, cr)
common.text_rows_draw_dynamic(cache, cr) common.text_rows_draw_dynamic(cache, cr)
end end
return compile.mk_acc(width, DIAL_DIAMETER, update, static, dynamic) return common.mk_acc(width, DIAL_DIAMETER, update, static, dynamic)
end end
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
@ -92,7 +91,7 @@ return function(update_freq, config, common, width, point)
PLOT_HEIGHT, PLOT_HEIGHT,
update_freq update_freq
) )
return compile.mk_acc( return common.mk_acc(
width, width,
PLOT_HEIGHT, PLOT_HEIGHT,
function(s) timeseries.update(obj, s.mem.used_percent) end, function(s) timeseries.update(obj, s.mem.used_percent) end,
@ -130,7 +129,7 @@ return function(update_freq, config, common, width, point)
text_table.set(obj, 3, r, i_o.conky(TABLE_CONKY[r].mem)) text_table.set(obj, 3, r, i_o.conky(TABLE_CONKY[r].mem))
end end
end end
return compile.mk_acc( return common.mk_acc(
width, width,
TABLE_HEIGHT, TABLE_HEIGHT,
update, update,
@ -179,8 +178,7 @@ return function(update_freq, config, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
local rbs = compile.compile_module( local rbs = common.compile_module(
common,
'MEMORY', 'MEMORY',
point, point,
width, width,

View File

@ -2,7 +2,6 @@ local format = require 'format'
local pure = require 'pure' local pure = require 'pure'
local i_o = require 'i_o' local i_o = require 'i_o'
local sys = require 'sys' local sys = require 'sys'
local compile = require 'compile'
return function(update_freq, common, width, point) return function(update_freq, common, width, point)
local PLOT_SEC_BREAK = 20 local PLOT_SEC_BREAK = 20
@ -51,7 +50,7 @@ return function(update_freq, common, width, point)
update_freq, update_freq,
state[key] state[key]
) )
return compile.mk_acc( return common.mk_acc(
width, width,
PLOT_HEIGHT + PLOT_SEC_BREAK, PLOT_HEIGHT + PLOT_SEC_BREAK,
function(s) common.update_rate_timeseries(obj, s[key]) end, function(s) common.update_rate_timeseries(obj, s[key]) end,
@ -66,8 +65,7 @@ return function(update_freq, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main drawing functions -- main drawing functions
local rbs = compile.compile_module( local rbs = common.compile_module(
common,
'NETWORK', 'NETWORK',
point, point,
width, width,

View File

@ -1,4 +1,3 @@
local compile = require 'compile'
local pure = require 'pure' local pure = require 'pure'
return function(main_state, common, width, point) return function(main_state, common, width, point)
@ -32,7 +31,7 @@ return function(main_state, common, width, point)
end end
end end
end end
return compile.mk_acc( return common.mk_acc(
width, width,
TEXT_SPACING * 4, TEXT_SPACING * 4,
update, update,
@ -41,8 +40,7 @@ return function(main_state, common, width, point)
) )
end end
return compile.compile_module( return common.compile_module(
common,
'PACMAN', 'PACMAN',
point, point,
width, width,

View File

@ -1,6 +1,5 @@
local format = require 'format' local format = require 'format'
local pure = require 'pure' local pure = require 'pure'
local compile = require 'compile'
local sys = require 'sys' local sys = require 'sys'
return function(update_freq, config, common, width, point) return function(update_freq, config, common, width, point)
@ -40,7 +39,7 @@ return function(update_freq, config, common, width, point)
update_freq, update_freq,
read_joules() read_joules()
) )
return compile.mk_acc( return common.mk_acc(
width, width,
PLOT_HEIGHT + PLOT_SEC_BREAK, PLOT_HEIGHT + PLOT_SEC_BREAK,
function(_) common.update_rate_timeseries(obj, read_joules()) end, function(_) common.update_rate_timeseries(obj, read_joules()) end,
@ -89,7 +88,7 @@ return function(update_freq, config, common, width, point)
0, 0,
update_freq update_freq
) )
return compile.mk_acc( return common.mk_acc(
width, width,
PLOT_HEIGHT + PLOT_SEC_BREAK, PLOT_HEIGHT + PLOT_SEC_BREAK,
function() function()
@ -106,8 +105,7 @@ return function(update_freq, config, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
return compile.compile_module( return common.compile_module(
common,
'POWER', 'POWER',
point, point,
width, width,

View File

@ -1,7 +1,6 @@
local compound_dial = require 'compound_dial' local compound_dial = require 'compound_dial'
local text_table = require 'text_table' local text_table = require 'text_table'
local i_o = require 'i_o' local i_o = require 'i_o'
local compile = require 'compile'
local cpu = require 'sys' local cpu = require 'sys'
local pure = require 'pure' local pure = require 'pure'
@ -91,7 +90,7 @@ return function(update_freq, config, main_state, common, width, point)
compound_dial.draw_dynamic(cores[i].loads, cr) compound_dial.draw_dynamic(cores[i].loads, cr)
end end
end end
return compile.mk_acc( return common.mk_acc(
width, width,
DIAL_OUTER_RADIUS * 2, DIAL_OUTER_RADIUS * 2,
update, update,
@ -123,7 +122,7 @@ return function(update_freq, config, main_state, common, width, point)
end end
local static = pure.partial(common.text_rows_draw_static, cpu_status) local static = pure.partial(common.text_rows_draw_static, cpu_status)
local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status) local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status)
return compile.mk_acc( return common.mk_acc(
width, width,
TEXT_SPACING, TEXT_SPACING,
update, update,
@ -136,8 +135,7 @@ return function(update_freq, config, main_state, common, width, point)
-- frequency -- frequency
local mk_sep = pure.partial( local mk_sep = pure.partial(
compile.mk_seperator, common.mk_seperator,
common,
width, width,
point.x point.x
) )
@ -164,7 +162,7 @@ return function(update_freq, config, main_state, common, width, point)
end end
local static = pure.partial(common.tagged_percent_timeseries_draw_static, total_load) local static = pure.partial(common.tagged_percent_timeseries_draw_static, total_load)
local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, total_load) local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, total_load)
return compile.mk_acc( return common.mk_acc(
width, width,
PLOT_HEIGHT + PLOT_SECTION_BREAK, PLOT_HEIGHT + PLOT_SECTION_BREAK,
update, update,
@ -203,7 +201,7 @@ return function(update_freq, config, main_state, common, width, point)
end end
local static = pure.partial(text_table.draw_static, tbl) local static = pure.partial(text_table.draw_static, tbl)
local dynamic = pure.partial(text_table.draw_dynamic, tbl) local dynamic = pure.partial(text_table.draw_dynamic, tbl)
return compile.mk_acc( return common.mk_acc(
width, width,
TABLE_HEIGHT, TABLE_HEIGHT,
update, update,
@ -215,8 +213,7 @@ return function(update_freq, config, main_state, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
local rbs = compile.compile_module( local rbs = common.compile_module(
common,
'PROCESSOR', 'PROCESSOR',
point, point,
width, width,
@ -224,7 +221,7 @@ return function(update_freq, config, main_state, common, width, point)
{mk_cores, config.show_cores, TEXT_SPACING}, {mk_cores, config.show_cores, TEXT_SPACING},
{mk_hwp_freq, config.show_stats, SEPARATOR_SPACING}, {mk_hwp_freq, config.show_stats, SEPARATOR_SPACING},
}, },
compile.mk_section( common.mk_section(
SEPARATOR_SPACING, SEPARATOR_SPACING,
mk_sep, mk_sep,
{mk_load_plot, config.show_plot, TABLE_SECTION_BREAK}, {mk_load_plot, config.show_plot, TABLE_SECTION_BREAK},

View File

@ -1,6 +1,5 @@
local format = require 'format' local format = require 'format'
local pure = require 'pure' local pure = require 'pure'
local compile = require 'compile'
local sys = require 'sys' local sys = require 'sys'
return function(update_freq, config, common, width, point) return function(update_freq, config, common, width, point)
@ -34,7 +33,7 @@ return function(update_freq, config, common, width, point)
update_freq, update_freq,
state[key] state[key]
) )
return compile.mk_acc( return common.mk_acc(
-- TODO construct this more sanely without referring to hardcoded vars -- TODO construct this more sanely without referring to hardcoded vars
width, width,
PLOT_HEIGHT + PLOT_SEC_BREAK, PLOT_HEIGHT + PLOT_SEC_BREAK,
@ -50,8 +49,7 @@ return function(update_freq, config, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main drawing functions -- main drawing functions
local rbs = compile.compile_module( local rbs = common.compile_module(
common,
'INPUT / OUTPUT', 'INPUT / OUTPUT',
point, point,
width, width,

View File

@ -1,6 +1,5 @@
local i_o = require 'i_o' local i_o = require 'i_o'
local pure = require 'pure' local pure = require 'pure'
local compile = require 'compile'
return function(main_state, common, width, point) return function(main_state, common, width, point)
local TEXT_SPACING = 20 local TEXT_SPACING = 20
@ -31,7 +30,7 @@ return function(main_state, common, width, point)
end end
local static = pure.partial(common.text_rows_draw_static, obj) local static = pure.partial(common.text_rows_draw_static, obj)
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj) local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)
return compile.mk_acc( return common.mk_acc(
width, width,
TEXT_SPACING * 3, TEXT_SPACING * 3,
update, update,
@ -40,5 +39,5 @@ return function(main_state, common, width, point)
) )
end end
return compile.compile_module(common, 'SYSTEM', point, width, {{mk_stats, true, 0}}) return common.compile_module('SYSTEM', point, width, {{mk_stats, true, 0}})
end end