From 8967eec44bce74969a1b6ae820ac2d4292c503c4 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Thu, 11 May 2023 14:28:32 +0200 Subject: [PATCH] [module/watson] Add formatting string Make it possible to customize the watson message in the widget see #963 --- bumblebee_status/modules/contrib/watson.py | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/bumblebee_status/modules/contrib/watson.py b/bumblebee_status/modules/contrib/watson.py index d7b260b..a717342 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 @@ class Module(core.module.Module): 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 @@ class Module(core.module.Module): 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"