From 0dcf1a01c0be79b60332dde8c3416a4e81618e5f Mon Sep 17 00:00:00 2001 From: nojhan Date: Fri, 8 Sep 2023 16:11:58 +0200 Subject: [PATCH] feat: display tasks number in nearest upper dir and immediate subdirs --- presets/colors_nojhan.conf | 6 ++++++ taskwarrior-deluxe.py | 40 +++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/presets/colors_nojhan.conf b/presets/colors_nojhan.conf index ef80c7e..d3590a5 100644 --- a/presets/colors_nojhan.conf +++ b/presets/colors_nojhan.conf @@ -31,3 +31,9 @@ color.tags.bug=rgb00ccff color.project=rgb8877ff color.due=rgbff8888 + +color.taskdir=bold white +color.taskdir.travail=bold italic white +color.parentdir= +color.parentdir.tasks=italic rgbffff88 + diff --git a/taskwarrior-deluxe.py b/taskwarrior-deluxe.py index d456646..968b007 100755 --- a/taskwarrior-deluxe.py +++ b/taskwarrior-deluxe.py @@ -875,6 +875,44 @@ if __name__ == "__main__": sectioner = layouts["sections"][config["layout.sections"]](config, stacker, g_sort_on, group_by) console = Console(theme = swatch) - # console.rule("taskwarrior-deluxe") + + # Display the basename of the directory holding the database. + task_dir = taskfile.parent + cwd = pathlib.Path.cwd() + relp = pathlib.Path(os.path.relpath(task_dir, cwd)) + w = Widget(config) + if relp == '.': + # Just the name of the current dir. + console.rule(w.rtext(str(task_dir.name), swatch="taskdir"), style=config["color.taskdir"]) + else: + # Display a number of tasks in an upper directory. + uptaskfile = find_tasks(".task", task_dir.parent, config) + if uptaskfile: + uprelp = pathlib.Path(os.path.relpath(task_dir.parent, cwd)) + upreli = re.sub("\.\./*", "⮬", str(uprelp)) + upjdata = get_data(uptaskfile) + console.print(w.rtext(f"{upreli} {uptaskfile.parent.name}/: ", swatch="parentdir"), end="") + console.print(w.rtext(f"{len(upjdata)} tasks", swatch="parentdir.tasks")) + + # Relative path to the directory holding the task files. + rela = re.sub("\.\./*", "⮬", str(relp)) + reli = re.sub("\.", "", rela) + if reli: + console.rule(w.rtext(f"{reli} {task_dir.name}", swatch="taskdir"), style=config["color.taskdir"]) + else: + console.rule(w.rtext(f"{task_dir.name}", swatch="taskdir"), style=config["color.taskdir"]) + + # Main display. console.print(sectioner(jdata)) + # Number of tasks in immediate subdirs. + for f in os.scandir(cwd): + if f.is_dir(): + downtaskfile = find_tasks(".task", pathlib.Path(f), config) + if downtaskfile and downtaskfile != taskfile: + downrelp = pathlib.Path(os.path.relpath(task_dir.parent, cwd)) + downreli = re.sub("\.\./*", "⮯", str(downrelp)) + downjdata = get_data(downtaskfile) + console.print(w.rtext(f"{downreli}./{downtaskfile.parent.name}: ", swatch="parentdir"), end="") + console.print(w.rtext(f"{len(downjdata)} tasks", swatch="parentdir.tasks")) +