REF pass table instead of compiled functions from modules
This commit is contained in:
parent
4094d754f1
commit
aebb40db59
|
@ -3,7 +3,6 @@ local M = {}
|
|||
local pure = require 'pure'
|
||||
local geom = require 'geom'
|
||||
local fill_rect = require 'fill_rect'
|
||||
local line = require 'line'
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- compile entire layout
|
||||
|
@ -12,8 +11,16 @@ 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))
|
||||
-- gross...
|
||||
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})
|
||||
acc.next_x = math.max(acc.next_x, r.next_x)
|
||||
acc.next_y = r.next_y
|
||||
|
|
|
@ -69,11 +69,12 @@ return function(config, main_state, common, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main functions
|
||||
|
||||
return common.compile_module(
|
||||
'FILE SYSTEMS',
|
||||
point,
|
||||
width,
|
||||
{{mk_smart, config.show_smart, SEPARATOR_SPACING}},
|
||||
return {
|
||||
header = 'FILE SYSTEMS',
|
||||
point = point,
|
||||
width = width,
|
||||
update_wrapper = nil,
|
||||
top = {{mk_smart, config.show_smart, SEPARATOR_SPACING}},
|
||||
common.mk_section(SEPARATOR_SPACING, mk_sep, {mk_bars, true, 0})
|
||||
)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -215,11 +215,12 @@ return function(update_freq, config, common, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main drawing functions
|
||||
|
||||
local rbs = common.compile_module(
|
||||
'NVIDIA GRAPHICS',
|
||||
point,
|
||||
width,
|
||||
{{mk_status, true, SEPARATOR_SPACING}},
|
||||
return {
|
||||
header = 'NVIDIA GRAPHICS',
|
||||
point = point,
|
||||
width = width,
|
||||
update_wrapper = function(f) return function(_) f(update_state()) end end,
|
||||
top = {{mk_status, true, SEPARATOR_SPACING}},
|
||||
common.mk_section(
|
||||
SEPARATOR_SPACING,
|
||||
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_vid_util, config.show_vid_util, 0}
|
||||
)
|
||||
)
|
||||
return pure.map_at("update", function(f) return function(_) f(update_state()) end end, rbs)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -178,15 +178,15 @@ return function(update_freq, config, common, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main functions
|
||||
|
||||
local rbs = common.compile_module(
|
||||
'MEMORY',
|
||||
point,
|
||||
width,
|
||||
{
|
||||
return {
|
||||
header = 'MEMORY',
|
||||
point = point,
|
||||
width = width,
|
||||
update_wrapper = function(f) return function(_) f(read_state()) end end,
|
||||
top = {
|
||||
{mk_stats, config.show_stats, PLOT_SECTION_BREAK},
|
||||
{mk_plot, config.show_plot, TABLE_SECTION_BREAK},
|
||||
{mk_tbl, config.show_table, 0},
|
||||
}
|
||||
)
|
||||
return pure.map_at("update", function(f) return function(_) f(read_state()) end end, rbs)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -65,15 +65,14 @@ return function(update_freq, common, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main drawing functions
|
||||
|
||||
local rbs = common.compile_module(
|
||||
'NETWORK',
|
||||
point,
|
||||
width,
|
||||
{
|
||||
return {
|
||||
header = 'NETWORK',
|
||||
point = point,
|
||||
width = width,
|
||||
update_wrapper = function(f) return function(_) f(read_interfaces()) end end,
|
||||
top = {
|
||||
{mk_rx, true, PLOT_SEC_BREAK},
|
||||
{mk_tx, true, 0},
|
||||
}
|
||||
)
|
||||
|
||||
return pure.map_at("update", function(f) return function(_) f(read_interfaces()) end end, rbs)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -40,10 +40,11 @@ return function(main_state, common, width, point)
|
|||
)
|
||||
end
|
||||
|
||||
return common.compile_module(
|
||||
'PACMAN',
|
||||
point,
|
||||
width,
|
||||
{{mk_stats, true, 0}}
|
||||
)
|
||||
return {
|
||||
header = 'PACMAN',
|
||||
point = point,
|
||||
width = width,
|
||||
update_wrapper = nil,
|
||||
top = {{mk_stats, true, 0}}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -105,14 +105,15 @@ return function(update_freq, config, common, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main functions
|
||||
|
||||
return common.compile_module(
|
||||
'POWER',
|
||||
point,
|
||||
width,
|
||||
pure.concat(
|
||||
return {
|
||||
header = 'POWER',
|
||||
point = point,
|
||||
width = width,
|
||||
update_wrapper = 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}}
|
||||
)
|
||||
)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -213,11 +213,17 @@ return function(update_freq, config, main_state, common, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main functions
|
||||
|
||||
local rbs = common.compile_module(
|
||||
'PROCESSOR',
|
||||
point,
|
||||
width,
|
||||
{
|
||||
return {
|
||||
header = 'PROCESSOR',
|
||||
point = point,
|
||||
width = width,
|
||||
update_wrapper = function(f)
|
||||
return function()
|
||||
update_state()
|
||||
f()
|
||||
end
|
||||
end,
|
||||
top = {
|
||||
{mk_cores, config.show_cores, TEXT_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_tbl, config.show_table, 0}
|
||||
)
|
||||
)
|
||||
|
||||
return pure.map_at(
|
||||
"update",
|
||||
function(f)
|
||||
return function()
|
||||
update_state()
|
||||
f()
|
||||
end
|
||||
end,
|
||||
rbs
|
||||
)
|
||||
}
|
||||
end
|
||||
|
|
|
@ -49,23 +49,19 @@ return function(update_freq, config, common, width, point)
|
|||
-----------------------------------------------------------------------------
|
||||
-- main drawing functions
|
||||
|
||||
local rbs = common.compile_module(
|
||||
'INPUT / OUTPUT',
|
||||
point,
|
||||
width,
|
||||
{
|
||||
{mk_reads, true, PLOT_SEC_BREAK},
|
||||
{mk_writes, true, 0},
|
||||
}
|
||||
)
|
||||
|
||||
return pure.map_at(
|
||||
"update",
|
||||
function(f)
|
||||
return {
|
||||
header = 'INPUT / OUTPUT',
|
||||
point = point,
|
||||
width = width,
|
||||
update_wrapper = function(f)
|
||||
return function(_)
|
||||
state.read, state.write = sys.get_total_disk_io(DEVICE_PATHS)
|
||||
f()
|
||||
end
|
||||
end,
|
||||
rbs)
|
||||
top = {
|
||||
{mk_reads, true, PLOT_SEC_BREAK},
|
||||
{mk_writes, true, 0},
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -39,5 +39,11 @@ return function(main_state, common, width, point)
|
|||
)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue