From e290ca79adf1a2a0546dcfcac2de578cb795a484 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Wed, 10 Aug 2022 22:22:50 -0400 Subject: [PATCH 01/11] ADD dhall config --- config/config.dhall | 269 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 269 insertions(+) create mode 100644 config/config.dhall diff --git a/config/config.dhall b/config/config.dhall new file mode 100644 index 0000000..50d46a3 --- /dev/null +++ b/config/config.dhall @@ -0,0 +1,269 @@ +let Vector2 = \(a : Type) -> { x : a, y : a } + +let Point = Vector2 Natural + +let Margin = Vector2 Natural + +let FileSystem = { show_smart : Bool, paths : List Text } + +let Graphics = + { dev_power : Text + , show_temp : Bool + , show_clock : Bool + , show_gpu_util : Bool + , show_mem_util : Bool + , show_vid_util : Bool + } + +let Memory = + { show_stats : Bool + , show_plot : Bool + , show_swap : Bool + , table_rows : Natural + } + +let Processor = + { core_rows : Natural + , core_padding : Natural + , show_stats : Bool + , show_plot : Bool + , table_rows : Natural + } + +let RaplSpec = { name : Text, address : Text } + +let Power = { battery : Text, rapl_specs : List RaplSpec } + +let ReadWrite = { devices : List Text } + +let Modules = + { Type = + { filesystem : Optional FileSystem + , graphics : Optional Graphics + , memory : Optional Memory + , processor : Optional Processor + , power : Optional Power + , readwrite : Optional ReadWrite + } + , default = + { filesystem = None FileSystem + , graphics = None Graphics + , memory = None Memory + , processor = None Processor + , power = None Power + , readwrite = None ReadWrite + } + } + +let ModType = + < FileSystem + | Graphics + | Memory + | Network + | Pacman + | Processor + | ReadWrite + | System + > + +let Block = < Pad : Natural | Mod : ModType > + +let Column = { blocks : List Block, width : Natural } + +let Panel = { columns : List Column, margins : Margin } + +let Layout = { anchor : Point, panels : List Panel } + +let Sizes = + { Type = + { normal : Natural + , plot_label : Natural + , table : Natural + , header : Natural + } + , default = { normal = 13, plot_label = 8, table = 11, header = 15 } + } + +let Font = + { Type = { family : Text, sizes : Sizes.Type } + , default = { family = "Neuropolitical", sizes = Sizes::{=} } + } + +let PlotGeometry = + { Type = + { spacing : Natural + , height : Natural + , seconds : Natural + , ticks : Vector2 Natural + } + , default = + { seconds = 90, ticks = { x = 9, y = 4 }, height = 56, spacing = 20 } + } + +let TableGeometry = + { Type = + { name_chars : Natural + , padding : Margin + , header_padding : Natural + , row_spacing : Natural + } + , default = + { name_chars = 8 + , padding = { x = 6, y = 15 } + , header_padding = 20 + , row_spacing = 13 + } + } + +let HeaderGeometry = + { Type = { underline_offset : Natural, padding : Natural } + , default = { underline_offset = 26, padding = 19 } + } + +let Geometry = + { Type = + { plot : PlotGeometry.Type + , table : TableGeometry.Type + , header : HeaderGeometry.Type + } + , default = + { plot = PlotGeometry::{=} + , table = TableGeometry::{=} + , header = HeaderGeometry::{=} + } + } + +let StopRGB = { color : Natural, stop : Double } + +let StopRGBA = { color : Natural, stop : Double, alpha : Double } + +let ColorAlpha = { color : Natural, alpha : Double } + +let Pattern = + < RGB : Natural + | RGBA : ColorAlpha + | GradientRGB : List StopRGB + | GradientRGBA : List StopRGBA + > + +let Patterns = + { Type = + { header : Pattern + , panel : { bg : Pattern } + , text : { active : Pattern, inactive : Pattern, critical : Pattern } + , border : Pattern + , plot : + { grid : Pattern + , outline : Pattern + , data : { border : Pattern, fill : Pattern } + } + , indicator : + { bg : Pattern, fg : { active : Pattern, inactive : Pattern } } + } + , default = + { header = Pattern.RGB 0xefefef + , panel.bg = Pattern.RGBA { color = 0x121212, alpha = 0.7 } + , text = + { active = Pattern.RGB 0xbfe1ff + , inactive = Pattern.RGB 0xc8c8c8 + , critical = Pattern.RGB 0xff8282 + } + , border = Pattern.RGB 0x888888 + , plot = + { grid = Pattern.RGB 0x666666 + , outline = Pattern.RGB 0x777777 + , data = + { border = + Pattern.GradientRGB + [ { color = 0x003f7c, stop = 0.0 } + , { color = 0x1e90ff, stop = 1.0 } + ] + , fill = + Pattern.GradientRGBA + [ { color = 0x316ece, stop = 0.2, alpha = 0.5 } + , { color = 0x8cc7ff, stop = 1.0, alpha = 1.0 } + ] + } + } + , indicator = + { bg = + Pattern.GradientRGB + [ { color = 0x565656, stop = 0.0 } + , { color = 0xbfbfbf, stop = 0.5 } + , { color = 0x565656, stop = 1.0 } + ] + , fg = + { active = + Pattern.GradientRGB + [ { color = 0x316BA6, stop = 0.0 } + , { color = 0x99CEFF, stop = 0.5 } + , { color = 0x316BA6, stop = 1.0 } + ] + , inactive = + Pattern.GradientRGB + [ { color = 0xFF3333, stop = 0.0 } + , { color = 0xFFB8B8, stop = 0.5 } + , { color = 0xFF3333, stop = 1.0 } + ] + } + } + } + } + +let Theme = + { Type = + { font : Font.Type + , geometry : Geometry.Type + , patterns : Patterns.Type + } + , default = + { font = Font::{=}, geometry = Geometry::{=}, patterns = Patterns::{=} } + } + +let layout = + { anchor = { x = 12, y = 11 } + , panels = + [ { columns = + [ { blocks = + [ Block.Mod ModType.Network + , Block.Pad 10 + , Block.Mod ModType.Memory + , Block.Pad 10 + , Block.Mod ModType.Processor + ] + , width = 436 + } + ] + , margins = { x = 20, y = 10 } + } + ] + : List Panel + } + : Layout + +let modules = + Modules::{ + , memory = Some + ( { show_stats = False + , show_swap = False + , show_plot = True + , table_rows = 3 + } + : Memory + ) + , processor = Some + ( { core_rows = 0 + , core_padding = 0 + , show_stats = False + , show_plot = True + , table_rows = 3 + } + : Processor + ) + } + +in { bootstrap = { update_interval = 1, dimensions = { x = 1920, y = 1080 } } + , theme = Theme::{=} + , layout + , modules + } From 0c4172b14909ef9290be1e297bac078da66b656b Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Thu, 11 Aug 2022 00:05:06 -0400 Subject: [PATCH 02/11] ENH update conky to use dhall --- config/config.dhall | 96 +++++++++++++++++++----------------------- config/fallback.dhall | 45 ++++++++++++++++++++ conky.conf | 58 +++++++++++++------------ src/color.lua | 14 ++++-- src/compile.lua | 8 ++-- src/modules/common.lua | 8 ++-- 6 files changed, 139 insertions(+), 90 deletions(-) create mode 100644 config/fallback.dhall diff --git a/config/config.dhall b/config/config.dhall index 50d46a3..7aca51c 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -4,7 +4,9 @@ let Point = Vector2 Natural let Margin = Vector2 Natural -let FileSystem = { show_smart : Bool, paths : List Text } +let FSPath = { name : Text, path : Text } + +let FileSystem = { show_smart : Bool, fs_paths : List FSPath } let Graphics = { dev_power : Text @@ -56,14 +58,14 @@ let Modules = } let ModType = - < FileSystem - | Graphics - | Memory - | Network - | Pacman - | Processor - | ReadWrite - | System + < fileSystem + | graphics + | memory + | network + | pacman + | processor + | readwrite + | system > let Block = < Pad : Natural | Mod : ModType > @@ -220,50 +222,40 @@ let Theme = { font = Font::{=}, geometry = Geometry::{=}, patterns = Patterns::{=} } } -let layout = - { anchor = { x = 12, y = 11 } - , panels = - [ { columns = - [ { blocks = - [ Block.Mod ModType.Network - , Block.Pad 10 - , Block.Mod ModType.Memory - , Block.Pad 10 - , Block.Mod ModType.Processor - ] - , width = 436 - } - ] - , margins = { x = 20, y = 10 } - } - ] - : List Panel - } - : Layout +let Bootstrap = { update_interval : Natural, dimensions : Point } -let modules = - Modules::{ - , memory = Some - ( { show_stats = False - , show_swap = False - , show_plot = True - , table_rows = 3 - } - : Memory - ) - , processor = Some - ( { core_rows = 0 - , core_padding = 0 - , show_stats = False - , show_plot = True - , table_rows = 3 - } - : Processor - ) +let Config = + { bootstrap : Bootstrap + , theme : Theme.Type + , layout : Layout + , modules : Modules.Type } -in { bootstrap = { update_interval = 1, dimensions = { x = 1920, y = 1080 } } - , theme = Theme::{=} - , layout - , modules +let toConfig = + \(i : Natural) -> + \(d : Point) -> + \(t : Theme.Type) -> + \(l : Layout) -> + \(m : Modules.Type) -> + { bootstrap = { update_interval = i, dimensions = d } + , theme = t + , layout = l + , modules = m + } + : Config + +in { toConfig + , Block + , ModType + , Layout + , Panel + , Modules + , FSPath + , FileSystem + , Graphics + , Memory + , Processor + , Power + , ReadWrite + , Theme } diff --git a/config/fallback.dhall b/config/fallback.dhall new file mode 100644 index 0000000..ce9c7e3 --- /dev/null +++ b/config/fallback.dhall @@ -0,0 +1,45 @@ +let C = ./config.dhall + +let layout = + { anchor = { x = 12, y = 11 } + , panels = + [ { columns = + [ { blocks = + [ C.Block.Mod C.ModType.network + , C.Block.Pad 10 + , C.Block.Mod C.ModType.memory + , C.Block.Pad 10 + , C.Block.Mod C.ModType.processor + ] + , width = 436 + } + ] + , margins = { x = 20, y = 10 } + } + ] + : List C.Panel + } + : C.Layout + +let modules = + C.Modules::{ + , memory = Some + ( { show_stats = False + , show_swap = False + , show_plot = True + , table_rows = 3 + } + : C.Memory + ) + , processor = Some + ( { core_rows = 0 + , core_padding = 0 + , show_stats = False + , show_plot = True + , table_rows = 3 + } + : C.Processor + ) + } + +in C.toConfig 1 { x = 1920, y = 1080 } C.Theme::{=} layout modules diff --git a/conky.conf b/conky.conf index 897cd6a..6bed01a 100644 --- a/conky.conf +++ b/conky.conf @@ -55,37 +55,41 @@ package.cpath = conky_dir..'lib/lib/lua/5.4/?.so;' local yaml = require 'lyaml' local i_o = require 'i_o' -local schema_path = conky_dir..'/config/schema.yml' -local validate_config +-- local schema_path = conky_dir..'/config/schema.yml' +-- local validate_config -if i_o.exe_exists('yajsv') then - validate_config = function(config_path) - local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path) - return i_o.exit_code_cmd(cmd) == 0 - end -else - validate_config = function(_) - i_o.warnf('could not validate config') - return true - end +-- if i_o.exe_exists('yajsv') then +-- validate_config = function(config_path) +-- local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path) +-- return i_o.exit_code_cmd(cmd) == 0 +-- end +-- else +-- validate_config = function(_) +-- i_o.warnf('could not validate config') +-- return true +-- end +-- end + +local config_path = '/tmp/conky.yml' + +local try_read_config = function(path) + print(path) + local cmd = string.format('dhall-to-yaml --file %s > %s', path, config_path) + return i_o.exit_code_cmd(cmd) end local find_valid_config = function(paths) for i = 1, #paths do local path = paths[i] - local r = i_o.read_file(path) - if r ~= nil then - if validate_config(path) then - i_o.infof('Using config at %s', path) - return path, yaml.load(r) - else - i_o.warnf('%s did not pass; trying next', path) - end + local rc = try_read_config(path) + if rc == 0 then + i_o.infof('Using config at %s', path) + return yaml.load(i_o.read_file(config_path)) else - i_o.infof('could not find %s; trying next', path) + i_o.warnf('could not read %s; trying next', path) end end - i_o.assertf(false, 'ERROR: could not load valid config') + i_o.assertf(false, 'could not load valid config') end local get_config_dir = function() @@ -93,11 +97,11 @@ local get_config_dir = function() end local try_config_paths = { - get_config_dir()..'conky.yml', - conky_dir..'config/fallback.yml' + get_config_dir()..'conky.dhall', + conky_dir..'config/fallback.dhall' } -local config_path, config = find_valid_config(try_config_paths) +local config = find_valid_config(try_config_paths) local bootstrap = config.bootstrap @@ -125,8 +129,8 @@ conky.config = { xinerama_head = 0, double_buffer = true, - minimum_width = bootstrap.dimensions[1], - minimum_height = bootstrap.dimensions[2], + minimum_width = bootstrap.dimensions.x, + minimum_height = bootstrap.dimensions.y, draw_shades = false, draw_outline = false, diff --git a/src/color.lua b/src/color.lua index 69a2b35..c834493 100644 --- a/src/color.lua +++ b/src/color.lua @@ -15,6 +15,7 @@ local rgba = function(hex, alpha) a = alpha, } ) + print(hex, obj.r, obj.g, obj.b) return err.set_type(obj, "color") end @@ -65,10 +66,15 @@ compile_patterns = function(patterns) r[k] = rgb(v) elseif v.color ~= nil then r[k] = rgba(v.color, v.alpha) - elseif v.gradient ~= nil then - r[k] = compile_gradient(v.gradient) - elseif v.gradient_alpha ~= nil then - r[k] = compile_gradient_alpha(v.gradient_alpha) + elseif #v > 0 then + if v[1].alpha ~= nil then + r[k] = compile_gradient_alpha(v) + else + -- for k, v in pairs(compile_gradient(v)) do + -- print(k, v.r) + -- end + r[k] = compile_gradient(v) + end else r[k] = compile_patterns(v) end diff --git a/src/compile.lua b/src/compile.lua index e727ab8..708dff2 100644 --- a/src/compile.lua +++ b/src/compile.lua @@ -99,8 +99,8 @@ local reduce_static = function(common_, mods, y, acc, panel_mods) acc.next_x = acc.next_x + panel_mods else local margins = panel_mods.margins - local margin_x = margins[1] - local margin_y = margins[2] + local margin_x = margins.x + local margin_y = margins.y local mpoint = geom.make_point(acc.next_x + margin_x, y + margin_y) local r = arrange_panel_modules(common_, mods, mpoint, panel_mods.columns) local w = r.width + margin_x * 2 @@ -163,9 +163,11 @@ return function(update_interval, config_path) pacman = pure.partial(pacman, main_state) } + local anchor = config.layout.anchor + local compiled = compile_layout( common(config), - geom.make_point(table.unpack(config.layout.anchor)), + geom.make_point(anchor.x, anchor.y), mods, config.layout.panels ) diff --git a/src/modules/common.lua b/src/modules/common.lua index 7275d94..10e8975 100644 --- a/src/modules/common.lua +++ b/src/modules/common.lua @@ -104,8 +104,8 @@ return function(config) -- timeseries helper functions local _default_grid_config = timeseries.grid_config( - geometry.plot.ticks[1], - geometry.plot.ticks[2], + geometry.plot.ticks.x, + geometry.plot.ticks.y, patterns.plot.grid ) @@ -615,8 +615,8 @@ return function(config) local gtable = geometry.table local padding = gtable.padding - local xpad = padding[1] - local ypad = padding[2] + local xpad = padding.x + local ypad = padding.y local default_table_font_spec = make_font_spec(font_family, font_sizes.table, false) From ee09e31e7da52aeb27850d975675a0123c8e8ace Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Thu, 11 Aug 2022 00:27:16 -0400 Subject: [PATCH 03/11] FIX typos --- config/config.dhall | 18 ++++++++++++------ config/fallback.dhall | 28 +++++++++++++++------------- conky.conf | 1 - src/color.lua | 1 - 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/config/config.dhall b/config/config.dhall index 7aca51c..7bc1795 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -58,21 +58,26 @@ let Modules = } let ModType = - < fileSystem + < filesystem | graphics | memory | network | pacman | processor + | power | readwrite | system > let Block = < Pad : Natural | Mod : ModType > -let Column = { blocks : List Block, width : Natural } +let Column_ = { blocks : List Block, width : Natural } -let Panel = { columns : List Column, margins : Margin } +let Column = < CPad : Natural | CCol : Column_ > + +let Panel_ = { columns : List Column, margins : Margin } + +let Panel = < PPad : Natural | PPanel : Panel_ > let Layout = { anchor : Point, panels : List Panel } @@ -113,7 +118,7 @@ let TableGeometry = { name_chars = 8 , padding = { x = 6, y = 15 } , header_padding = 20 - , row_spacing = 13 + , row_spacing = 16 } } @@ -160,7 +165,7 @@ let Patterns = , data : { border : Pattern, fill : Pattern } } , indicator : - { bg : Pattern, fg : { active : Pattern, inactive : Pattern } } + { bg : Pattern, fg : { active : Pattern, critical : Pattern } } } , default = { header = Pattern.RGB 0xefefef @@ -201,7 +206,7 @@ let Patterns = , { color = 0x99CEFF, stop = 0.5 } , { color = 0x316BA6, stop = 1.0 } ] - , inactive = + , critical = Pattern.GradientRGB [ { color = 0xFF3333, stop = 0.0 } , { color = 0xFFB8B8, stop = 0.5 } @@ -246,6 +251,7 @@ let toConfig = in { toConfig , Block + , Column , ModType , Layout , Panel diff --git a/config/fallback.dhall b/config/fallback.dhall index ce9c7e3..308438f 100644 --- a/config/fallback.dhall +++ b/config/fallback.dhall @@ -3,19 +3,21 @@ let C = ./config.dhall let layout = { anchor = { x = 12, y = 11 } , panels = - [ { columns = - [ { blocks = - [ C.Block.Mod C.ModType.network - , C.Block.Pad 10 - , C.Block.Mod C.ModType.memory - , C.Block.Pad 10 - , C.Block.Mod C.ModType.processor - ] - , width = 436 - } - ] - , margins = { x = 20, y = 10 } - } + [ C.Panel.PPanel + { columns = + [ C.Column.CCol + { blocks = + [ C.Block.Mod C.ModType.network + , C.Block.Pad 10 + , C.Block.Mod C.ModType.memory + , C.Block.Pad 10 + , C.Block.Mod C.ModType.processor + ] + , width = 436 + } + ] + , margins = { x = 20, y = 10 } + } ] : List C.Panel } diff --git a/conky.conf b/conky.conf index 6bed01a..9781c55 100644 --- a/conky.conf +++ b/conky.conf @@ -73,7 +73,6 @@ local i_o = require 'i_o' local config_path = '/tmp/conky.yml' local try_read_config = function(path) - print(path) local cmd = string.format('dhall-to-yaml --file %s > %s', path, config_path) return i_o.exit_code_cmd(cmd) end diff --git a/src/color.lua b/src/color.lua index c834493..cbc54ca 100644 --- a/src/color.lua +++ b/src/color.lua @@ -15,7 +15,6 @@ local rgba = function(hex, alpha) a = alpha, } ) - print(hex, obj.r, obj.g, obj.b) return err.set_type(obj, "color") end From 40678a8e17a4f1e2fa5bcc948a5812d63512d812 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Thu, 11 Aug 2022 00:31:09 -0400 Subject: [PATCH 04/11] REF add some nice comments --- conky.conf | 15 --------------- src/color.lua | 10 +++++++--- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/conky.conf b/conky.conf index 9781c55..f8bca59 100644 --- a/conky.conf +++ b/conky.conf @@ -55,21 +55,6 @@ package.cpath = conky_dir..'lib/lib/lua/5.4/?.so;' local yaml = require 'lyaml' local i_o = require 'i_o' --- local schema_path = conky_dir..'/config/schema.yml' --- local validate_config - --- if i_o.exe_exists('yajsv') then --- validate_config = function(config_path) --- local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path) --- return i_o.exit_code_cmd(cmd) == 0 --- end --- else --- validate_config = function(_) --- i_o.warnf('could not validate config') --- return true --- end --- end - local config_path = '/tmp/conky.yml' local try_read_config = function(path) diff --git a/src/color.lua b/src/color.lua index cbc54ca..10d7656 100644 --- a/src/color.lua +++ b/src/color.lua @@ -61,19 +61,23 @@ local compile_patterns compile_patterns = function(patterns) local r = {} for k, v in pairs(patterns) do + -- number -> solid color if type(v) == "number" then r[k] = rgb(v) + -- { color = x, alpha = y} -> alpha color elseif v.color ~= nil then r[k] = rgba(v.color, v.alpha) + -- ASSUME non-empty array is a gradient elseif #v > 0 then + -- ASSUME alpha gradient will have color/stop/alpha records for each + -- member, so just check the first if v[1].alpha ~= nil then r[k] = compile_gradient_alpha(v) else - -- for k, v in pairs(compile_gradient(v)) do - -- print(k, v.r) - -- end r[k] = compile_gradient(v) end + -- ASSUME nothing else in the tree is a number, a table with 'color', or + -- an array else r[k] = compile_patterns(v) end From 53544b347efcdd0862e5d60d9de953ac408ebe2b Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Thu, 11 Aug 2022 23:03:33 -0400 Subject: [PATCH 05/11] ENH use disgusting hack to simulate a sum type in yaml --- config/config.dhall | 93 +++++++++++++++++++++++++-------------------- src/color.lua | 25 ++++-------- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/config/config.dhall b/config/config.dhall index 7bc1795..3815d24 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -153,65 +153,74 @@ let Pattern = | GradientRGBA : List StopRGBA > +let Annotated = \(a : Type) -> { type : Text, data : a } + +let annotate = + \(a : Pattern) -> + { type = showConstructor a, data = a } : Annotated Pattern + +let APattern = Annotated Pattern + +let symGradient = + \(c0 : Natural) -> + \(c1 : Natural) -> + annotate + ( Pattern.GradientRGB + [ { color = c0, stop = 0.0 } + , { color = c1, stop = 0.5 } + , { color = c0, stop = 1.0 } + ] + ) + let Patterns = { Type = - { header : Pattern - , panel : { bg : Pattern } - , text : { active : Pattern, inactive : Pattern, critical : Pattern } - , border : Pattern + { header : APattern + , panel : { bg : APattern } + , text : + { active : APattern, inactive : APattern, critical : APattern } + , border : APattern , plot : - { grid : Pattern - , outline : Pattern - , data : { border : Pattern, fill : Pattern } + { grid : APattern + , outline : APattern + , data : { border : APattern, fill : APattern } } , indicator : - { bg : Pattern, fg : { active : Pattern, critical : Pattern } } + { bg : APattern, fg : { active : APattern, critical : APattern } } } , default = - { header = Pattern.RGB 0xefefef - , panel.bg = Pattern.RGBA { color = 0x121212, alpha = 0.7 } + { header = annotate (Pattern.RGB 0xefefef) + , panel.bg = annotate (Pattern.RGBA { color = 0x121212, alpha = 0.7 }) , text = - { active = Pattern.RGB 0xbfe1ff - , inactive = Pattern.RGB 0xc8c8c8 - , critical = Pattern.RGB 0xff8282 + { active = annotate (Pattern.RGB 0xbfe1ff) + , inactive = annotate (Pattern.RGB 0xc8c8c8) + , critical = annotate (Pattern.RGB 0xff8282) } - , border = Pattern.RGB 0x888888 + , border = annotate (Pattern.RGB 0x888888) , plot = - { grid = Pattern.RGB 0x666666 - , outline = Pattern.RGB 0x777777 + { grid = annotate (Pattern.RGB 0x666666) + , outline = annotate (Pattern.RGB 0x777777) , data = { border = - Pattern.GradientRGB - [ { color = 0x003f7c, stop = 0.0 } - , { color = 0x1e90ff, stop = 1.0 } - ] + annotate + ( Pattern.GradientRGB + [ { color = 0x003f7c, stop = 0.0 } + , { color = 0x1e90ff, stop = 1.0 } + ] + ) , fill = - Pattern.GradientRGBA - [ { color = 0x316ece, stop = 0.2, alpha = 0.5 } - , { color = 0x8cc7ff, stop = 1.0, alpha = 1.0 } - ] + annotate + ( Pattern.GradientRGBA + [ { color = 0x316ece, stop = 0.2, alpha = 0.5 } + , { color = 0x8cc7ff, stop = 1.0, alpha = 1.0 } + ] + ) } } , indicator = - { bg = - Pattern.GradientRGB - [ { color = 0x565656, stop = 0.0 } - , { color = 0xbfbfbf, stop = 0.5 } - , { color = 0x565656, stop = 1.0 } - ] + { bg = symGradient 0x565656 0xbfbfbf , fg = - { active = - Pattern.GradientRGB - [ { color = 0x316BA6, stop = 0.0 } - , { color = 0x99CEFF, stop = 0.5 } - , { color = 0x316BA6, stop = 1.0 } - ] - , critical = - Pattern.GradientRGB - [ { color = 0xFF3333, stop = 0.0 } - , { color = 0xFFB8B8, stop = 0.5 } - , { color = 0xFF3333, stop = 1.0 } - ] + { active = symGradient 0x316BA6 0x99CEFF + , critical = symGradient 0xFF3333 0xFFB8B8 } } } diff --git a/src/color.lua b/src/color.lua index 10d7656..1adc444 100644 --- a/src/color.lua +++ b/src/color.lua @@ -61,23 +61,14 @@ local compile_patterns compile_patterns = function(patterns) local r = {} for k, v in pairs(patterns) do - -- number -> solid color - if type(v) == "number" then - r[k] = rgb(v) - -- { color = x, alpha = y} -> alpha color - elseif v.color ~= nil then - r[k] = rgba(v.color, v.alpha) - -- ASSUME non-empty array is a gradient - elseif #v > 0 then - -- ASSUME alpha gradient will have color/stop/alpha records for each - -- member, so just check the first - if v[1].alpha ~= nil then - r[k] = compile_gradient_alpha(v) - else - r[k] = compile_gradient(v) - end - -- ASSUME nothing else in the tree is a number, a table with 'color', or - -- an array + if v.type == "RGB" then + r[k] = rgb(v.data) + elseif v.type == "RGBA" then + r[k] = rgba(v.data.color, v.data.alpha) + elseif v.type == "GradientRGB" then + r[k] = compile_gradient(v.data) + elseif v.type == "GradientRGBA" then + r[k] = compile_gradient_alpha(v.data) else r[k] = compile_patterns(v) end From c50a704c0fa5a80e65a4887ff3564c561d698393 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Fri, 12 Aug 2022 00:20:01 -0400 Subject: [PATCH 06/11] ENH use disgusting yaml union type hack for module layout --- config/config.dhall | 80 ++++++++++++++------------------------ config/fallback.dhall | 72 ++++++++++++++++------------------ src/compile.lua | 20 +++++----- src/modules/filesystem.lua | 2 +- src/modules/network.lua | 2 +- src/modules/pacman.lua | 2 +- src/modules/processor.lua | 2 +- src/modules/system.lua | 2 +- 8 files changed, 77 insertions(+), 105 deletions(-) diff --git a/config/config.dhall b/config/config.dhall index 3815d24..f6e3fc4 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -38,38 +38,21 @@ let Power = { battery : Text, rapl_specs : List RaplSpec } let ReadWrite = { devices : List Text } -let Modules = - { Type = - { filesystem : Optional FileSystem - , graphics : Optional Graphics - , memory : Optional Memory - , processor : Optional Processor - , power : Optional Power - , readwrite : Optional ReadWrite - } - , default = - { filesystem = None FileSystem - , graphics = None Graphics - , memory = None Memory - , processor = None Processor - , power = None Power - , readwrite = None ReadWrite - } - } - let ModType = - < filesystem - | graphics - | memory + < filesystem : FileSystem + | graphics : Graphics + | memory : Memory | network | pacman - | processor - | power - | readwrite + | processor : Processor + | power : Power + | readwrite : ReadWrite | system > -let Block = < Pad : Natural | Mod : ModType > +let Annotated = \(a : Type) -> { type : Text, data : a } + +let Block = < Pad : Natural | Mod : Annotated ModType > let Column_ = { blocks : List Block, width : Natural } @@ -153,18 +136,18 @@ let Pattern = | GradientRGBA : List StopRGBA > -let Annotated = \(a : Type) -> { type : Text, data : a } - -let annotate = +let annotatePattern = \(a : Pattern) -> { type = showConstructor a, data = a } : Annotated Pattern +let mod = \(a : ModType) -> Block.Mod { type = showConstructor a, data = a } + let APattern = Annotated Pattern let symGradient = \(c0 : Natural) -> \(c1 : Natural) -> - annotate + annotatePattern ( Pattern.GradientRGB [ { color = c0, stop = 0.0 } , { color = c1, stop = 0.5 } @@ -188,27 +171,28 @@ let Patterns = { bg : APattern, fg : { active : APattern, critical : APattern } } } , default = - { header = annotate (Pattern.RGB 0xefefef) - , panel.bg = annotate (Pattern.RGBA { color = 0x121212, alpha = 0.7 }) + { header = annotatePattern (Pattern.RGB 0xefefef) + , panel.bg + = annotatePattern (Pattern.RGBA { color = 0x121212, alpha = 0.7 }) , text = - { active = annotate (Pattern.RGB 0xbfe1ff) - , inactive = annotate (Pattern.RGB 0xc8c8c8) - , critical = annotate (Pattern.RGB 0xff8282) + { active = annotatePattern (Pattern.RGB 0xbfe1ff) + , inactive = annotatePattern (Pattern.RGB 0xc8c8c8) + , critical = annotatePattern (Pattern.RGB 0xff8282) } - , border = annotate (Pattern.RGB 0x888888) + , border = annotatePattern (Pattern.RGB 0x888888) , plot = - { grid = annotate (Pattern.RGB 0x666666) - , outline = annotate (Pattern.RGB 0x777777) + { grid = annotatePattern (Pattern.RGB 0x666666) + , outline = annotatePattern (Pattern.RGB 0x777777) , data = { border = - annotate + annotatePattern ( Pattern.GradientRGB [ { color = 0x003f7c, stop = 0.0 } , { color = 0x1e90ff, stop = 1.0 } ] ) , fill = - annotate + annotatePattern ( Pattern.GradientRGBA [ { color = 0x316ece, stop = 0.2, alpha = 0.5 } , { color = 0x8cc7ff, stop = 1.0, alpha = 1.0 } @@ -238,23 +222,17 @@ let Theme = let Bootstrap = { update_interval : Natural, dimensions : Point } -let Config = - { bootstrap : Bootstrap - , theme : Theme.Type - , layout : Layout - , modules : Modules.Type - } +let Config = { bootstrap : Bootstrap, theme : Theme.Type, layout : Layout } let toConfig = \(i : Natural) -> - \(d : Point) -> + \(x : Natural) -> + \(y : Natural) -> \(t : Theme.Type) -> \(l : Layout) -> - \(m : Modules.Type) -> - { bootstrap = { update_interval = i, dimensions = d } + { bootstrap = { update_interval = i, dimensions = { x, y } } , theme = t , layout = l - , modules = m } : Config @@ -264,7 +242,6 @@ in { toConfig , ModType , Layout , Panel - , Modules , FSPath , FileSystem , Graphics @@ -273,4 +250,5 @@ in { toConfig , Power , ReadWrite , Theme + , mod } diff --git a/config/fallback.dhall b/config/fallback.dhall index 308438f..54576b5 100644 --- a/config/fallback.dhall +++ b/config/fallback.dhall @@ -1,47 +1,41 @@ let C = ./config.dhall +let memory = + C.ModType.memory + { show_stats = False + , show_swap = False + , show_plot = True + , table_rows = 3 + } + +let processor = + C.ModType.processor + { core_rows = 0 + , core_padding = 0 + , show_stats = False + , show_plot = True + , table_rows = 3 + } + let layout = - { anchor = { x = 12, y = 11 } - , panels = - [ C.Panel.PPanel - { columns = - [ C.Column.CCol - { blocks = - [ C.Block.Mod C.ModType.network - , C.Block.Pad 10 - , C.Block.Mod C.ModType.memory - , C.Block.Pad 10 - , C.Block.Mod C.ModType.processor - ] - , width = 436 - } + { anchor = { x = 12, y = 11 } + , panels = + [ C.Panel.PPanel + { columns = + [ C.Column.CCol + { blocks = + [ C.mod C.ModType.network + , C.Block.Pad 10 + , C.mod memory + , C.Block.Pad 10 + , C.mod processor ] - , margins = { x = 20, y = 10 } + , width = 436 } ] - : List C.Panel - } - : C.Layout - -let modules = - C.Modules::{ - , memory = Some - ( { show_stats = False - , show_swap = False - , show_plot = True - , table_rows = 3 - } - : C.Memory - ) - , processor = Some - ( { core_rows = 0 - , core_padding = 0 - , show_stats = False - , show_plot = True - , table_rows = 3 - } - : C.Processor - ) + , margins = { x = 20, y = 10 } + } + ] } -in C.toConfig 1 { x = 1920, y = 1080 } C.Theme::{=} layout modules +in C.toConfig 1 1920 1080 C.Theme::{=} layout diff --git a/src/compile.lua b/src/compile.lua index 708dff2..304aaa2 100644 --- a/src/compile.lua +++ b/src/compile.lua @@ -18,7 +18,8 @@ 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 - local m = modlist[new](common_, width, geom.make_point(init_x, acc.next_y)) + local m = modlist[new.type](new.data, 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 r = common_.compile_module( m.header, m.point, @@ -147,19 +148,18 @@ end return function(update_interval, config_path) local update_freq = 1 / update_interval local config = yaml.load(i_o.read_file(config_path)) - local cmods = config.modules local main_state = {} - local mods = { - memory = pure.partial(memory, update_freq, cmods.memory), - readwrite = pure.partial(readwrite, update_freq, cmods.readwrite), + local modlist = { + memory = pure.partial(memory, update_freq), + readwrite = pure.partial(readwrite, update_freq), network = pure.partial(network, update_freq), - power = pure.partial(power, update_freq, cmods.power), - filesystem = pure.partial(filesystem, cmods.filesystem, main_state), + power = pure.partial(power, update_freq), + filesystem = pure.partial(filesystem, main_state), system = pure.partial(system, main_state), - graphics = pure.partial(graphics, update_freq, cmods.graphics), - processor = pure.partial(processor, update_freq, cmods.processor, main_state), + graphics = pure.partial(graphics, update_freq), + processor = pure.partial(processor, update_freq, main_state), pacman = pure.partial(pacman, main_state) } @@ -168,7 +168,7 @@ return function(update_interval, config_path) local compiled = compile_layout( common(config), geom.make_point(anchor.x, anchor.y), - mods, + modlist, config.layout.panels ) diff --git a/src/modules/filesystem.lua b/src/modules/filesystem.lua index 8c36ebb..79d7248 100644 --- a/src/modules/filesystem.lua +++ b/src/modules/filesystem.lua @@ -2,7 +2,7 @@ local i_o = require 'i_o' local pure = require 'pure' local impure = require 'impure' -return function(config, main_state, common, width, point) +return function(main_state, config, common, width, point) local SPACING = 20 local BAR_PAD = 100 local SEPARATOR_SPACING = 20 diff --git a/src/modules/network.lua b/src/modules/network.lua index a0e0065..c1fb4ae 100644 --- a/src/modules/network.lua +++ b/src/modules/network.lua @@ -3,7 +3,7 @@ local pure = require 'pure' local i_o = require 'i_o' local sys = require 'sys' -return function(update_freq, common, width, point) +return function(update_freq, _, common, width, point) local PLOT_SEC_BREAK = 20 local PLOT_HEIGHT = 56 local interface_paths = sys.get_net_interface_paths() diff --git a/src/modules/pacman.lua b/src/modules/pacman.lua index fa6b8e2..f1739a9 100644 --- a/src/modules/pacman.lua +++ b/src/modules/pacman.lua @@ -1,6 +1,6 @@ local pure = require 'pure' -return function(main_state, common, width, point) +return function(main_state, _, common, width, point) local TEXT_SPACING = 20 local __string_match = string.match diff --git a/src/modules/processor.lua b/src/modules/processor.lua index 25497f9..7ed6bce 100644 --- a/src/modules/processor.lua +++ b/src/modules/processor.lua @@ -6,7 +6,7 @@ local pure = require 'pure' local __math_floor = math.floor -return function(update_freq, config, main_state, common, width, point) +return function(update_freq, main_state, config, common, width, point) local DIAL_INNER_RADIUS = 30 local DIAL_OUTER_RADIUS = 42 local DIAL_THICKNESS = 5.5 diff --git a/src/modules/system.lua b/src/modules/system.lua index 050a790..9a47ccb 100644 --- a/src/modules/system.lua +++ b/src/modules/system.lua @@ -1,7 +1,7 @@ local i_o = require 'i_o' local pure = require 'pure' -return function(main_state, common, width, point) +return function(main_state, _, common, width, point) local TEXT_SPACING = 20 local __string_match = string.match From 99ce64bbb6473ed71b474fbd3c788cf80d060fb4 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Mon, 15 Aug 2022 23:23:15 -0400 Subject: [PATCH 07/11] ENH use module-specific geometries --- config/config.dhall | 122 +++++++++++++++++++++++++++++-------- config/fallback.dhall | 8 ++- src/modules/filesystem.lua | 7 ++- src/modules/graphics.lua | 9 +-- src/modules/memory.lua | 11 ++-- src/modules/network.lua | 7 ++- src/modules/pacman.lua | 4 +- src/modules/power.lua | 7 ++- src/modules/readwrite.lua | 5 +- src/modules/system.lua | 4 +- 10 files changed, 130 insertions(+), 54 deletions(-) diff --git a/config/config.dhall b/config/config.dhall index f6e3fc4..3553441 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -6,48 +6,113 @@ let Margin = Vector2 Natural let FSPath = { name : Text, path : Text } -let FileSystem = { show_smart : Bool, fs_paths : List FSPath } +let FSGeo = + { Type = { spacing : Natural, bar_pad : Natural, sep_spacing : Natural } + , default = { spacing = 20, bar_pad = 100, sep_spacing = 20 } + } + +let FileSystem = + { Type = + { show_smart : Bool, fs_paths : List FSPath, geometry : FSGeo.Type } + , 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 = - { dev_power : Text - , show_temp : Bool - , show_clock : Bool - , show_gpu_util : Bool - , show_mem_util : Bool - , show_vid_util : Bool + { Type = + { dev_power : Text + , show_temp : Bool + , show_clock : Bool + , show_gpu_util : Bool + , show_mem_util : Bool + , show_vid_util : Bool + , geometry : GfxGeo.Type + } + , default.geometry = GfxGeo::{=} + } + +let MemGeo = + { Type = { text_spacing : Natural, plot : PlotGeo.Type } + , default = { plot = PlotGeo::{=}, text_spacing = 20 } } let Memory = - { show_stats : Bool - , show_plot : Bool - , show_swap : Bool - , table_rows : Natural + { Type = + { show_stats : Bool + , show_plot : Bool + , show_swap : Bool + , table_rows : Natural + , geometry : MemGeo.Type + } + , default.geometry = MemGeo::{=} } +let Network = + { Type = { geometry : { plot : PlotGeo.Type } } + , default.geometry.plot = PlotGeo::{=} + } + +let ProcGeo = { Type = { plot : PlotGeo.Type }, default.plot = PlotGeo::{=} } + let Processor = - { core_rows : Natural - , core_padding : Natural - , show_stats : Bool - , show_plot : Bool - , table_rows : Natural + { Type = + { core_rows : Natural + , core_padding : Natural + , show_stats : Bool + , show_plot : Bool + , table_rows : Natural + , geometry : ProcGeo.Type + } + , default.geometry = ProcGeo::{=} } let RaplSpec = { name : Text, address : Text } -let Power = { battery : Text, rapl_specs : List RaplSpec } +let PwrGeo = + { Type = { text_spacing : Natural, plot : PlotGeo.Type } + , default = { text_spacing = 20, plot = PlotGeo::{=} } + } -let ReadWrite = { devices : List Text } +let Pacman = + { Type = { geometry : { text_spacing : Natural } } + , default.geometry.text_spacing = 20 + } + +let Power = + { Type = + { battery : Text, rapl_specs : List RaplSpec, geometry : PwrGeo.Type } + , default.geometry = PwrGeo::{=} + } + +let RWGeo = { Type = { plot : PlotGeo.Type }, default.plot = PlotGeo::{=} } + +let ReadWrite = + { Type = { devices : List Text, geometry : RWGeo.Type } + , default.geometry = RWGeo::{=} + } + +let System = Pacman let ModType = - < filesystem : FileSystem - | graphics : Graphics - | memory : Memory - | network - | pacman - | processor : Processor - | power : Power - | readwrite : ReadWrite - | system + < filesystem : FileSystem.Type + | graphics : Graphics.Type + | memory : Memory.Type + | network : Network.Type + | pacman : Pacman.Type + | processor : Processor.Type + | power : Power.Type + | readwrite : ReadWrite.Type + | system : System.Type > let Annotated = \(a : Type) -> { type : Text, data : a } @@ -246,9 +311,12 @@ in { toConfig , FileSystem , Graphics , Memory + , Network + , Pacman , Processor , Power , ReadWrite + , System , Theme , mod } diff --git a/config/fallback.dhall b/config/fallback.dhall index 54576b5..846961a 100644 --- a/config/fallback.dhall +++ b/config/fallback.dhall @@ -2,7 +2,8 @@ let C = ./config.dhall let memory = C.ModType.memory - { show_stats = False + C.Memory::{ + , show_stats = False , show_swap = False , show_plot = True , table_rows = 3 @@ -10,7 +11,8 @@ let memory = let processor = C.ModType.processor - { core_rows = 0 + C.Processor::{ + , core_rows = 0 , core_padding = 0 , show_stats = False , show_plot = True @@ -24,7 +26,7 @@ let layout = { columns = [ C.Column.CCol { blocks = - [ C.mod C.ModType.network + [ C.mod (C.ModType.network C.Network::{=}) , C.Block.Pad 10 , C.mod memory , C.Block.Pad 10 diff --git a/src/modules/filesystem.lua b/src/modules/filesystem.lua index 79d7248..c6bfa3a 100644 --- a/src/modules/filesystem.lua +++ b/src/modules/filesystem.lua @@ -3,9 +3,10 @@ local pure = require 'pure' local impure = require 'impure' return function(main_state, config, common, width, point) - local SPACING = 20 - local BAR_PAD = 100 - local SEPARATOR_SPACING = 20 + local geo = config.geometry + local SPACING = geo.spacing + local BAR_PAD = geo.bar_pad + local SEPARATOR_SPACING = geo.sep_spacing ----------------------------------------------------------------------------- -- smartd diff --git a/src/modules/graphics.lua b/src/modules/graphics.lua index a49f918..264a82a 100644 --- a/src/modules/graphics.lua +++ b/src/modules/graphics.lua @@ -2,10 +2,11 @@ local pure = require 'pure' local i_o = require 'i_o' return function(update_freq, config, common, width, point) - local SEPARATOR_SPACING = 20 - local TEXT_SPACING = 20 - local PLOT_SEC_BREAK = 20 - local PLOT_HEIGHT = 56 + local geo = config.geometry + local SEPARATOR_SPACING = geo.sep_spacing + local TEXT_SPACING = geo.text_spacing + local PLOT_SEC_BREAK = geo.plot.sec_break + local PLOT_HEIGHT = geo.plot.height local NA = 'N/A' local NVIDIA_EXE = 'nvidia-settings' local __string_match = string.match diff --git a/src/modules/memory.lua b/src/modules/memory.lua index b584520..bcd882e 100644 --- a/src/modules/memory.lua +++ b/src/modules/memory.lua @@ -5,14 +5,15 @@ local pure = require 'pure' local sys = require 'sys' return function(update_freq, config, common, width, point) + local geo = config.geometry local DIAL_THICKNESS = 8 local DIAL_RADIUS = 32 - local DIAL_SPACING = 40 + local DIAL_X_SPACING = 40 local CACHE_Y_OFFSET = 7 local CACHE_X_OFFSET = 50 - local TEXT_SPACING = 20 - local PLOT_SECTION_BREAK = 23 - local PLOT_HEIGHT = 56 + 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 __math_floor = math.floor @@ -54,7 +55,7 @@ return function(update_freq, config, common, width, point) local CACHE_X local SWAP_X if _show_swap == true then - SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_SPACING + SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_X_SPACING CACHE_X = SWAP_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2 else CACHE_X = MEM_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2 diff --git a/src/modules/network.lua b/src/modules/network.lua index c1fb4ae..7836901 100644 --- a/src/modules/network.lua +++ b/src/modules/network.lua @@ -3,9 +3,10 @@ local pure = require 'pure' local i_o = require 'i_o' local sys = require 'sys' -return function(update_freq, _, common, width, point) - local PLOT_SEC_BREAK = 20 - local PLOT_HEIGHT = 56 +return function(update_freq, config, common, width, point) + local geo = config.geometry + local PLOT_SEC_BREAK = geo.plot.sec_break + local PLOT_HEIGHT = geo.plot.height local interface_paths = sys.get_net_interface_paths() local get_bits = function(path) diff --git a/src/modules/pacman.lua b/src/modules/pacman.lua index f1739a9..88130f8 100644 --- a/src/modules/pacman.lua +++ b/src/modules/pacman.lua @@ -1,7 +1,7 @@ local pure = require 'pure' -return function(main_state, _, common, width, point) - local TEXT_SPACING = 20 +return function(main_state, config, common, width, point) + local TEXT_SPACING = config.geometry.text_spacing local __string_match = string.match local __string_gmatch = string.gmatch diff --git a/src/modules/power.lua b/src/modules/power.lua index a634fc4..4324663 100644 --- a/src/modules/power.lua +++ b/src/modules/power.lua @@ -3,9 +3,10 @@ local pure = require 'pure' local sys = require 'sys' return function(update_freq, config, common, width, point) - local TEXT_SPACING = 20 - local PLOT_SEC_BREAK = 20 - local PLOT_HEIGHT = 56 + local geo = config.geometry + local TEXT_SPACING = geo.text_spacing + local PLOT_SEC_BREAK = geo.plot.sec_break + local PLOT_HEIGHT = geo.plot.height local power_label_function = function(plot_max) local fmt = common.y_label_format_string(plot_max, 'W') diff --git a/src/modules/readwrite.lua b/src/modules/readwrite.lua index 2ffaed4..5824d44 100644 --- a/src/modules/readwrite.lua +++ b/src/modules/readwrite.lua @@ -5,8 +5,9 @@ local i_o = require 'i_o' local impure = require 'impure' return function(update_freq, config, common, width, point) - local PLOT_SEC_BREAK = 20 - local PLOT_HEIGHT = 56 + local geo = config.geometry + local PLOT_SEC_BREAK = geo.plot.sec_break + local PLOT_HEIGHT = geo.plot.height local mod_state = {read = 0, write = 0} local device_paths = sys.get_disk_paths(config.devices) diff --git a/src/modules/system.lua b/src/modules/system.lua index 9a47ccb..4c14193 100644 --- a/src/modules/system.lua +++ b/src/modules/system.lua @@ -1,8 +1,8 @@ local i_o = require 'i_o' local pure = require 'pure' -return function(main_state, _, common, width, point) - local TEXT_SPACING = 20 +return function(main_state, config, common, width, point) + local TEXT_SPACING = config.geometry.text_spacing local __string_match = string.match From fb79ea899d300a4781af73aa5a4f743048f64f98 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 16 Aug 2022 00:14:04 -0400 Subject: [PATCH 08/11] 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 From 4b5f289b99c738b47c0219fee76b9bcfeb95f1b1 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 16 Aug 2022 23:49:13 -0400 Subject: [PATCH 09/11] ENH make plot heights/y ticks configurable per modules --- config/config.dhall | 9 +++-- src/modules/common.lua | 68 +++++++++++++++++++++--------------- src/modules/graphics.lua | 35 ++++++++++--------- src/modules/memory.lua | 72 ++++++++++++++++++++------------------- src/modules/network.lua | 13 +++---- src/modules/power.lua | 18 +++++----- src/modules/processor.lua | 57 ++++++++++++++++--------------- src/modules/readwrite.lua | 13 +++---- src/modules/system.lua | 6 ++-- 9 files changed, 155 insertions(+), 136 deletions(-) diff --git a/config/config.dhall b/config/config.dhall index abf01c6..933d4c9 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -11,8 +11,8 @@ 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 } + { Type = { sec_break : Natural, height : Natural, ticks_y : Natural } + , default = { sec_break = 20, height = 56, ticks_y = 4 } } let PlotGeo = { Type = { plot : PlotGeo_.Type }, default.plot = PlotGeo_::{=} } @@ -156,10 +156,9 @@ let PlotGeometry = { spacing : Natural , height : Natural , seconds : Natural - , ticks : Vector2 Natural + , ticks_x : Natural } - , default = - { seconds = 90, ticks = { x = 9, y = 4 }, height = 56, spacing = 20 } + , default = { seconds = 90, ticks_x = 9, height = 56, spacing = 20 } } let TableGeometry = diff --git a/src/modules/common.lua b/src/modules/common.lua index 10e8975..e5ee797 100644 --- a/src/modules/common.lua +++ b/src/modules/common.lua @@ -103,19 +103,23 @@ return function(config) ----------------------------------------------------------------------------- -- timeseries helper functions - local _default_grid_config = timeseries.grid_config( - geometry.plot.ticks.x, - geometry.plot.ticks.y, - patterns.plot.grid - ) + local _default_grid_config = function(ticks_y) + return timeseries.grid_config( + geometry.plot.ticks_x, + ticks_y, + patterns.plot.grid + ) + end - local _default_plot_config = timeseries.config( - geometry.plot.seconds, - patterns.plot.outline, - patterns.plot.data.border, - patterns.plot.data.fill, - _default_grid_config - ) + local _default_plot_config = function(ticks_y) + return timeseries.config( + geometry.plot.seconds, + patterns.plot.outline, + patterns.plot.data.border, + patterns.plot.data.fill, + _default_grid_config(ticks_y) + ) + end local _format_percent_label = function(_) return function(z) return __string_format('%i%%', math.floor(z * 100)) end @@ -131,18 +135,20 @@ return function(config) _format_percent_label ) - local _make_timeseries = function(x, y, w, h, label_config, update_freq) + local _make_timeseries = function(x, y, w, h, ticks_y, label_config, update_freq) return timeseries.make( geom.make_box(x, y, w, h), update_freq, - _default_plot_config, + _default_plot_config(ticks_y), label_config ) end local gplot = geometry.plot - local _make_tagged_percent_timeseries = function(x, y, w, h, spacing, label, update_freq, _format) + local _make_tagged_percent_timeseries = function(x, y, w, h, ticks_y, + spacing, label, update_freq, + _format) return { label = _left_text(geom.make_point(x, y), label), value = text_threshold.make_formatted( @@ -157,6 +163,7 @@ return function(config) y + _maybe_config(gplot.spacing, spacing), w, _maybe_config(gplot.height, h), + ticks_y, update_freq ), } @@ -169,11 +176,11 @@ return function(config) return scaled_timeseries.scaling_parameters(2, m, 0.9) end - local _make_scaled_timeseries = function(x, y, w, h, f, min_domain, update_freq) + local _make_scaled_timeseries = function(x, y, w, h, ticks_y, f, min_domain, update_freq) return scaled_timeseries.make( geom.make_box(x, y, w, h), update_freq, - _default_plot_config, + _default_plot_config(ticks_y), timeseries.label_config(patterns.text.inactive, label_font_spec, f), _base_2_scale_data(min_domain) ) @@ -216,22 +223,24 @@ return function(config) ----------------------------------------------------------------------------- -- percent timeseries - M.make_percent_timeseries = function(x, y, w, h, update_freq) - return _make_timeseries(x, y, w, h, _percent_label_config, update_freq) + M.make_percent_timeseries = function(x, y, w, h, ticks_y, update_freq) + return _make_timeseries(x, y, w, h, ticks_y, _percent_label_config, update_freq) end ----------------------------------------------------------------------------- -- tagged percent timeseries - M.make_tagged_percent_timeseries = function(x, y, w, h, spacing, label, update_freq) + M.make_tagged_percent_timeseries = function(x, y, w, h, ticks_y, spacing, + label, update_freq) return _make_tagged_percent_timeseries( - x, y, w, h, spacing, label, update_freq, '%s%%' + x, y, w, h, ticks_y, spacing, label, update_freq, '%s%%' ) end - M.make_tagged_maybe_percent_timeseries = function(x, y, w, h, spacing, label, update_freq) + M.make_tagged_maybe_percent_timeseries = function(x, y, w, h, ticks_y, + spacing, label, update_freq) return _make_tagged_percent_timeseries( - x, y, w, h, spacing, label, update_freq, _format_percent_maybe + x, y, w, h, ticks_y, spacing, label, update_freq, _format_percent_maybe ) end @@ -294,9 +303,9 @@ return function(config) ----------------------------------------------------------------------------- -- tagged scaled plot - M.make_tagged_scaled_timeseries = function(x, y, w, h, format_fun, label_fun, - spacing, label, min_domain, - update_freq) + M.make_tagged_scaled_timeseries = function(x, y, w, h, ticks_y, format_fun, + label_fun, spacing, label, + min_domain, update_freq) return { label = _left_text(geom.make_point(x, y), label), value = text.make_formatted( @@ -310,6 +319,7 @@ return function(config) y + spacing, w, h, + ticks_y, label_fun, min_domain, update_freq @@ -341,8 +351,9 @@ return function(config) end end - M.make_rate_timeseries = function(x, y, w, h, format_fun, label_fun, spacing, - label, min_domain, update_freq, init) + M.make_rate_timeseries = function(x, y, w, h, ticks_y, format_fun, + label_fun, spacing, label, min_domain, + update_freq, init) return { label = _left_text(geom.make_point(x, y), label), value = text.make_formatted( @@ -356,6 +367,7 @@ return function(config) y + spacing, w, h, + ticks_y, label_fun, min_domain, update_freq diff --git a/src/modules/graphics.lua b/src/modules/graphics.lua index 264a82a..add0293 100644 --- a/src/modules/graphics.lua +++ b/src/modules/graphics.lua @@ -3,10 +3,10 @@ local i_o = require 'i_o' return function(update_freq, config, common, width, point) local geo = config.geometry - local SEPARATOR_SPACING = geo.sep_spacing - local TEXT_SPACING = geo.text_spacing - local PLOT_SEC_BREAK = geo.plot.sec_break - local PLOT_HEIGHT = geo.plot.height + local sep_spacing = geo.sep_spacing + local text_spacing = geo.text_spacing + local plot_sec_break = geo.plot.sec_break + local plot_height = geo.plot.height local NA = 'N/A' local NVIDIA_EXE = 'nvidia-settings' local __string_match = string.match @@ -89,8 +89,9 @@ return function(update_freq, config, common, width, point) point.x, y, width, - PLOT_HEIGHT, - PLOT_SEC_BREAK, + plot_height, + geo.plot.ticks_y, + plot_sec_break, label, update_freq ) @@ -103,7 +104,7 @@ return function(update_freq, config, common, width, point) local dynamic = pure.partial(common.tagged_percent_timeseries_draw_dynamic, obj) return common.mk_acc( width, - PLOT_HEIGHT + PLOT_SEC_BREAK, + plot_height + plot_sec_break, update, static, dynamic @@ -155,7 +156,7 @@ return function(update_freq, config, common, width, point) point.x, y, width, - TEXT_SPACING, + text_spacing, {'GPU Clock Speed', 'Memory Clock Speed'} ) local update = function() @@ -169,7 +170,7 @@ return function(update_freq, config, common, width, point) end local static = pure.partial(common.text_rows_draw_static, obj) local dynamic = pure.partial(common.text_rows_draw_dynamic, obj) - return common.mk_acc(width, TEXT_SPACING, update, static, dynamic) + return common.mk_acc(width, text_spacing, update, static, dynamic) end ----------------------------------------------------------------------------- @@ -207,19 +208,19 @@ return function(update_freq, config, common, width, point) point = point, width = width, set_state = update_state, - top = {{mk_status, true, SEPARATOR_SPACING}}, + top = {{mk_status, true, sep_spacing}}, common.mk_section( - SEPARATOR_SPACING, - {mk_temp, config.show_temp, SEPARATOR_SPACING} + sep_spacing, + {mk_temp, config.show_temp, sep_spacing} ), common.mk_section( - SEPARATOR_SPACING, - {mk_clock, config.show_clock, SEPARATOR_SPACING} + sep_spacing, + {mk_clock, config.show_clock, sep_spacing} ), common.mk_section( - SEPARATOR_SPACING, - {mk_gpu_util, config.show_gpu_util, PLOT_SEC_BREAK}, - {mk_mem_util, config.show_mem_util, PLOT_SEC_BREAK}, + sep_spacing, + {mk_gpu_util, config.show_gpu_util, plot_sec_break}, + {mk_mem_util, config.show_mem_util, plot_sec_break}, {mk_vid_util, config.show_vid_util, 0} ) } diff --git a/src/modules/memory.lua b/src/modules/memory.lua index c898c2a..e7f1b7a 100644 --- a/src/modules/memory.lua +++ b/src/modules/memory.lua @@ -6,14 +6,14 @@ local sys = require 'sys' return function(update_freq, config, common, width, point) local geo = config.geometry - local DIAL_THICKNESS = 8 - local DIAL_RADIUS = 32 - local DIAL_X_SPACING = 40 - local CACHE_Y_OFFSET = 7 - local CACHE_X_OFFSET = 50 - local PLOT_SECTION_BREAK = geo.plot.sec_break - local PLOT_HEIGHT = geo.plot.height - local TABLE_SECTION_BREAK = geo.table.sec_break + local dial_thickness = 8 + local dial_radius = 32 + local dial_x_spacing = 40 + local cache_y_offset = 7 + local cache_x_offset = 50 + local plot_sec_break = geo.plot.sec_break + local plot_height = geo.plot.height + local table_sec_break = geo.table.sec_break local __math_floor = math.floor local __string_format = string.format @@ -49,33 +49,33 @@ return function(update_freq, config, common, width, point) -- mem stats (dial + text) local mk_stats = function(y) - local MEM_X = point.x + DIAL_RADIUS + DIAL_THICKNESS / 2 - local DIAL_DIAMETER = DIAL_RADIUS * 2 + DIAL_THICKNESS - local CACHE_X - local SWAP_X + local mem_x = point.x + dial_radius + dial_thickness / 2 + local dial_diameter = dial_radius * 2 + dial_thickness + local cache_x + local swap_x if _show_swap == true then - SWAP_X = MEM_X + DIAL_DIAMETER + DIAL_X_SPACING - CACHE_X = SWAP_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2 + swap_x = mem_x + dial_diameter + dial_x_spacing + cache_x = swap_x + cache_x_offset + dial_diameter / 2 else - CACHE_X = MEM_X + CACHE_X_OFFSET + DIAL_DIAMETER / 2 + cache_x = mem_x + cache_x_offset + dial_diameter / 2 end - local CACHE_WIDTH = point.x + width - CACHE_X + local cache_width = point.x + width - cache_x local format_percent = pure.partial(__string_format, '%i%%', true) -- memory bits (used no matter what) local mem = common.make_dial( - MEM_X, - y + DIAL_RADIUS, - DIAL_RADIUS, - DIAL_THICKNESS, + mem_x, + y + dial_radius, + dial_radius, + dial_thickness, 80, format_percent, __math_floor ) local cache = common.make_text_rows_formatted( - CACHE_X, - y + CACHE_Y_OFFSET, - CACHE_WIDTH, + cache_x, + y + cache_y_offset, + cache_width, geo.text_spacing, {'Page Cache', 'Buffers', 'Shared', 'Kernel Slab'}, '%.1f%%' @@ -98,15 +98,15 @@ return function(update_freq, config, common, width, point) common.dial_draw_dynamic(mem, cr) common.text_rows_draw_dynamic(cache, cr) end - local ret = pure.partial(common.mk_acc, width, DIAL_DIAMETER) + local ret = pure.partial(common.mk_acc, width, dial_diameter) -- add swap bits if needed if _show_swap == true then local swap = common.make_dial( - SWAP_X, - y + DIAL_RADIUS, - DIAL_RADIUS, - DIAL_THICKNESS, + swap_x, + y + dial_radius, + dial_radius, + dial_thickness, 80, format_percent, __math_floor @@ -135,12 +135,13 @@ return function(update_freq, config, common, width, point) point.x, y, width, - PLOT_HEIGHT, + plot_height, + geo.plot.ticks_y, update_freq ) return common.mk_acc( width, - PLOT_HEIGHT, + plot_height, function() timeseries.update(obj, mod_state.mem.used_percent) end, pure.partial(timeseries.draw_static, obj), pure.partial(timeseries.draw_dynamic, obj) @@ -152,14 +153,15 @@ return function(update_freq, config, common, width, point) point.x, y, width, - PLOT_HEIGHT, - PLOT_SECTION_BREAK, + plot_height, + geo.plot.ticks_y, + plot_sec_break, "Total Memory", update_freq ) return common.mk_acc( width, - PLOT_HEIGHT + PLOT_SECTION_BREAK, + plot_height + plot_sec_break, function() common.tagged_percent_timeseries_set( obj, @@ -216,8 +218,8 @@ return function(update_freq, config, common, width, point) width = width, set_state = read_state, top = { - {mk_stats, config.show_stats, PLOT_SECTION_BREAK}, - {mk_plot, config.show_plot, TABLE_SECTION_BREAK}, + {mk_stats, config.show_stats, plot_sec_break}, + {mk_plot, config.show_plot, table_sec_break}, {mk_tbl, config.table_rows > 0, 0}, } } diff --git a/src/modules/network.lua b/src/modules/network.lua index 7836901..6d4a223 100644 --- a/src/modules/network.lua +++ b/src/modules/network.lua @@ -5,8 +5,8 @@ local sys = require 'sys' return function(update_freq, config, common, width, point) local geo = config.geometry - local PLOT_SEC_BREAK = geo.plot.sec_break - local PLOT_HEIGHT = geo.plot.height + local plot_sec_break = geo.plot.sec_break + local plot_height = geo.plot.height local interface_paths = sys.get_net_interface_paths() local get_bits = function(path) @@ -41,10 +41,11 @@ return function(update_freq, config, common, width, point) point.x, y, width, - PLOT_HEIGHT, + plot_height, + geo.plot.ticks_y, value_format_function, common.converted_y_label_format_generator('b'), - PLOT_SEC_BREAK, + plot_sec_break, label, 2, update_freq, @@ -52,7 +53,7 @@ return function(update_freq, config, common, width, point) ) return common.mk_acc( width, - PLOT_HEIGHT + PLOT_SEC_BREAK, + plot_height + plot_sec_break, function() common.update_rate_timeseries(obj, mod_state[key]) end, pure.partial(common.tagged_scaled_timeseries_draw_static, obj), pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj) @@ -71,7 +72,7 @@ return function(update_freq, config, common, width, point) width = width, set_state = read_interfaces, top = { - {mk_rx, true, PLOT_SEC_BREAK}, + {mk_rx, true, plot_sec_break}, {mk_tx, true, 0}, } } diff --git a/src/modules/power.lua b/src/modules/power.lua index a8da106..c211c2e 100644 --- a/src/modules/power.lua +++ b/src/modules/power.lua @@ -4,8 +4,8 @@ local sys = require 'sys' return function(update_freq, config, common, width, point) local geo = config.geometry - local PLOT_SEC_BREAK = geo.plot.sec_break - local PLOT_HEIGHT = geo.plot.height + local plot_sec_break = geo.plot.sec_break + local plot_height = geo.plot.height local power_label_function = function(plot_max) local fmt = common.y_label_format_string(plot_max, 'W') @@ -30,10 +30,11 @@ return function(update_freq, config, common, width, point) point.x, y, width, - PLOT_HEIGHT, + plot_height, + geo.plot.ticks_y, format_rapl, power_label_function, - PLOT_SEC_BREAK, + plot_sec_break, label, 0, update_freq, @@ -41,7 +42,7 @@ return function(update_freq, config, common, width, point) ) return common.mk_acc( width, - PLOT_HEIGHT + PLOT_SEC_BREAK, + plot_height + plot_sec_break, function(_) common.update_rate_timeseries(obj, read_joules()) end, mk_static(obj), mk_dynamic(obj) @@ -72,17 +73,18 @@ return function(update_freq, config, common, width, point) point.x, y, width, - PLOT_HEIGHT, + plot_height, + geo.plot.ticks_y, format_ac, power_label_function, - PLOT_SEC_BREAK, + plot_sec_break, 'Battery Draw', 0, update_freq ) return common.mk_acc( width, - PLOT_HEIGHT + PLOT_SEC_BREAK, + plot_height + plot_sec_break, function() common.tagged_scaled_timeseries_set( obj, diff --git a/src/modules/processor.lua b/src/modules/processor.lua index 02d38d9..b9e979d 100644 --- a/src/modules/processor.lua +++ b/src/modules/processor.lua @@ -7,16 +7,16 @@ local pure = require 'pure' local __math_floor = math.floor return function(update_freq, main_state, config, common, width, point) + local dial_inner_radius = 30 + local dial_outer_radius = 42 + local dial_thickness = 5.5 + local dial_y_spacing = 20 + local geo = config.geometry - local DIAL_INNER_RADIUS = 30 - local DIAL_OUTER_RADIUS = 42 - local DIAL_THICKNESS = 5.5 - 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 + local sep_spacing = geo.sep_spacing + local text_spacing = geo.text_spacing + local plot_sec_break = geo.plot.sec_break + local plot_height = geo.plot.height ----------------------------------------------------------------------------- -- processor state @@ -52,26 +52,26 @@ return function(update_freq, main_state, config, common, width, point) local dial_x = point.x + (core_cols == 1 and (width / 2) - or (config.core_padding + DIAL_OUTER_RADIUS + - (width - 2 * (DIAL_OUTER_RADIUS + config.core_padding)) + or (config.core_padding + dial_outer_radius + + (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_Y_SPACING) + local dial_y = y + dial_outer_radius + + (2 * dial_outer_radius + dial_y_spacing) * math.floor((c - 1) / core_cols) return { loads = common.make_compound_dial( dial_x, dial_y, - DIAL_OUTER_RADIUS, - DIAL_INNER_RADIUS, - DIAL_THICKNESS, + dial_outer_radius, + dial_inner_radius, + dial_thickness, 80, nthreads ), coretemp = common.make_text_circle( dial_x, dial_y, - DIAL_INNER_RADIUS - 2, + dial_inner_radius - 2, '%s°C', 80, __math_floor @@ -116,8 +116,8 @@ return function(update_freq, main_state, config, common, width, point) end return common.mk_acc( width, - (DIAL_OUTER_RADIUS * 2 + DIAL_Y_SPACING) * config.core_rows - - DIAL_Y_SPACING, + (dial_outer_radius * 2 + dial_y_spacing) * config.core_rows + - dial_y_spacing, update, static, dynamic @@ -133,7 +133,7 @@ return function(update_freq, main_state, config, common, width, point) point.x, y, width, - TEXT_SPACING, + text_spacing, {'HWP Preference', 'Ave Freq'} ) local update = function() @@ -149,7 +149,7 @@ return function(update_freq, main_state, config, common, width, point) local dynamic = pure.partial(common.text_rows_draw_dynamic, cpu_status) return common.mk_acc( width, - TEXT_SPACING, + text_spacing, update, static, dynamic @@ -164,8 +164,9 @@ return function(update_freq, main_state, config, common, width, point) point.x, y, width, - PLOT_HEIGHT, - PLOT_SECTION_BREAK, + plot_height, + geo.plot.ticks_y, + plot_sec_break, "Total Load", update_freq ) @@ -178,7 +179,7 @@ return function(update_freq, main_state, config, common, width, point) end return common.mk_acc( width, - PLOT_HEIGHT + PLOT_SECTION_BREAK, + plot_height + plot_sec_break, update, pure.partial(common.tagged_percent_timeseries_draw_static, total_load), pure.partial(common.tagged_percent_timeseries_draw_dynamic, total_load) @@ -230,12 +231,12 @@ return function(update_freq, main_state, config, common, width, point) width = width, set_state = update_state, top = { - {mk_cores, show_cores, TEXT_SPACING}, - {mk_hwp_freq, config.show_stats, SEPARATOR_SPACING}, + {mk_cores, show_cores, text_spacing}, + {mk_hwp_freq, config.show_stats, sep_spacing}, }, common.mk_section( - SEPARATOR_SPACING, - {mk_load_plot, config.show_plot, TABLE_SECTION_BREAK}, + sep_spacing, + {mk_load_plot, config.show_plot, geo.table.sec_break}, {mk_tbl, config.table_rows > 0, 0} ) } diff --git a/src/modules/readwrite.lua b/src/modules/readwrite.lua index 5824d44..e65ced9 100644 --- a/src/modules/readwrite.lua +++ b/src/modules/readwrite.lua @@ -6,8 +6,8 @@ local impure = require 'impure' return function(update_freq, config, common, width, point) local geo = config.geometry - local PLOT_SEC_BREAK = geo.plot.sec_break - local PLOT_HEIGHT = geo.plot.height + local plot_sec_break = geo.plot.sec_break + local plot_height = geo.plot.height local mod_state = {read = 0, write = 0} local device_paths = sys.get_disk_paths(config.devices) @@ -34,10 +34,11 @@ return function(update_freq, config, common, width, point) point.x, y, width, - PLOT_HEIGHT, + plot_height, + geo.plot.ticks_y, format_value_function, common.converted_y_label_format_generator('B'), - PLOT_SEC_BREAK, + plot_sec_break, label, 2, update_freq, @@ -45,7 +46,7 @@ return function(update_freq, config, common, width, point) ) return common.mk_acc( width, - PLOT_HEIGHT + PLOT_SEC_BREAK, + plot_height + plot_sec_break, function() common.update_rate_timeseries(obj, mod_state[key]) end, pure.partial(common.tagged_scaled_timeseries_draw_static, obj), pure.partial(common.tagged_scaled_timeseries_draw_dynamic, obj) @@ -64,7 +65,7 @@ return function(update_freq, config, common, width, point) width = width, set_state = update_state, top = { - {mk_reads, true, PLOT_SEC_BREAK}, + {mk_reads, true, plot_sec_break}, {mk_writes, true, 0}, } } diff --git a/src/modules/system.lua b/src/modules/system.lua index 4c14193..ddda7c1 100644 --- a/src/modules/system.lua +++ b/src/modules/system.lua @@ -2,7 +2,7 @@ local i_o = require 'i_o' local pure = require 'pure' return function(main_state, config, common, width, point) - local TEXT_SPACING = config.geometry.text_spacing + local text_spacing = config.geometry.text_spacing local __string_match = string.match @@ -11,7 +11,7 @@ return function(main_state, config, common, width, point) point.x, y, width, - TEXT_SPACING, + text_spacing, {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'} ) -- just update this once @@ -35,7 +35,7 @@ return function(main_state, config, common, width, point) local dynamic = pure.partial(common.text_rows_draw_dynamic, obj) return common.mk_acc( width, - TEXT_SPACING * 3, + text_spacing * 3, update, static, dynamic From 554a8ced0dd0796a0e6a12a0a942543a985cccf2 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 16 Aug 2022 23:52:25 -0400 Subject: [PATCH 10/11] REF make id's more legit --- src/modules/filesystem.lua | 12 ++++++------ src/modules/graphics.lua | 6 ++++-- src/modules/memory.lua | 3 ++- src/modules/pacman.lua | 6 +++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/modules/filesystem.lua b/src/modules/filesystem.lua index 61cf74b..1e3ae97 100644 --- a/src/modules/filesystem.lua +++ b/src/modules/filesystem.lua @@ -4,8 +4,8 @@ local impure = require 'impure' return function(main_state, config, common, width, point) local geo = config.geometry - local SPACING = geo.bar_spacing - local SEPARATOR_SPACING = geo.sep_spacing + local bar_spacing = geo.bar_spacing + local separator_bar_spacing = geo.sep_spacing ----------------------------------------------------------------------------- -- smartd @@ -50,7 +50,7 @@ return function(main_state, config, common, width, point) -- relative to the right edge of the text column geo.bar_pad, names, - SPACING, + bar_spacing, 12, 80 ) @@ -64,7 +64,7 @@ return function(main_state, config, common, width, point) end return common.mk_acc( width, - (#config.fs_paths - 1) * SPACING, + (#config.fs_paths - 1) * bar_spacing, update, pure.partial(common.compound_bar_draw_static, obj), pure.partial(common.compound_bar_draw_dynamic, obj) @@ -79,7 +79,7 @@ return function(main_state, config, common, width, point) point = point, width = width, set_state = nil, - top = {{mk_smart, config.show_smart, SEPARATOR_SPACING}}, - common.mk_section(SEPARATOR_SPACING, {mk_bars, true, 0}) + top = {{mk_smart, config.show_smart, separator_bar_spacing}}, + common.mk_section(separator_bar_spacing, {mk_bars, true, 0}) } end diff --git a/src/modules/graphics.lua b/src/modules/graphics.lua index add0293..fa5e443 100644 --- a/src/modules/graphics.lua +++ b/src/modules/graphics.lua @@ -2,13 +2,15 @@ local pure = require 'pure' local i_o = require 'i_o' return function(update_freq, config, common, width, point) + local NA = 'N/A' + local NVIDIA_EXE = 'nvidia-settings' + local geo = config.geometry local sep_spacing = geo.sep_spacing local text_spacing = geo.text_spacing local plot_sec_break = geo.plot.sec_break local plot_height = geo.plot.height - local NA = 'N/A' - local NVIDIA_EXE = 'nvidia-settings' + local __string_match = string.match local __string_format = string.format local __tonumber = tonumber diff --git a/src/modules/memory.lua b/src/modules/memory.lua index e7f1b7a..699c6e6 100644 --- a/src/modules/memory.lua +++ b/src/modules/memory.lua @@ -5,12 +5,13 @@ local pure = require 'pure' local sys = require 'sys' return function(update_freq, config, common, width, point) - local geo = config.geometry local dial_thickness = 8 local dial_radius = 32 local dial_x_spacing = 40 local cache_y_offset = 7 local cache_x_offset = 50 + + local geo = config.geometry local plot_sec_break = geo.plot.sec_break local plot_height = geo.plot.height local table_sec_break = geo.table.sec_break diff --git a/src/modules/pacman.lua b/src/modules/pacman.lua index 88130f8..156bc82 100644 --- a/src/modules/pacman.lua +++ b/src/modules/pacman.lua @@ -1,7 +1,7 @@ local pure = require 'pure' return function(main_state, config, common, width, point) - local TEXT_SPACING = config.geometry.text_spacing + local text_spacing = config.geometry.text_spacing local __string_match = string.match local __string_gmatch = string.gmatch @@ -11,7 +11,7 @@ return function(main_state, config, common, width, point) point.x, y, width, - TEXT_SPACING, + text_spacing, {'Total', 'Explicit', 'Outdated', 'Orphaned', 'Local'} ) local update = function() @@ -33,7 +33,7 @@ return function(main_state, config, common, width, point) end return common.mk_acc( width, - TEXT_SPACING * 4, + text_spacing * 4, update, pure.partial(common.text_rows_draw_static, obj), pure.partial(common.text_rows_draw_dynamic, obj) From 1f1e10ad94df2a30bb33273515c0aa3ef2162c9b Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 16 Aug 2022 23:53:45 -0400 Subject: [PATCH 11/11] ENH get rid of dead config bits --- config/config.dhall | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/config/config.dhall b/config/config.dhall index 933d4c9..0b9752d 100644 --- a/config/config.dhall +++ b/config/config.dhall @@ -152,13 +152,8 @@ let Font = } let PlotGeometry = - { Type = - { spacing : Natural - , height : Natural - , seconds : Natural - , ticks_x : Natural - } - , default = { seconds = 90, ticks_x = 9, height = 56, spacing = 20 } + { Type = { seconds : Natural, ticks_x : Natural } + , default = { seconds = 90, ticks_x = 9 } } let TableGeometry =