luaa: use fg/bg as keys for colors
[awesome.git] / lib / beautiful.lua.in
blobd1f8ff3d926ff0779f8cf18e35489ccb3b1f786b
1 ----------------------------------------------------------------------------
2 -- @author Damien Leone <damien.leone@gmail.com>
3 -- @author Julien Danjou <julien@danjou.info>
4 -- @copyright 2008 Damien Leone, Julien Danjou
5 -- @release @AWESOME_VERSION@
6 ----------------------------------------------------------------------------
8 -- Grab environment
9 local io = io
10 local print = print
11 local setmetatable = setmetatable
12 local util = require("awful.util")
13 local package = package
14 local capi =
16 screen = screen,
17 awesome = awesome,
18 image = image
21 local module_name = "beautiful"
23 --- beautiful: theme library
24 module("beautiful")
26 -- Local data
27 local theme = {}
29 --- Split line in two if it contains the '=' character.
30 -- @param line The line to split.
31 -- @return nil if the '=' character is not in the string
32 local function split_line(line)
33 local split_val = line:find('=')
35 if split_val and line:sub(1, 1) ~= '#' and line:sub(1, 2) ~= '--' then
36 -- Remove spaces and tabulations in key
37 local key = line:sub(1, split_val - 1):gsub(' ', ''):gsub('\t', '')
38 -- and extra spaces and tabulations before value
39 local value = line:sub(split_val + 1, -1)
40 while value:sub(1, 1) == ' ' or value:sub(1, 1) == '\t' do
41 value = value:sub(2, -1)
42 end
44 return key, value
45 end
46 end
48 --- Get a value directly.
49 -- @param key The key.
50 -- @return The value.
51 function __index(self, key)
52 if theme[key] then
53 return theme[key]
54 end
55 end
57 --- Init function, should be runned at the beginning of configuration file.
58 -- @param path The theme file path.
59 function init(path)
60 if path then
61 local f = io.open(path)
63 if not f then
64 return print("E: unable to load theme " .. path)
65 end
67 for line in f:lines() do
68 local key, value
69 key, value = split_line(line)
70 if key then
71 if key == "wallpaper_cmd" then
72 for s = 1, capi.screen.count() do
73 util.spawn(value, s)
74 end
75 elseif key == "font" then
76 capi.awesome.font = value
77 elseif key == "fg_normal" then
78 capi.awesome.fg = value
79 elseif key == "bg_normal" then
80 capi.awesome.bg = value
81 end
82 -- Store.
83 theme[key] = value
84 end
85 end
86 f:close()
87 end
88 end
90 --- Get the current theme.
91 -- @return The current theme table.
92 function get()
93 return package.loaded[module_name]
94 end
96 setmetatable(package.loaded[module_name], package.loaded[module_name])
98 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80