diff --git a/bumblebee_status/modules/contrib/watson.py b/bumblebee_status/modules/contrib/watson.py index d7b260ba..a7173424 100644 --- a/bumblebee_status/modules/contrib/watson.py +++ b/bumblebee_status/modules/contrib/watson.py @@ -5,6 +5,10 @@ Requires the following executable: * watson +Parameters: + * watson.format: Output format, defaults to "{project} [{tags}]" + Supported fields are: {project}, {tags}, {relative_start}, {absolute_start} + contributed by `bendardenne `_ - many thanks! """ @@ -26,11 +30,11 @@ def __init__(self, config, theme): super().__init__(config, theme, core.widget.Widget(self.text)) self.__tracking = False - self.__project = "" + self.__info = {} + self.__format = self.parameter("format", "{project} [{tags}]") core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.toggle) def toggle(self, widget): - self.__project = "hit" if self.__tracking: util.cli.execute("watson stop") else: @@ -39,20 +43,27 @@ def toggle(self, widget): def text(self, widget): if self.__tracking: - return self.__project + return self.__format.format(**self.__info) else: return "Paused" def update(self): output = util.cli.execute("watson status") - if re.match(r"No project started", output): + + m = re.search(r"Project ([^\[\]]+)(?: \[(.+)\])? started (.+) \((.+)\)", output) + + if m: + self.__tracking = True + self.__info = { + "project": m.group(1), + "tags": m.group(2) or "", + "relative_start": m.group(3), + "absolute_start": m.group(4), + } + else: self.__tracking = False return - self.__tracking = True - m = re.search(r"Project (.+) started", output) - self.__project = m.group(1) - def state(self, widget): return "on" if self.__tracking else "off"