Skip to content

Commit

Permalink
[module/watson] Add formatting string
Browse files Browse the repository at this point in the history
Make it possible to customize the watson message in the widget

see #963
  • Loading branch information
tobi-wan-kenobi committed May 11, 2023
1 parent 14f19c8 commit 8967eec
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions bumblebee_status/modules/contrib/watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/bendardenne>`_ - many thanks!
"""

Expand All @@ -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:
Expand All @@ -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"

Expand Down

0 comments on commit 8967eec

Please sign in to comment.