[themes] Add font and background colors to themes

Themes can now specify "fg" (font color) and "bg" (background color) on
all levels.
This commit is contained in:
Tobias Witek 2016-10-31 07:54:18 +01:00
parent 8538f272d6
commit 7b48b08365
3 changed files with 14 additions and 4 deletions

View file

@ -12,7 +12,9 @@ class i3bar(bumblebee.output.Output):
theme = obj.theme() theme = obj.theme()
data = { data = {
"full_text": "{}{}{}".format(theme.prefix(obj), obj.data(), theme.suffix(obj)) "full_text": "{}{}{}".format(theme.prefix(obj), obj.data(), theme.suffix(obj)),
"color": theme.color(obj),
"background": theme.background(obj)
} }
if theme.default_separators(obj) == False: if theme.default_separators(obj) == False:
data["separator"] = False data["separator"] = False

View file

@ -13,7 +13,7 @@ class Theme:
module = obj.__module__.split(".")[-1] module = obj.__module__.split(".")[-1]
module_theme = self._data.get(module, {}) module_theme = self._data.get(module, {})
value = getattr(obj, key)() if hasattr(obj, key) else "" value = getattr(obj, key)() if hasattr(obj, key) else None
value = self._defaults.get(key, value) value = self._defaults.get(key, value)
value = module_theme.get(key, value) value = module_theme.get(key, value)
@ -25,6 +25,12 @@ class Theme:
return value return value
def color(self, obj):
return self._gettheme(obj, "fg")
def background(self, obj):
return self._gettheme(obj, "bg")
def default_separators(self, obj): def default_separators(self, obj):
return self._gettheme(obj, "default_separators") return self._gettheme(obj, "default_separators")

View file

@ -7,10 +7,12 @@
"prefix": "bat ", "prefix": "bat ",
"states": { "states": {
"charging": { "charging": {
"suffix": "+ " "suffix": "+ ",
"fg": "#00ff00"
}, },
"discharging": { "discharging": {
"suffix": "- " "suffix": "- ",
"fg": "#ff0000"
} }
} }
}, },