From aebb40db591d31ba025e4e656a8b4c3bfdcf72e1 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 17 Jul 2022 19:12:31 -0400 Subject: [PATCH] REF pass table instead of compiled functions from modules --- drawing/compile.lua | 13 ++++++++++--- drawing/filesystem.lua | 13 +++++++------ drawing/graphics.lua | 14 +++++++------- drawing/memory.lua | 14 +++++++------- drawing/network.lua | 15 +++++++-------- drawing/pacman.lua | 13 +++++++------ drawing/power.lua | 13 +++++++------ drawing/processor.lua | 29 ++++++++++++----------------- drawing/readwrite.lua | 24 ++++++++++-------------- drawing/system.lua | 8 +++++++- 10 files changed, 81 insertions(+), 75 deletions(-) diff --git a/drawing/compile.lua b/drawing/compile.lua index a6d40d4..b2e09c8 100644 --- a/drawing/compile.lua +++ b/drawing/compile.lua @@ -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 diff --git a/drawing/filesystem.lua b/drawing/filesystem.lua index b241c6e..7ab8c94 100644 --- a/drawing/filesystem.lua +++ b/drawing/filesystem.lua @@ -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 diff --git a/drawing/graphics.lua b/drawing/graphics.lua index b813c07..2f46db9 100644 --- a/drawing/graphics.lua +++ b/drawing/graphics.lua @@ -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 diff --git a/drawing/memory.lua b/drawing/memory.lua index bccda8f..d1276d2 100644 --- a/drawing/memory.lua +++ b/drawing/memory.lua @@ -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 diff --git a/drawing/network.lua b/drawing/network.lua index 0711f4c..38092b5 100644 --- a/drawing/network.lua +++ b/drawing/network.lua @@ -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 diff --git a/drawing/pacman.lua b/drawing/pacman.lua index b9e8b96..8d84440 100644 --- a/drawing/pacman.lua +++ b/drawing/pacman.lua @@ -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 diff --git a/drawing/power.lua b/drawing/power.lua index 7bb8729..6c62b1b 100644 --- a/drawing/power.lua +++ b/drawing/power.lua @@ -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 diff --git a/drawing/processor.lua b/drawing/processor.lua index 0097158..4f4887a 100644 --- a/drawing/processor.lua +++ b/drawing/processor.lua @@ -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 diff --git a/drawing/readwrite.lua b/drawing/readwrite.lua index 4153bff..fcbe0a1 100644 --- a/drawing/readwrite.lua +++ b/drawing/readwrite.lua @@ -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 diff --git a/drawing/system.lua b/drawing/system.lua index 5a763f7..506cb91 100644 --- a/drawing/system.lua +++ b/drawing/system.lua @@ -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