[core] Add prefix/postfix support

This commit is contained in:
Tobias Witek 2020-02-24 14:54:11 +01:00
parent 37e1deaa6f
commit 1a093a73b1
4 changed files with 23 additions and 4 deletions

View file

@ -38,6 +38,18 @@ class i3(object):
def stop(self):
return { 'suffix': '\n]' }
def __pad(self, module, widget, full_text):
padding = self._theme.padding()
if not full_text: return padding
return '{}{}{}'.format(padding, full_text, padding)
def __decorate(self, module, widget, full_text):
return '{}{}{}'.format(
self.__pad(module, widget, self._theme.prefix(widget)),
full_text,
self.__pad(module, widget, self._theme.suffix(widget))
)
def __common_attributes(self, module, widget):
return {
'separator': self._theme.default_separators(),
@ -64,7 +76,7 @@ class i3(object):
def __main(self, module, widget):
attr = self.__common_attributes(module, widget)
attr.update({
'full_text': widget.full_text(),
'full_text': self.__decorate(module, widget, widget.full_text()),
'color': self._theme.fg(widget),
'background': self._theme.bg(widget),
})

View file

@ -39,6 +39,8 @@ class Theme(object):
('border-bottom', 0),
('border-left', 0),
('border-right', 0),
('padding', ''),
('prefix', ''), ('suffix', ''),
]:
setattr(self, attr.replace('-', '_'), lambda widget=None, default=default, attr=attr: self.__get(widget, attr, default))
@ -77,6 +79,11 @@ class Theme(object):
tmp = tmp[self.__widget_count % len(tmp)]
value = tmp.get(key, value)
value = self.__data.get(key, value)
if widget.module():
value = self.__get(None, widget.module().name(), {}).get(key, value)
if not key in widget.state():
for state in widget.state():
theme = self.__get(widget, state, {})

View file

@ -15,7 +15,9 @@ class Widget(util.store.Store, core.input.Object):
return self._full_text(self)
return self._full_text
def module(self, module):
def module(self, module=None):
if not module:
return self._module
self._module = module
def state(self):

View file

@ -14,14 +14,12 @@
## Backwards-compatibility
- aliases
- icons (prefix/postfix)
- charts (braille)
- minimize modules
- hide modules if not in warning/error state (-a)
- WAL support / colorscheme support
- tkinter / popups
- scrolling decorator (incl. minwidth, alignment)
- states
## Improvements
- pango output (improve - maybe autodetect? see #531)