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 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 = let Graphics =
{ dev_power : Text { dev_power : Text
@ -56,14 +58,14 @@ let Modules =
} }
let ModType = let ModType =
< FileSystem < fileSystem
| Graphics | graphics
| Memory | memory
| Network | network
| Pacman | pacman
| Processor | processor
| ReadWrite | readwrite
| System | system
> >
let Block = < Pad : Natural | Mod : ModType > let Block = < Pad : Natural | Mod : ModType >
@ -220,50 +222,40 @@ let Theme =
{ font = Font::{=}, geometry = Geometry::{=}, patterns = Patterns::{=} } { font = Font::{=}, geometry = Geometry::{=}, patterns = Patterns::{=} }
} }
let layout = let Bootstrap = { update_interval : Natural, dimensions : Point }
{ 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 = let Config =
Modules::{ { bootstrap : Bootstrap
, memory = Some , theme : Theme.Type
( { show_stats = False , layout : Layout
, show_swap = False , modules : Modules.Type
, 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 } } let toConfig =
, theme = Theme::{=} \(i : Natural) ->
, layout \(d : Point) ->
, modules \(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 yaml = require 'lyaml'
local i_o = require 'i_o' local i_o = require 'i_o'
local schema_path = conky_dir..'/config/schema.yml' -- local schema_path = conky_dir..'/config/schema.yml'
local validate_config -- local validate_config
if i_o.exe_exists('yajsv') then -- if i_o.exe_exists('yajsv') then
validate_config = function(config_path) -- validate_config = function(config_path)
local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path) -- local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path)
return i_o.exit_code_cmd(cmd) == 0 -- return i_o.exit_code_cmd(cmd) == 0
end -- end
else -- else
validate_config = function(_) -- validate_config = function(_)
i_o.warnf('could not validate config') -- i_o.warnf('could not validate config')
return true -- return true
end -- 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 end
local find_valid_config = function(paths) local find_valid_config = function(paths)
for i = 1, #paths do for i = 1, #paths do
local path = paths[i] local path = paths[i]
local r = i_o.read_file(path) local rc = try_read_config(path)
if r ~= nil then if rc == 0 then
if validate_config(path) then i_o.infof('Using config at %s', path)
i_o.infof('Using config at %s', path) return yaml.load(i_o.read_file(config_path))
return path, yaml.load(r)
else
i_o.warnf('%s did not pass; trying next', path)
end
else else
i_o.infof('could not find %s; trying next', path) i_o.warnf('could not read %s; trying next', path)
end end
end end
i_o.assertf(false, 'ERROR: could not load valid config') i_o.assertf(false, 'could not load valid config')
end end
local get_config_dir = function() local get_config_dir = function()
@ -93,11 +97,11 @@ local get_config_dir = function()
end end
local try_config_paths = { local try_config_paths = {
get_config_dir()..'conky.yml', get_config_dir()..'conky.dhall',
conky_dir..'config/fallback.yml' 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 local bootstrap = config.bootstrap
@ -125,8 +129,8 @@ conky.config = {
xinerama_head = 0, xinerama_head = 0,
double_buffer = true, double_buffer = true,
minimum_width = bootstrap.dimensions[1], minimum_width = bootstrap.dimensions.x,
minimum_height = bootstrap.dimensions[2], minimum_height = bootstrap.dimensions.y,
draw_shades = false, draw_shades = false,
draw_outline = false, draw_outline = false,

View File

@ -15,6 +15,7 @@ local rgba = function(hex, alpha)
a = alpha, a = alpha,
} }
) )
print(hex, obj.r, obj.g, obj.b)
return err.set_type(obj, "color") return err.set_type(obj, "color")
end end
@ -65,10 +66,15 @@ compile_patterns = function(patterns)
r[k] = rgb(v) r[k] = rgb(v)
elseif v.color ~= nil then elseif v.color ~= nil then
r[k] = rgba(v.color, v.alpha) r[k] = rgba(v.color, v.alpha)
elseif v.gradient ~= nil then elseif #v > 0 then
r[k] = compile_gradient(v.gradient) if v[1].alpha ~= nil then
elseif v.gradient_alpha ~= nil then r[k] = compile_gradient_alpha(v)
r[k] = compile_gradient_alpha(v.gradient_alpha) else
-- for k, v in pairs(compile_gradient(v)) do
-- print(k, v.r)
-- end
r[k] = compile_gradient(v)
end
else else
r[k] = compile_patterns(v) r[k] = compile_patterns(v)
end 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 acc.next_x = acc.next_x + panel_mods
else else
local margins = panel_mods.margins local margins = panel_mods.margins
local margin_x = margins[1] local margin_x = margins.x
local margin_y = margins[2] local margin_y = margins.y
local mpoint = geom.make_point(acc.next_x + margin_x, y + margin_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 r = arrange_panel_modules(common_, mods, mpoint, panel_mods.columns)
local w = r.width + margin_x * 2 local w = r.width + margin_x * 2
@ -163,9 +163,11 @@ return function(update_interval, config_path)
pacman = pure.partial(pacman, main_state) pacman = pure.partial(pacman, main_state)
} }
local anchor = config.layout.anchor
local compiled = compile_layout( local compiled = compile_layout(
common(config), common(config),
geom.make_point(table.unpack(config.layout.anchor)), geom.make_point(anchor.x, anchor.y),
mods, mods,
config.layout.panels config.layout.panels
) )

View File

@ -104,8 +104,8 @@ return function(config)
-- timeseries helper functions -- timeseries helper functions
local _default_grid_config = timeseries.grid_config( local _default_grid_config = timeseries.grid_config(
geometry.plot.ticks[1], geometry.plot.ticks.x,
geometry.plot.ticks[2], geometry.plot.ticks.y,
patterns.plot.grid patterns.plot.grid
) )
@ -615,8 +615,8 @@ return function(config)
local gtable = geometry.table local gtable = geometry.table
local padding = gtable.padding local padding = gtable.padding
local xpad = padding[1] local xpad = padding.x
local ypad = padding[2] local ypad = padding.y
local default_table_font_spec = make_font_spec(font_family, font_sizes.table, false) local default_table_font_spec = make_font_spec(font_family, font_sizes.table, false)