ENH update conky to use dhall

This commit is contained in:
Nathan Dwarshuis 2022-08-11 00:05:06 -04:00
parent e290ca79ad
commit 0c4172b149
6 changed files with 139 additions and 90 deletions

View File

@ -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
}

45
config/fallback.dhall Normal file
View File

@ -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

View File

@ -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
local rc = try_read_config(path)
if rc == 0 then
i_o.infof('Using config at %s', path)
return path, yaml.load(r)
return yaml.load(i_o.read_file(config_path))
else
i_o.warnf('%s did not pass; trying next', path)
end
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,

View File

@ -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

View File

@ -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
)

View File

@ -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)