[modules/taskwarrior] add state handling

Sets one of two states:
  "stopped" - Default, no running task
  "active"  - When an active task is running.
This commit is contained in:
Alex Kelly 2022-09-15 11:48:43 -04:00
parent 97a022e452
commit a5e0b01e3b

View file

@ -22,6 +22,7 @@ class Module(core.module.Module):
super().__init__(config, theme, core.widget.Widget(self.output)) super().__init__(config, theme, core.widget.Widget(self.output))
self.__pending_tasks = "0" self.__pending_tasks = "0"
self.__status = "stopped"
def update(self): def update(self):
"""Return a string with the number of pending tasks from TaskWarrior """Return a string with the number of pending tasks from TaskWarrior
@ -43,16 +44,23 @@ class Module(core.module.Module):
reporting_tasks = ( reporting_tasks = (
f"{active_tasks[0]['id']} - {active_tasks[0]['description']}" f"{active_tasks[0]['id']} - {active_tasks[0]['description']}"
) )
self.__status = "active"
else: else:
reporting_tasks = len(w.filter_tasks({"status": "pending"})) reporting_tasks = len(w.filter_tasks({"status": "pending"}))
self.__status = "stopped"
self.__pending_tasks = reporting_tasks self.__pending_tasks = reporting_tasks
except: except:
self.__pending_tasks = "n/a" self.__pending_tasks = "n/a"
self.__status = "stopped"
@core.decorators.scrollable @core.decorators.scrollable
def output(self, _): def output(self, _):
"""Format the task counter to output in bumblebee.""" """Format the task counter to output in bumblebee."""
return "{}".format(self.__pending_tasks) return "{}".format(self.__pending_tasks)
def state(self, widget):
"""Return the set status to reflect state"""
return self.__status
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4