ENH use disgusting yaml union type hack for module layout
This commit is contained in:
parent
53544b347e
commit
c50a704c0f
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue