ENH use disgusting yaml union type hack for module layout

This commit is contained in:
Nathan Dwarshuis 2022-08-12 00:20:01 -04:00
parent 53544b347e
commit c50a704c0f
8 changed files with 77 additions and 105 deletions

View File

@ -38,38 +38,21 @@ let Power = { battery : Text, rapl_specs : List RaplSpec }
let ReadWrite = { devices : List Text } 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 = let ModType =
< filesystem < filesystem : FileSystem
| graphics | graphics : Graphics
| memory | memory : Memory
| network | network
| pacman | pacman
| processor | processor : Processor
| power | power : Power
| readwrite | readwrite : ReadWrite
| system | 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 } let Column_ = { blocks : List Block, width : Natural }
@ -153,18 +136,18 @@ let Pattern =
| GradientRGBA : List StopRGBA | GradientRGBA : List StopRGBA
> >
let Annotated = \(a : Type) -> { type : Text, data : a } let annotatePattern =
let annotate =
\(a : Pattern) -> \(a : Pattern) ->
{ type = showConstructor a, data = a } : Annotated Pattern { type = showConstructor a, data = a } : Annotated Pattern
let mod = \(a : ModType) -> Block.Mod { type = showConstructor a, data = a }
let APattern = Annotated Pattern let APattern = Annotated Pattern
let symGradient = let symGradient =
\(c0 : Natural) -> \(c0 : Natural) ->
\(c1 : Natural) -> \(c1 : Natural) ->
annotate annotatePattern
( Pattern.GradientRGB ( Pattern.GradientRGB
[ { color = c0, stop = 0.0 } [ { color = c0, stop = 0.0 }
, { color = c1, stop = 0.5 } , { color = c1, stop = 0.5 }
@ -188,27 +171,28 @@ let Patterns =
{ bg : APattern, fg : { active : APattern, critical : APattern } } { bg : APattern, fg : { active : APattern, critical : APattern } }
} }
, default = , default =
{ header = annotate (Pattern.RGB 0xefefef) { header = annotatePattern (Pattern.RGB 0xefefef)
, panel.bg = annotate (Pattern.RGBA { color = 0x121212, alpha = 0.7 }) , panel.bg
= annotatePattern (Pattern.RGBA { color = 0x121212, alpha = 0.7 })
, text = , text =
{ active = annotate (Pattern.RGB 0xbfe1ff) { active = annotatePattern (Pattern.RGB 0xbfe1ff)
, inactive = annotate (Pattern.RGB 0xc8c8c8) , inactive = annotatePattern (Pattern.RGB 0xc8c8c8)
, critical = annotate (Pattern.RGB 0xff8282) , critical = annotatePattern (Pattern.RGB 0xff8282)
} }
, border = annotate (Pattern.RGB 0x888888) , border = annotatePattern (Pattern.RGB 0x888888)
, plot = , plot =
{ grid = annotate (Pattern.RGB 0x666666) { grid = annotatePattern (Pattern.RGB 0x666666)
, outline = annotate (Pattern.RGB 0x777777) , outline = annotatePattern (Pattern.RGB 0x777777)
, data = , data =
{ border = { border =
annotate annotatePattern
( Pattern.GradientRGB ( Pattern.GradientRGB
[ { color = 0x003f7c, stop = 0.0 } [ { color = 0x003f7c, stop = 0.0 }
, { color = 0x1e90ff, stop = 1.0 } , { color = 0x1e90ff, stop = 1.0 }
] ]
) )
, fill = , fill =
annotate annotatePattern
( Pattern.GradientRGBA ( Pattern.GradientRGBA
[ { color = 0x316ece, stop = 0.2, alpha = 0.5 } [ { color = 0x316ece, stop = 0.2, alpha = 0.5 }
, { color = 0x8cc7ff, stop = 1.0, alpha = 1.0 } , { color = 0x8cc7ff, stop = 1.0, alpha = 1.0 }
@ -238,23 +222,17 @@ let Theme =
let Bootstrap = { update_interval : Natural, dimensions : Point } let Bootstrap = { update_interval : Natural, dimensions : Point }
let Config = let Config = { bootstrap : Bootstrap, theme : Theme.Type, layout : Layout }
{ bootstrap : Bootstrap
, theme : Theme.Type
, layout : Layout
, modules : Modules.Type
}
let toConfig = let toConfig =
\(i : Natural) -> \(i : Natural) ->
\(d : Point) -> \(x : Natural) ->
\(y : Natural) ->
\(t : Theme.Type) -> \(t : Theme.Type) ->
\(l : Layout) -> \(l : Layout) ->
\(m : Modules.Type) -> { bootstrap = { update_interval = i, dimensions = { x, y } }
{ bootstrap = { update_interval = i, dimensions = d }
, theme = t , theme = t
, layout = l , layout = l
, modules = m
} }
: Config : Config
@ -264,7 +242,6 @@ in { toConfig
, ModType , ModType
, Layout , Layout
, Panel , Panel
, Modules
, FSPath , FSPath
, FileSystem , FileSystem
, Graphics , Graphics
@ -273,4 +250,5 @@ in { toConfig
, Power , Power
, ReadWrite , ReadWrite
, Theme , Theme
, mod
} }

View File

@ -1,5 +1,22 @@
let C = ./config.dhall 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 = let layout =
{ anchor = { x = 12, y = 11 } { anchor = { x = 12, y = 11 }
, panels = , panels =
@ -7,11 +24,11 @@ let layout =
{ columns = { columns =
[ C.Column.CCol [ C.Column.CCol
{ blocks = { blocks =
[ C.Block.Mod C.ModType.network [ C.mod C.ModType.network
, C.Block.Pad 10 , C.Block.Pad 10
, C.Block.Mod C.ModType.memory , C.mod memory
, C.Block.Pad 10 , C.Block.Pad 10
, C.Block.Mod C.ModType.processor , C.mod processor
] ]
, width = 436 , width = 436
} }
@ -19,29 +36,6 @@ let layout =
, margins = { x = 20, y = 10 } , 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 in C.toConfig 1 1920 1080 C.Theme::{=} layout

View File

@ -18,7 +18,8 @@ local reduce_modules_y = function(common_, modlist, init_x, width, acc, new)
if type(new) == "number" then if type(new) == "number" then
acc.next_y = acc.next_y + new acc.next_y = acc.next_y + new
else else
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( local r = common_.compile_module(
m.header, m.header,
m.point, m.point,
@ -147,19 +148,18 @@ end
return function(update_interval, config_path) return function(update_interval, config_path)
local update_freq = 1 / update_interval local update_freq = 1 / update_interval
local config = yaml.load(i_o.read_file(config_path)) local config = yaml.load(i_o.read_file(config_path))
local cmods = config.modules
local main_state = {} local main_state = {}
local mods = { local modlist = {
memory = pure.partial(memory, update_freq, cmods.memory), memory = pure.partial(memory, update_freq),
readwrite = pure.partial(readwrite, update_freq, cmods.readwrite), readwrite = pure.partial(readwrite, update_freq),
network = pure.partial(network, update_freq), network = pure.partial(network, update_freq),
power = pure.partial(power, update_freq, cmods.power), power = pure.partial(power, update_freq),
filesystem = pure.partial(filesystem, cmods.filesystem, main_state), filesystem = pure.partial(filesystem, main_state),
system = pure.partial(system, main_state), system = pure.partial(system, main_state),
graphics = pure.partial(graphics, update_freq, cmods.graphics), graphics = pure.partial(graphics, update_freq),
processor = pure.partial(processor, update_freq, cmods.processor, main_state), processor = pure.partial(processor, update_freq, main_state),
pacman = pure.partial(pacman, main_state) pacman = pure.partial(pacman, main_state)
} }
@ -168,7 +168,7 @@ return function(update_interval, config_path)
local compiled = compile_layout( local compiled = compile_layout(
common(config), common(config),
geom.make_point(anchor.x, anchor.y), geom.make_point(anchor.x, anchor.y),
mods, modlist,
config.layout.panels config.layout.panels
) )

View File

@ -2,7 +2,7 @@ local i_o = require 'i_o'
local pure = require 'pure' local pure = require 'pure'
local impure = require 'impure' local impure = require 'impure'
return function(config, main_state, common, width, point) return function(main_state, config, common, width, point)
local SPACING = 20 local SPACING = 20
local BAR_PAD = 100 local BAR_PAD = 100
local SEPARATOR_SPACING = 20 local SEPARATOR_SPACING = 20

View File

@ -3,7 +3,7 @@ local pure = require 'pure'
local i_o = require 'i_o' local i_o = require 'i_o'
local sys = require 'sys' 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_SEC_BREAK = 20
local PLOT_HEIGHT = 56 local PLOT_HEIGHT = 56
local interface_paths = sys.get_net_interface_paths() local interface_paths = sys.get_net_interface_paths()

View File

@ -1,6 +1,6 @@
local pure = require 'pure' local pure = require 'pure'
return function(main_state, common, width, point) return function(main_state, _, common, width, point)
local TEXT_SPACING = 20 local TEXT_SPACING = 20
local __string_match = string.match local __string_match = string.match

View File

@ -6,7 +6,7 @@ local pure = require 'pure'
local __math_floor = math.floor 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_INNER_RADIUS = 30
local DIAL_OUTER_RADIUS = 42 local DIAL_OUTER_RADIUS = 42
local DIAL_THICKNESS = 5.5 local DIAL_THICKNESS = 5.5

View File

@ -1,7 +1,7 @@
local i_o = require 'i_o' local i_o = require 'i_o'
local pure = require 'pure' local pure = require 'pure'
return function(main_state, common, width, point) return function(main_state, _, common, width, point)
local TEXT_SPACING = 20 local TEXT_SPACING = 20
local __string_match = string.match local __string_match = string.match