Skip to content

Commit

Permalink
Extract logic for due date colour
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyNotHugo committed Mar 3, 2023
1 parent 5ce624c commit 6b0cc7e
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions todoman/formatters.py
Expand Up @@ -83,19 +83,7 @@ def compact_multiple(self, todos: Iterable[Todo], hide_list=False) -> str:
)

due = self.format_datetime(todo.due) or "(no due date)"
now = self.now if isinstance(todo.due, datetime) else self.now.date()

due_colour = None
if todo.due:
if todo.due <= now and not todo.is_completed:
due_colour = "red"
elif todo.due >= now + timedelta(hours=24):
due_colour = "white"
elif todo.due >= now:
due_colour = "yellow"
else:
due_colour = "white"

due_colour = self._due_colour(todo)
if due_colour:
due = click.style(str(due), fg=due_colour)

Expand Down Expand Up @@ -127,6 +115,18 @@ def compact_multiple(self, todos: Iterable[Todo], hide_list=False) -> str:

return "\n".join(table)

def _due_colour(self, todo: Todo) -> str:
now = self.now if isinstance(todo.due, datetime) else self.now.date()
if todo.due:
if todo.due <= now and not todo.is_completed:
return "red"
elif todo.due >= now + timedelta(hours=24):
return "white"
elif todo.due >= now:
return "yellow"

return "white"

def _format_multiline(self, title: str, value: str) -> str:
formatted_title = click.style(title, fg="white")

Expand Down

0 comments on commit 6b0cc7e

Please sign in to comment.