REF pass table instead of compiled functions from modules

This commit is contained in:
Nathan Dwarshuis 2022-07-17 19:12:31 -04:00
parent 4094d754f1
commit aebb40db59
10 changed files with 81 additions and 75 deletions

View File

@ -3,7 +3,6 @@ local M = {}
local pure = require 'pure' local pure = require 'pure'
local geom = require 'geom' local geom = require 'geom'
local fill_rect = require 'fill_rect' local fill_rect = require 'fill_rect'
local line = require 'line'
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- compile entire layout -- compile entire layout
@ -12,8 +11,16 @@ local reduce_modules_y = function(common, modlist, init_x, width, acc, new)
if type(new) == "number" then if type(new) == "number" then
acc.next_y = acc.next_y + new acc.next_y = acc.next_y + new
else else
print(new) -- gross...
local r = modlist[new](common, width, geom.make_point(init_x, acc.next_y)) local m = modlist[new](common, width, geom.make_point(init_x, acc.next_y))
local secs = {}
for i = 1, #m do
secs[i] = m[i]
end
local r = common.compile_module(m.header, m.point, m.width, m.top, table.unpack(secs))
if m.update_wrapper ~= nil then
r = pure.map_at("update", m.update_wrapper, r)
end
table.insert(acc.fgroups, {update = r.update, static = r.static, dynamic = r.dynamic}) 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_x = math.max(acc.next_x, r.next_x)
acc.next_y = r.next_y acc.next_y = r.next_y

View File

@ -69,11 +69,12 @@ return function(config, main_state, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
return common.compile_module( return {
'FILE SYSTEMS', header = 'FILE SYSTEMS',
point, point = point,
width, width = width,
{{mk_smart, config.show_smart, SEPARATOR_SPACING}}, update_wrapper = nil,
top = {{mk_smart, config.show_smart, SEPARATOR_SPACING}},
common.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

@ -215,11 +215,12 @@ return function(update_freq, config, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main drawing functions -- main drawing functions
local rbs = common.compile_module( return {
'NVIDIA GRAPHICS', header = 'NVIDIA GRAPHICS',
point, point = point,
width, width = width,
{{mk_status, true, SEPARATOR_SPACING}}, update_wrapper = function(f) return function(_) f(update_state()) end end,
top = {{mk_status, true, SEPARATOR_SPACING}},
common.mk_section( common.mk_section(
SEPARATOR_SPACING, SEPARATOR_SPACING,
mk_sep, mk_sep,
@ -237,6 +238,5 @@ return function(update_freq, config, common, width, point)
{mk_mem_util, config.show_mem_util, PLOT_SEC_BREAK}, {mk_mem_util, config.show_mem_util, PLOT_SEC_BREAK},
{mk_vid_util, config.show_vid_util, 0} {mk_vid_util, config.show_vid_util, 0}
) )
) }
return pure.map_at("update", function(f) return function(_) f(update_state()) end end, rbs)
end end

View File

@ -178,15 +178,15 @@ return function(update_freq, config, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
local rbs = common.compile_module( return {
'MEMORY', header = 'MEMORY',
point, point = point,
width, width = width,
{ update_wrapper = function(f) return function(_) f(read_state()) end end,
top = {
{mk_stats, config.show_stats, PLOT_SECTION_BREAK}, {mk_stats, config.show_stats, PLOT_SECTION_BREAK},
{mk_plot, config.show_plot, TABLE_SECTION_BREAK}, {mk_plot, config.show_plot, TABLE_SECTION_BREAK},
{mk_tbl, config.show_table, 0}, {mk_tbl, config.show_table, 0},
} }
) }
return pure.map_at("update", function(f) return function(_) f(read_state()) end end, rbs)
end end

View File

@ -65,15 +65,14 @@ return function(update_freq, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main drawing functions -- main drawing functions
local rbs = common.compile_module( return {
'NETWORK', header = 'NETWORK',
point, point = point,
width, width = width,
{ update_wrapper = function(f) return function(_) f(read_interfaces()) end end,
top = {
{mk_rx, true, PLOT_SEC_BREAK}, {mk_rx, true, PLOT_SEC_BREAK},
{mk_tx, true, 0}, {mk_tx, true, 0},
} }
) }
return pure.map_at("update", function(f) return function(_) f(read_interfaces()) end end, rbs)
end end

View File

@ -40,10 +40,11 @@ return function(main_state, common, width, point)
) )
end end
return common.compile_module( return {
'PACMAN', header = 'PACMAN',
point, point = point,
width, width = width,
{{mk_stats, true, 0}} update_wrapper = nil,
) top = {{mk_stats, true, 0}}
}
end end

View File

@ -105,14 +105,15 @@ return function(update_freq, config, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
return common.compile_module( return {
'POWER', header = 'POWER',
point, point = point,
width, width = width,
pure.concat( update_wrapper = nil,
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? -- TODO what happens if this is nil?
{{mk_bat, config.battery ~= nil, 0}} {{mk_bat, config.battery ~= nil, 0}}
) )
) }
end end

View File

@ -213,11 +213,17 @@ return function(update_freq, config, main_state, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main functions -- main functions
local rbs = common.compile_module( return {
'PROCESSOR', header = 'PROCESSOR',
point, point = point,
width, width = width,
{ update_wrapper = function(f)
return function()
update_state()
f()
end
end,
top = {
{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},
}, },
@ -227,16 +233,5 @@ return function(update_freq, config, main_state, common, width, point)
{mk_load_plot, config.show_plot, TABLE_SECTION_BREAK}, {mk_load_plot, config.show_plot, TABLE_SECTION_BREAK},
{mk_tbl, config.show_table, 0} {mk_tbl, config.show_table, 0}
) )
) }
return pure.map_at(
"update",
function(f)
return function()
update_state()
f()
end
end,
rbs
)
end end

View File

@ -49,23 +49,19 @@ return function(update_freq, config, common, width, point)
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- main drawing functions -- main drawing functions
local rbs = common.compile_module( return {
'INPUT / OUTPUT', header = 'INPUT / OUTPUT',
point, point = point,
width, width = width,
{ update_wrapper = function(f)
{mk_reads, true, PLOT_SEC_BREAK},
{mk_writes, true, 0},
}
)
return pure.map_at(
"update",
function(f)
return function(_) return function(_)
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS) state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
f() f()
end end
end, end,
rbs) top = {
{mk_reads, true, PLOT_SEC_BREAK},
{mk_writes, true, 0},
}
}
end end

View File

@ -39,5 +39,11 @@ return function(main_state, common, width, point)
) )
end end
return common.compile_module('SYSTEM', point, width, {{mk_stats, true, 0}}) return {
header = 'SYSTEM',
point = point,
width = width,
update_wrapper = nil,
top = {{mk_stats, true, 0}}
}
end end