From 0c06d37899e150da68e84e1c8d23fb584aedfc3e Mon Sep 17 00:00:00 2001 From: Alexis BRENON Date: Tue, 20 Jan 2015 15:37:35 +0100 Subject: [PATCH] [beautiful] Beautiful initialization handle path or table Allow beautiful to be initialized either with a path to the theme file or directly with a table --- lib/beautiful.lua.in | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/beautiful.lua.in b/lib/beautiful.lua.in index 54856821b..e63a37cae 100644 --- a/lib/beautiful.lua.in +++ b/lib/beautiful.lua.in @@ -72,16 +72,24 @@ function beautiful.get_font_height(name) end --- Init function, should be runned at the beginning of configuration file. --- @param path The theme file path. -function beautiful.init(path) - if path then +-- @param config The theme to load. It can be either the path to the theme file +-- (returning a table) or directly the table containing all the theme values +function beautiful.init(config) + if config then local success - - -- try and grab user's $HOME directory and expand '~' local homedir = os.getenv("HOME") - path = path:gsub("^~/", homedir .. "/") - success, theme = pcall(function() return dofile(path) end) + -- If config is the path to the theme file, + -- run this file, + -- else if it is the theme table, save it + if type(config) == 'string' then + -- Expand the '~' $HOME shortcut + config = config:gsub("^~/", homedir .. "/") + success, theme = pcall(function() return dofile(config) end) + elseif type(config) == 'table' then + success = true + theme = config + end if not success then return print("E: beautiful: error loading theme file " .. theme) @@ -95,10 +103,10 @@ function beautiful.init(path) if theme.font then set_font(theme.font) end else - return print("E: beautiful: error loading theme file " .. path) + return print("E: beautiful: error loading theme file " .. config) end else - return print("E: beautiful: error loading theme: no path specified") + return print("E: beautiful: error loading theme: no theme specified") end end