ENH use conky.conf as bootstrap file for config loading/validation

This commit is contained in:
Nathan Dwarshuis 2022-07-19 19:15:26 -04:00
parent c9918ba358
commit 3486e37a43
6 changed files with 99 additions and 29 deletions

View File

@ -1,3 +1,6 @@
bootstrap:
update_interval: 1
dimensions: [1920, 1080]
modules:
filesystem:
show_smart: true

View File

@ -4,7 +4,24 @@ required: [modules, layout]
additionalProperties: false
properties:
bootstrap:
required: [update_interval, dimensions]
additionalProperties: false
properties:
update_interval:
description: the update interval (seconds)
type: number
dimensions:
description: the max width/height of the conky window
type: array
minItems: 2
maxItems: 2
items:
type: integer
minimum: 1
modules:
required: [filesystem, graphics, memory, power, processor, readwrite]
additionalProperties: false
properties:
filesystem:

View File

@ -1,6 +1,72 @@
local update_interval = 1 -- in seconds
--------------------------------------------------------------------------------
-- set up paths
local conky_dir = debug.getinfo(1).source:match("@?(.*/)")
local subdirs = {
'?.lua',
'drawing/?.lua',
'schema/?.lua',
'core/?.lua',
'core/widget/?.lua',
'core/widget/arc/?.lua',
'core/widget/text/?.lua',
'core/widget/timeseries/?.lua',
'core/widget/rect/?.lua',
'core/widget/line/?.lua',
'lib/share/lua/5.4/?.lua',
'lib/share/lua/5.4/?/init.lua',
}
for i = 1, #subdirs do
subdirs[i] = conky_dir..subdirs[i]
end
package.path = table.concat(subdirs, ';')
package.cpath = conky_dir..'lib/lib/lua/5.4/?.so;'
--------------------------------------------------------------------------------
-- select global config to use (fallback to default if none found)
local yaml = require 'lyaml'
local i_o = require 'i_o'
local schema_path = conky_dir..'/config/schema.yml'
local try_config_paths = {
'/home/ndwar/.config/conky.yml',
conky_dir..'config/fallback.yml'
}
local config_path
local config
for i = 1, #try_config_paths do
config_path = try_config_paths[i]
local r = i_o.read_file(config_path)
if r ~= nil then
config = yaml.load(r)
break
end
end
i_o.printf('Using config at %s', config_path)
if i_o.exit_code_cmd('command -v yajsv > /dev/null') == 0 then
local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path)
assert(i_o.exit_code_cmd(cmd) == 0, 'ERROR: config failed validation')
else
print(string.format('WARNING: could not validate config'))
end
local bootstrap = config.bootstrap
local startup_hook = string.format(
'start %f %s %s %s',
bootstrap.update_interval,
config_path,
package.path,
package.cpath
)
conky.config = {
background = false,
@ -18,9 +84,8 @@ conky.config = {
xinerama_head = 0,
double_buffer = true,
-- TODO don't hardcode screen size here
minimum_width = 1920,
minimum_height = 1080,
minimum_width = bootstrap.dimensions[1],
minimum_height = bootstrap.dimensions[2],
draw_shades = false,
draw_outline = false,
@ -34,7 +99,7 @@ conky.config = {
-- Lua Load
lua_load = conky_dir..'main.lua',
lua_draw_hook_post = 'main',
lua_startup_hook = string.format('start %f %s', update_interval, conky_dir)
lua_startup_hook = startup_hook
}
--control updates entirely in lua

2
core

@ -1 +1 @@
Subproject commit aa0d02748b4316c44e21cc4af24727aba82159ff
Subproject commit 8f1495175f08bdc0716ef11b73d3babb10874c8b

View File

@ -146,7 +146,10 @@ end
return function(update_interval, config_path)
local update_freq = 1 / update_interval
local config = yaml.load(i_o.read_file(config_path))
local default_config = 'config.yml'
-- local r = i_o.read_file(config_path) or i_o.read_file(default_config)
local r = i_o.read_file(config_path) or i_o.read_file(default_config)
local config = yaml.load(r)
local cmods = config.modules
local main_state = {}

View File

@ -8,27 +8,9 @@ local __cairo_create
local __cairo_surface_destroy
local __cairo_destroy
function conky_start(update_interval, conky_dir)
local subdirs = {
'?.lua',
'drawing/?.lua',
'schema/?.lua',
'core/?.lua',
'core/widget/?.lua',
'core/widget/arc/?.lua',
'core/widget/text/?.lua',
'core/widget/timeseries/?.lua',
'core/widget/rect/?.lua',
'core/widget/line/?.lua',
'lib/share/lua/5.4/?.lua',
'lib/share/lua/5.4/?/init.lua',
}
for i = 1, #subdirs do
package.path = package.path..';'..conky_dir..subdirs[i]
end
package.cpath = package.cpath..';'..conky_dir..'lib/lib/lua/5.4/?.so;'
function conky_start(update_interval, config_path, path, cpath)
package.path = package.path..';'..path
package.cpath = package.cpath..';'..cpath
require 'cairo'
@ -41,7 +23,7 @@ function conky_start(update_interval, conky_dir)
conky_set_update_interval(update_interval)
draw_dynamic = compile(update_interval, conky_dir..'config.yml')
draw_dynamic = compile(update_interval, config_path)
end
--------------------------------------------------------------------------------