Skip to content

Commit

Permalink
clean up task tree + print line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
vighneshiyer committed Apr 6, 2024
1 parent 1e55552 commit ec5aab8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

## Quickstart

Install: `pip install todo-today-cli`
Install: `pipx install todo-today-cli`.

Install from source: `git clone [email protected]:vighneshiyer/today`, `cd today`, `pipx install -e .`.

Create a file (`tasks.md`) and add the following:

Expand Down
27 changes: 14 additions & 13 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 PriorityAttribute, Task, task_sorter, days
from today.task import Task, task_sorter, days
from today.parser import parse_markdown


Expand Down Expand Up @@ -112,10 +112,8 @@ def parse_task_files(args: CliArgs) -> List[Task]:
return tasks_visible


def display_specific_task(
task: Task, task_id: int, today: date, console: Console
) -> None:
details = task.details(task_id, today)
def display_specific_task(task: Task, today: date, console: Console) -> None:
details = task.details(today)
console.print("")
console.print(Markdown(details))
console.print("")
Expand Down Expand Up @@ -149,19 +147,22 @@ def tasks_to_tree(args: CliArgs, tasks: List[Task]) -> Tree:
priority_tasks = [t for t in tasks if t.attrs.priority_attr is not None]
other_tasks = [t for t in tasks if t.attrs.priority_attr is None]

priority_label = tree.add("[bold]Priority Tasks[/bold]")
for i, task in enumerate(priority_tasks):
priority_label.add(
# f"[bold]{i}[/bold] - [blue]{' / '.join(task.path)}[/blue] [blue bold]➔[/blue bold] {task.title} {Markdown(task.summary(args.today))} ([red italic]{task.file_path.relative_to(args.task_dir)}:{task.line_number}[/red italic])"
Markdown(
f"**{i}** - {' / '.join(task.path)}{task.title} {task.summary(args.today)} (*{task.file_path.relative_to(args.task_dir)}:{task.line_number}*)"
if len(priority_tasks) > 0:
priority_label = tree.add("[bold]Priority Tasks[/bold]")
for i, task in enumerate(priority_tasks):
priority_label.add(
# f"[bold]{i}[/bold] - [blue]{' / '.join(task.path)}[/blue] [blue bold]➔[/blue bold] {task.title} {Markdown(task.summary(args.today))} ([red italic]{task.file_path.relative_to(args.task_dir)}:{task.line_number}[/red italic])"
Markdown(
f"**{i}** - {' / '.join(task.path)}{task.title} {task.summary(args.today)} (*{task.file_path.relative_to(args.task_dir)}:{task.line_number}*)"
)
)
)

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)}")
Markdown(
f"**{task_idx}** - {task.title} {task.summary(args.today)} (*:{task.line_number}*)"
)
)
if task.subtasks:
for subtask in task.subtasks:
Expand Down
2 changes: 1 addition & 1 deletion today/scripts/today.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def run(args) -> None:
console.print(f"The task_id {args.task_id} does not exist")
sys.exit(1)
task = tasks[cli_args.task_id]
display_specific_task(task, cli_args.task_id, cli_args.today, console)
display_specific_task(task, cli_args.today, console)
sys.exit(0)

tree = tasks_to_tree(cli_args, tasks)
Expand Down
14 changes: 9 additions & 5 deletions today/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,20 @@ def is_displayed(self, today: date, lookahead_days: int = 0) -> bool:

def summary(self, today: date) -> str: # Returns a Markdown string
date_summary = self.attrs.date_attr.summary(today)
# pri_summary = (
# (self.attrs.priority_attr.summary() + " ")
# if self.attrs.priority_attr
# else ""
# )
pri_summary = (
(self.attrs.priority_attr.summary() + " ")
if self.attrs.priority_attr
else ""
"" # don't include task priorities in the summaries shown in the tree
)
return pri_summary + date_summary

def details(self, task_id: int, today: date) -> str: # Returns a Markdown string
def details(self, today: date) -> str: # Returns a Markdown string
string = ""
string += f"**Title**: {self.title} (id = `{task_id}`) \n"
string += f"**Title**: {self.title} \n"
string += self.attrs.date_attr.details(today)
if len(self.description) > 0:
string += "**Description**: \n\n"
string += self.description
Expand Down

0 comments on commit ec5aab8

Please sign in to comment.