From 4855b1aa0ac15bb27552694c708afcaa926e1e61 Mon Sep 17 00:00:00 2001 From: me Date: Fri, 31 Jan 2020 12:09:45 +0200 Subject: [PATCH] extract add_prefix() method --- bumblebee/output.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/bumblebee/output.py b/bumblebee/output.py index 4f5afca..89a0fd1 100644 --- a/bumblebee/output.py +++ b/bumblebee/output.py @@ -350,6 +350,23 @@ class WidgetDrawer(object): "separator_block_width": self._theme.separator_block_width(widget), }) + def add_prefix(self, widget, padding): + """add prefix to full_text""" + self._prefix = self._theme.prefix(widget, padding) + + if self._markup == "pango": + # add prefix/suffix colors + fg = self._theme.prefix_fg(widget) + bg = self._theme.prefix_bg(widget) + self._prefix = "{}".format( + "foreground='{}'".format(fg) if fg else "", + "background='{}'".format(bg) if bg else "", + self._prefix + ) + + if self._prefix: + self._full_text = u"{}{}".format(self._prefix, self._full_text) + def draw(self, widget, module=None, engine=None): """ Keep the same argument signature as I3BarOutput.draw() @@ -373,21 +390,10 @@ class WidgetDrawer(object): padding = self._theme.padding(widget) - self._prefix = self._theme.prefix(widget, padding) + self.add_prefix(widget, padding) + self._suffix = self._theme.suffix(widget, padding) - if self._markup == "pango": - # add prefix/suffix colors - fg = self._theme.prefix_fg(widget) - bg = self._theme.prefix_bg(widget) - self._prefix = "{}".format( - "foreground='{}'".format(fg) if fg else "", - "background='{}'".format(bg) if bg else "", - self._prefix - ) - - if self._prefix: - self._full_text = u"{}{}".format(self._prefix, self._full_text) if self._suffix: self._full_text = u"{}{}".format(self._full_text, self._suffix)