diff --git a/.task/backlog.data b/.task/backlog.data index c86c054..a4f5677 100644 --- a/.task/backlog.data +++ b/.task/backlog.data @@ -40,3 +40,5 @@ {"description":"handle prompts: for some commands like delete, taskwarrior setup an interactive prompt, which needs to be handled.","entry":"20230815T180334Z","modified":"20230815T180334Z","status":"pending","uuid":"e2480c4b-4c73-4d03-8568-82f14ade7b38","tags":["bug"]} {"description":"subgrouping: allow to add another sectionning, e.g. based on priority.","entry":"20230815T180428Z","modified":"20230815T180428Z","status":"pending","uuid":"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a","tags":["feat"]} {"description":"subgrouping: allow to add another sectionning, e.g. based on priority.","entry":"20230815T180428Z","modified":"20230815T180440Z","start":"20230815T180440Z","status":"pending","uuid":"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a","tags":["feat"]} +{"description":"sorting: allow sorting within a stacker.","entry":"20230816T115710Z","modified":"20230816T115710Z","status":"pending","uuid":"30ec6b32-a32e-4595-a24d-02ac9002fd72","tags":["feat"]} +{"description":"subgrouping: allow to add another sectionning, e.g. based on priority.","end":"20230816T115728Z","entry":"20230815T180428Z","modified":"20230816T115728Z","status":"completed","uuid":"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a","tags":["feat"]} diff --git a/.task/completed.data b/.task/completed.data index c0a1a06..d7db29c 100644 --- a/.task/completed.data +++ b/.task/completed.data @@ -1,2 +1,3 @@ +[description:"subgrouping: allow to add another sectionning, e.g. based on priority." end:"1692187048" entry:"1692122668" modified:"1692187048" status:"completed" tags:"feat" tags_feat:"x" uuid:"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a"] [description:"show done: display completed tasks during some days after their completion, but not after" end:"1692122556" entry:"1691990078" modified:"1692122561" status:"deleted" tags:"feat" tags_feat:"x" uuid:"18b8f46c-3498-4e75-8945-b578beaf29bc"] [description:"styling: apply configurable styles to each field and state with semantics" end:"1691990004" entry:"1691774377" modified:"1691990004" status:"completed" tags:"feat" tags_feat:"x" uuid:"17819637-4f4a-4e46-8622-12d8243c54da"] diff --git a/.task/pending.data b/.task/pending.data index 4325dd8..98cdbcd 100644 --- a/.task/pending.data +++ b/.task/pending.data @@ -8,4 +8,4 @@ [description:"init command: add a command to initialize a local .task dir and\/or config file.s" entry:"1692121630" modified:"1692121630" priority:"M" status:"pending" tags:"feat" tags_feat:"x" uuid:"81fc6480-e8e7-4dd4-9f01-a00f34463135"] [description:"colored panels: allow selecting a different swatch for each &open;sub&close;panel" entry:"1692122434" modified:"1692122452" priority:"M" status:"pending" tags:"feat,themes" tags_feat:"x" tags_themes:"x" uuid:"ca17838d-958f-498b-bff5-a24576820ae7"] [description:"handle prompts: for some commands like delete, taskwarrior setup an interactive prompt, which needs to be handled." entry:"1692122614" modified:"1692122614" status:"pending" tags:"bug" tags_bug:"x" uuid:"e2480c4b-4c73-4d03-8568-82f14ade7b38"] -[description:"subgrouping: allow to add another sectionning, e.g. based on priority." entry:"1692122668" modified:"1692122680" start:"1692122680" status:"pending" tags:"feat" tags_feat:"x" uuid:"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a"] +[description:"sorting: allow sorting within a stacker." entry:"1692187030" modified:"1692187030" status:"pending" tags:"feat" tags_feat:"x" uuid:"30ec6b32-a32e-4595-a24d-02ac9002fd72"] diff --git a/.task/undo.data b/.task/undo.data index a124f22..b13f652 100644 --- a/.task/undo.data +++ b/.task/undo.data @@ -153,3 +153,10 @@ time 1692122680 old [description:"subgrouping: allow to add another sectionning, e.g. based on priority." entry:"1692122668" modified:"1692122668" status:"pending" tags:"feat" tags_feat:"x" uuid:"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a"] new [description:"subgrouping: allow to add another sectionning, e.g. based on priority." entry:"1692122668" modified:"1692122680" start:"1692122680" status:"pending" tags:"feat" tags_feat:"x" uuid:"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a"] --- +time 1692187030 +new [description:"sorting: allow sorting within a stacker." entry:"1692187030" modified:"1692187030" status:"pending" tags:"feat" tags_feat:"x" uuid:"30ec6b32-a32e-4595-a24d-02ac9002fd72"] +--- +time 1692187048 +old [description:"subgrouping: allow to add another sectionning, e.g. based on priority." entry:"1692122668" modified:"1692122680" start:"1692122680" status:"pending" tags:"feat" tags_feat:"x" uuid:"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a"] +new [description:"subgrouping: allow to add another sectionning, e.g. based on priority." end:"1692187048" entry:"1692122668" modified:"1692187048" status:"completed" tags:"feat" tags_feat:"x" uuid:"9dc6d43a-b316-4417-ad2a-e47b8a5ddc7a"] +--- diff --git a/taskwarrior-deluxe.py b/taskwarrior-deluxe.py index 7741992..1224c78 100755 --- a/taskwarrior-deluxe.py +++ b/taskwarrior-deluxe.py @@ -15,8 +15,20 @@ from rich.columns import Columns class Widget: def __init__(self, order, group = None): - self.order = order - self.group = group + self.sorter = order + self.grouper = group + + def order(self, groups): + if self.sorter: + return self.sorter() + else: + return groups.keys() + + def group(self, tasks): + if self.grouper: + return self.grouper(tasks) + else: + return {"":tasks} class Tasker(Widget): def __init__(self, show_only, order, group = None, touched = []): @@ -234,9 +246,9 @@ class sections: def __call__(self, tasks): sections = [] groups = self.group(tasks) - for key in self.order(): + for key in self.order(groups): if key in groups: - sections.append( rich.panel.Panel(self.stacker(groups[key]), title = rich.text.Text(key.upper(), style=key), title_align = "left", expand = False)) + sections.append( rich.panel.Panel(self.stacker(groups[key]), title = rich.text.Text(str(key).upper(), style=key), title_align = "left", expand = False)) return rich.console.Group(*sections) class Horizontal(Sectioner): @@ -248,7 +260,7 @@ class sections: groups = self.group(tasks) table = rich.table.Table(box = None, show_header = False, show_lines = False) keys = [] - for key in self.order(): + for key in self.order(groups): if key in groups: table.add_column(key) keys.append(key) @@ -265,9 +277,8 @@ class SectionSorter: raise NotImplementedError class sort: - class Tasks: - def make(self, tasks, field, reverse = False): - return sorted(tasks, key = lambda t: t[field], reverse = reverse) + # def make(self, tasks, field, reverse = False): + # return sorted(tasks, key = lambda t: t[field], reverse = reverse) class OnValues(SectionSorter): def __init__(self, values): @@ -398,6 +409,7 @@ def get_swatches(name = None): 'urgency': 'color(219)', 'row_odd': 'on #262121', 'row_even' : 'on #2d2929', + 'priority': 'color(105)', }, "chalky": { @@ -536,6 +548,12 @@ if __name__ == "__main__": layouts_grp.add_argument('-C', '--layout-subsections', metavar='NAME', type=str, default=None, choices = get_layouts('sections').keys(), help="Layout managing sub-sections.") + layouts_grp.add_argument('-g', '--group-by', metavar="NAME", type=str, default="status", + help="Create sections by grouping on this field.") + + layouts_grp.add_argument('-G', '--subgroup-by', metavar="NAME", type=str, default=None, + help="Create sub-sections by grouping on this field.") + layouts_grp.add_argument('-T', '--swatch', metavar='NAME', type=str, default='none', choices = get_swatches().keys(), help="Color chart.") @@ -549,6 +567,7 @@ if __name__ == "__main__": parser.add_argument('cmd', nargs="*") asked = parser.parse_args() + # print(asked) # First pass arguments to taskwarrior and let it do its magic. out = call_taskwarrior(asked.cmd) @@ -580,16 +599,39 @@ if __name__ == "__main__": stacker = layouts['stack'][asked.layout_stack](tasker) - group_by_status = group.Status() - group_by_priority = group.Field("priority") - sort_on_status_values = sort.OnValues(["pending","started","completed"]) - sort_on_priority_values = sort.OnValues(["H","M","L",""]) - - if asked.layout_subsections: - subsectioner = layouts['sections'][asked.layout_subsections](stacker, sort_on_priority_values, group_by_priority) - sectioner = layouts['sections'][asked.layout_sections](subsectioner, sort_on_status_values, group_by_status) + if asked.group_by: + if asked.group_by.lower() == "status": + group_by = group.Status() + sort_on = sort.OnValues(["pending","started","completed"]) + elif asked.group_by.lower() == "priority": + group_by = group.Field("priority") + sort_on = sort.OnValues(["H","M","L",""]) + else: + group_by = group.Field(asked.group_by) + sort_on = None else: - sectioner = layouts['sections'][asked.layout_sections](stacker, sort_on_status_values, group_by_status) + group_by = group.Status() + sort_on = sort.OnValues(["pending","started","completed"]) + + if asked.subgroup_by: + if asked.subgroup_by.lower() == "status": + subgroup_by = group.Status() + subsort_on = sort.OnValues(["pending","started","completed"]) + if asked.subgroup_by.lower() == "priority": + subgroup_by = group.Field("priority") + subsort_on = sort.OnValues(["H","M","L",""]) + else: + subgroup_by = group.Field(asked.subgroup_by) + subsort_on = None + else: + subgroup_by = None + subsort_on = None + + if asked.layout_subsections and asked.subgroup_by: + subsectioner = layouts['sections'][asked.layout_subsections](stacker, subsort_on, subgroup_by) + sectioner = layouts['sections'][asked.layout_sections](subsectioner, sort_on, group_by) + else: + sectioner = layouts['sections'][asked.layout_sections](stacker, sort_on, group_by) console = Console(theme = swatch) # console.rule("taskwarrior-deluxe")