From fb79ea899d300a4781af73aa5a4f743048f64f98 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 16 Aug 2022 00:14:04 -0400 Subject: [PATCH] ENH modularize module geometries --- config/config.dhall | 77 +++++++++++++++++++++----------------- src/modules/filesystem.lua | 7 ++-- src/modules/memory.lua | 5 +-- src/modules/power.lua | 3 +- src/modules/processor.lua | 19 +++++----- 5 files changed, 59 insertions(+), 52 deletions(-) diff --git a/config/config.dhall b/config/config.dhall index 3553441..abf01c6 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -6,9 +6,45 @@ let Margin = Vector2 Natural let FSPath = { name : Text, path : Text } +let TextGeo = { Type = { text_spacing : Natural }, default.text_spacing = 20 } + +let SepGeo = { Type = { sep_spacing : Natural }, default.sep_spacing = 20 } + +let PlotGeo_ = + { Type = { sec_break : Natural, height : Natural } + , default = { sec_break = 20, height = 56 } + } + +let PlotGeo = { Type = { plot : PlotGeo_.Type }, default.plot = PlotGeo_::{=} } + +let TableGeo_ = { Type = { sec_break : Natural }, default.sec_break = 20 } + +let TableGeo = + { Type = { table : TableGeo_.Type }, default.table = TableGeo_::{=} } + let FSGeo = - { Type = { spacing : Natural, bar_pad : Natural, sep_spacing : Natural } - , default = { spacing = 20, bar_pad = 100, sep_spacing = 20 } + { Type = { bar_spacing : Natural, bar_pad : Natural } //\\ SepGeo.Type + , default = { bar_spacing = 20, bar_pad = 100 } /\ SepGeo::{=} + } + +let GfxGeo = + { Type = SepGeo.Type //\\ PlotGeo.Type //\\ TextGeo.Type + , default = SepGeo::{=} /\ PlotGeo::{=} /\ TextGeo::{=} + } + +let MemGeo = + { Type = TextGeo.Type //\\ PlotGeo.Type //\\ TableGeo.Type + , default = TextGeo::{=} /\ PlotGeo::{=} /\ TableGeo::{=} + } + +let ProcGeo = + { Type = GfxGeo.Type //\\ TableGeo.Type + , default = GfxGeo::{=} /\ TableGeo::{=} + } + +let PwrGeo = + { Type = TextGeo.Type //\\ PlotGeo.Type + , default = TextGeo::{=} /\ PlotGeo::{=} } let FileSystem = @@ -17,17 +53,6 @@ let FileSystem = , default.geometry = FSGeo::{=} } -let PlotGeo = - { Type = { sec_break : Natural, height : Natural } - , default = { sec_break = 20, height = 56 } - } - -let GfxGeo = - { Type = - { sep_spacing : Natural, text_spacing : Natural, plot : PlotGeo.Type } - , default = { sep_spacing = 20, text_spacing = 20, plot = PlotGeo::{=} } - } - let Graphics = { Type = { dev_power : Text @@ -41,11 +66,6 @@ let Graphics = , default.geometry = GfxGeo::{=} } -let MemGeo = - { Type = { text_spacing : Natural, plot : PlotGeo.Type } - , default = { plot = PlotGeo::{=}, text_spacing = 20 } - } - let Memory = { Type = { show_stats : Bool @@ -58,11 +78,7 @@ let Memory = } let Network = - { Type = { geometry : { plot : PlotGeo.Type } } - , default.geometry.plot = PlotGeo::{=} - } - -let ProcGeo = { Type = { plot : PlotGeo.Type }, default.plot = PlotGeo::{=} } + { Type = { geometry : PlotGeo.Type }, default.geometry = PlotGeo::{=} } let Processor = { Type = @@ -78,15 +94,8 @@ let Processor = let RaplSpec = { name : Text, address : Text } -let PwrGeo = - { Type = { text_spacing : Natural, plot : PlotGeo.Type } - , default = { text_spacing = 20, plot = PlotGeo::{=} } - } - let Pacman = - { Type = { geometry : { text_spacing : Natural } } - , default.geometry.text_spacing = 20 - } + { Type = { geometry : TextGeo.Type }, default.geometry = TextGeo::{=} } let Power = { Type = @@ -94,11 +103,9 @@ let Power = , default.geometry = PwrGeo::{=} } -let RWGeo = { Type = { plot : PlotGeo.Type }, default.plot = PlotGeo::{=} } - let ReadWrite = - { Type = { devices : List Text, geometry : RWGeo.Type } - , default.geometry = RWGeo::{=} + { Type = { devices : List Text, geometry : PlotGeo.Type } + , default.geometry = PlotGeo::{=} } let System = Pacman diff --git a/src/modules/filesystem.lua b/src/modules/filesystem.lua index c6bfa3a..61cf74b 100644 --- a/src/modules/filesystem.lua +++ b/src/modules/filesystem.lua @@ -4,8 +4,7 @@ local impure = require 'impure' return function(main_state, config, common, width, point) local geo = config.geometry - local SPACING = geo.spacing - local BAR_PAD = geo.bar_pad + local SPACING = geo.bar_spacing local SEPARATOR_SPACING = geo.sep_spacing ----------------------------------------------------------------------------- @@ -47,7 +46,9 @@ return function(main_state, config, common, width, point) point.x, y, width, - BAR_PAD, + -- TODO this isn't actually padding, it would be padding if it was + -- relative to the right edge of the text column + geo.bar_pad, names, SPACING, 12, diff --git a/src/modules/memory.lua b/src/modules/memory.lua index bcd882e..c898c2a 100644 --- a/src/modules/memory.lua +++ b/src/modules/memory.lua @@ -11,10 +11,9 @@ return function(update_freq, config, common, width, point) local DIAL_X_SPACING = 40 local CACHE_Y_OFFSET = 7 local CACHE_X_OFFSET = 50 - local TEXT_SPACING = geo.text_spacing local PLOT_SECTION_BREAK = geo.plot.sec_break local PLOT_HEIGHT = geo.plot.height - local TABLE_SECTION_BREAK = 20 + local TABLE_SECTION_BREAK = geo.table.sec_break local __math_floor = math.floor local __string_format = string.format @@ -77,7 +76,7 @@ return function(update_freq, config, common, width, point) CACHE_X, y + CACHE_Y_OFFSET, CACHE_WIDTH, - TEXT_SPACING, + geo.text_spacing, {'Page Cache', 'Buffers', 'Shared', 'Kernel Slab'}, '%.1f%%' ) diff --git a/src/modules/power.lua b/src/modules/power.lua index 4324663..a8da106 100644 --- a/src/modules/power.lua +++ b/src/modules/power.lua @@ -4,7 +4,6 @@ local sys = require 'sys' return function(update_freq, config, common, width, point) local geo = config.geometry - local TEXT_SPACING = geo.text_spacing local PLOT_SEC_BREAK = geo.plot.sec_break local PLOT_HEIGHT = geo.plot.height @@ -51,7 +50,7 @@ return function(update_freq, config, common, width, point) local mk_rate_blockspec = function(spec) local f = pure.partial(mk_rate_plot, spec.name, spec.address) - return {f, true, TEXT_SPACING} + return {f, true, geo.text_spacing} end ----------------------------------------------------------------------------- diff --git a/src/modules/processor.lua b/src/modules/processor.lua index 7ed6bce..02d38d9 100644 --- a/src/modules/processor.lua +++ b/src/modules/processor.lua @@ -7,15 +7,16 @@ local pure = require 'pure' local __math_floor = math.floor return function(update_freq, main_state, config, common, width, point) + local geo = config.geometry local DIAL_INNER_RADIUS = 30 local DIAL_OUTER_RADIUS = 42 local DIAL_THICKNESS = 5.5 - local DIAL_SPACING = 20 - local SEPARATOR_SPACING = 20 - local TEXT_SPACING = 22 - local PLOT_SECTION_BREAK = 23 - local PLOT_HEIGHT = 56 - local TABLE_SECTION_BREAK = 20 + local DIAL_Y_SPACING = 20 + local SEPARATOR_SPACING = geo.sep_spacing + local TEXT_SPACING = geo.text_spacing + local PLOT_SECTION_BREAK = geo.plot.sec_break + local PLOT_HEIGHT = geo.plot.height + local TABLE_SECTION_BREAK = geo.table.sec_break ----------------------------------------------------------------------------- -- processor state @@ -55,7 +56,7 @@ return function(update_freq, main_state, config, common, width, point) (width - 2 * (DIAL_OUTER_RADIUS + config.core_padding)) * math.fmod(c - 1, core_cols) / (core_cols - 1))) local dial_y = y + DIAL_OUTER_RADIUS + - (2 * DIAL_OUTER_RADIUS + DIAL_SPACING) + (2 * DIAL_OUTER_RADIUS + DIAL_Y_SPACING) * math.floor((c - 1) / core_cols) return { loads = common.make_compound_dial( @@ -115,8 +116,8 @@ return function(update_freq, main_state, config, common, width, point) end return common.mk_acc( width, - (DIAL_OUTER_RADIUS * 2 + DIAL_SPACING) * config.core_rows - - DIAL_SPACING, + (DIAL_OUTER_RADIUS * 2 + DIAL_Y_SPACING) * config.core_rows + - DIAL_Y_SPACING, update, static, dynamic