Skip to content

Commit

Permalink
print md files for each top-level heading in tree
Browse files Browse the repository at this point in the history
  • Loading branch information
vighneshiyer committed Dec 27, 2023
1 parent 1d9417a commit 3554ce6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
18 changes: 14 additions & 4 deletions today-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@
- [x] Do not display subtasks that are already checked off
- [x] Write quickstart guide / simplify and shorten docs + add ToC
- ~~[ ] Show subtasks that are done in the visible subtasks (with a checkmark)~~ (goes against the way normal tasks work)
- [ ] Do some refactoring and cleanup [d:12/24]
- [ ] Display the task file name when running today (similar to start) [d:12/24]
- [ ] Migrate more code outside the printing logic in cli.py for unit testing [d:12/24]
- [ ] Add importance markers feature [d:12/24]
- [x] Do some refactoring and cleanup [d:12/24]
- [x] Migrate more code outside the printing logic in cli.py for unit testing [d:12/24]
- [x] Display the task file name when running today (similar to start) [d:12/24]
- [ ] Be able to select a subtask using `start`

### Importance Markers

The idea is that every day there might be 1-3 critical tasks that should be placed at the top no matter what the heading order is.
There should be a way to mark those critical tasks such that they always show up at the top and it makes task selection easy.
Also, the remaining tasks can be displayed in the normal tree form as 'extras' for a given day.

- [ ] Rename date_defns to task_attrs
- [ ] Add importance markers parsing
- [ ] Add new logic to tree printing

### Assignees

Expand Down
22 changes: 12 additions & 10 deletions today/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rich.console import Console
from rich.markdown import Markdown

from today.task import Task, task_sorter
from today.task import Task, task_sorter, days
from today.parser import parse_markdown


Expand Down Expand Up @@ -119,9 +119,9 @@ def maybe_display_specific_task(args: CliArgs, tasks: List[Task], console: Conso

def tasks_to_tree(args: CliArgs, tasks: List[Task]) -> Tree:
# Print tasks as a tree
tree = Tree(f"[bold underline]Tasks for today ({args.today})[/bold underline]" +
tree = Tree(f"[bold underline]Tasks for today[/bold underline] ({args.today})" +
("" if args.lookahead_days == timedelta(0) else f" (+{days(args.lookahead_days)})"))
def add_to_tree(task: Task, tree: Tree, task_idx: int) -> Tree:
def add_to_tree(task: Task, tree: Tree, task_idx: int, first_call: bool) -> Tree:
if len(task.path) == 0: # Base case
parent = tree.add(Markdown(f"**{task_idx}** - {task.title} {task.summary(args.today)}"))
if task.subtasks:
Expand All @@ -130,17 +130,19 @@ def add_to_tree(task: Task, tree: Tree, task_idx: int) -> Tree:
parent.add(Markdown(f"{subtask.title} {subtask.summary(args.today)}"))
return tree
else:
# Try to find the first heading in the current tree's children
labels = [t.label for t in tree.children]
if task.path[0] in labels: # The first heading has been found, continue to traverse down its children
first_heading = task.path[0]
# Try to find the first heading in the current tree's children
# The top-level heading should contain the file path of its associated markdown file
# All the subheadings should just be the raw heading
expected_label = f"{task.path[0]}" if not first_call else f"[bold]{task.path[0]}[/bold] ([red italic]{task.file_path.relative_to(args.task_dir)}[/red italic])"
if expected_label in labels: # The first heading has been found, continue to traverse down its children
task.path = task.path[1:]
return add_to_tree(task, tree.children[labels.index(first_heading)], task_idx)
return add_to_tree(task, tree.children[labels.index(expected_label)], task_idx, False)
else: # The first heading doesn't exist, create it and traverse down its children
child = tree.add(f"{task.path[0]}")
child = tree.add(expected_label)
task.path = task.path[1:]
return add_to_tree(task, child, task_idx)
return add_to_tree(task, child, task_idx, False)

for i, task in enumerate(tasks):
add_to_tree(task, tree, i)
add_to_tree(task, tree, i, True)
return tree
11 changes: 5 additions & 6 deletions today/scripts/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ def run(args) -> None:
print(f"The task id provided ({cli_args.task_id}) is not in range, rerun today")
sys.exit(1)
task = tasks[cli_args.task_id]
#path = " → ".join(task.path)
#path = " <span weight='bold' color='red'>/</span> ".join(task.path)
#path = " <span weight='bold'>/</span> ".join(task.path)
path = " / ".join(task.path)
current_task = f"<span weight='bold'> Current Task ({cli_args.task_id}) -</span>" if False else ""
# path = " → ".join(task.path)
# path = " / ".join(task.path)
path = " <span weight='bold'>/</span> ".join(task.path)
# current_task = f"<span weight='bold'> Current Task ({cli_args.task_id}) -</span>" if False else ""
rel_path = task.file_path.relative_to(cli_args.task_dir)
task_snippet = f"<span color='white'>{current_task} {path} <span weight='bold' color='red'>→</span> {task.title} <span color='lightgray'>({rel_path})</span></span>"
task_snippet = f"<span color='white'> {path} <span weight='bold' color='red'>→</span> {task.title} <span color='lightgray'>({rel_path})</span></span>"
Path("/tmp/task").write_text(task_snippet)

# https://i3wm.org/docs/i3status.html
Expand Down

0 comments on commit 3554ce6

Please sign in to comment.