pydoto-cli

Simple ToDo-like application, that just works. Add any tasks without closing your terminal.
git clone https://git.nfu.su/pydoto-cli.git
Log | Files | Refs | README

commit 546f8ad4771db0b1fdf4782b397fea1647fd99b7
parent 0ece98abe8ba6bec400d882cc897353e71790b66
Author: Pr0fiTX <uventik999@gmail.com>
Date:   Wed, 18 Jun 2025 13:28:46 +0300

[REFACTORING]: Move output functions to another file

Diffstat:
Ataskprinter.py | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtasksmanage.py | 92+++++++++++++++----------------------------------------------------------------
2 files changed, 78 insertions(+), 75 deletions(-)

diff --git a/taskprinter.py b/taskprinter.py @@ -0,0 +1,61 @@ +class TaskPrinter: + COMPLETED_M = "[x]" + DELETED_M = "[d]" + EXPIRED_M = "[e]" + ACTIVE_M = "[ ]" + + @classmethod + def mark_choser(cls, task) -> str: + match task.status.value: + case "active": + return cls.ACTIVE_M + case "deleted": + return cls.DELETED_M + case "expired": + return cls.EXPIRED_M + case "completed": + return cls.COMPLETED_M + case _: + return " " + + @classmethod + def print_tasks_all(cls, tasks): + for task in tasks: + cls.task_out(task, 1, 0, 1, 1, 1) + + @classmethod + def print_tasks(cls, tasks): + for task in tasks: + if (task.status.value == "deleted"): + continue + + cls.task_out(task, 1, 0, 1, 1, 1) + + @classmethod + def print_id_all(cls, tasks): + for task in tasks: + cls.task_out(task, 1, 1, 1, 1, 1) + + @classmethod + def print_id(cls, tasks): + for task in tasks: + if (task.status.value == "deleted"): + continue + + cls.task_out(task, 1, 1, 1, 1, 1) + + @classmethod + def print_active(cls, tasks): + for task in tasks: + if (task.status.value != "active"): + continue + + cls.task_out(task, 1, 0, 1, 1, 1) + + @classmethod + def task_out(cls, task, sta=0, id=0, nam=0, des=0, exp=0): + print(f"{cls.mark_choser(task)}" if sta else "", + f"| \"{task.creation_date}\" |" if id else "", + f"{task.name}" if nam else "", + f"| {task.description} " if task.description and des else "", + f"| {task.expiration_date}" if task.expiration_date and exp else "") diff --git a/tasksmanage.py b/tasksmanage.py @@ -1,5 +1,6 @@ import json as js import os +import taskprinter as tp from datetime import datetime from enum import Enum @@ -125,102 +126,43 @@ class Task: print(f"!> Can't write to the file {DB_NAME}: {e}") @classmethod - def print_active(cls): # TODO: Prettier Output + def print_active(cls): cls.update_expiration_statuses() tasks = cls.db_load() - if not tasks: - print("!> You don't have any tasks") - return - - print("\n\t=== ACTIVE TASKS ===\n") - print(' TITLE\tDESCRIPTION\tDUE DATE') - print('----' * 10) - for task in tasks: - if (task.status != TaskStatus.ACTIVE): - continue - - print(f" {task.name}\t", - f" {task.description}\t" if task.description else "-\t", - f" {task.expiration_date}\t" if task.expiration_date else "-\t") - print('----' * 10) + if not cls.check_for_emptiness(tasks): + tp.TaskPrinter.print_active(tasks) @classmethod def print_id(cls): cls.update_expiration_statuses() tasks = cls.db_load() - if not tasks: - print("!> You don't have any tasks") - return - - print("\n\t=== TASKS ===\n") - print(' ID (CREATION DATE)\tTITLE\tDESCRIPTION\tDUE DATE\tSTATUS') - print('----' * 30) - for task in tasks: - if (task.status == TaskStatus.DELETED): - continue - - print(f" {task.creation_date}\t", - f" {task.name}\t", - f" {task.description}\t" if task.description else "-\t", - f" {task.expiration_date}\t" if task.expiration_date else "-\t", - f" {task.status.value}\t") - print('----' * 30) + if not cls.check_for_emptiness(tasks): + tp.TaskPrinter.print_id(tasks) @classmethod def print_id_all(cls): cls.update_expiration_statuses() tasks = cls.db_load() - if not tasks: - print("!> You don't have any tasks") - return - - print("\n\t=== TASKS ===\n") - print(' ID (CREATION DATE)\tTITLE\tDESCRIPTION\tDUE DATE\tSTATUS') - print('----' * 30) - for task in tasks: - print(f" {task.creation_date}\t", - f" {task.name}\t", - f" {task.description}\t" if task.description else "-\t", - f" {task.expiration_date}\t" if task.expiration_date else "-\t", - f" {task.status.value}\t") - print('----' * 30) + if not cls.check_for_emptiness(tasks): + tp.TaskPrinter.print_id_all(tasks) @classmethod def print_tasks(cls): cls.update_expiration_statuses() tasks = cls.db_load() - if not tasks: - print("!> You don't have any tasks") - return - - print("\n\t=== TASKS ===\n") - print(' TITLE\tDESCRIPTION\tDUE DATE\tSTATUS') - print('----' * 20) - for task in tasks: - if (task.status == TaskStatus.DELETED): - continue - - print(f" {task.name}\t", - f" {task.description}\t" if task.description else "-\t", - f" {task.expiration_date}\t" if task.expiration_date else "-\t", - f" {task.status.value}\t") - print('----' * 20) + if not cls.check_for_emptiness(tasks): + tp.TaskPrinter.print_tasks(tasks) @classmethod def print_tasks_all(cls): cls.update_expiration_statuses() tasks = cls.db_load() + if not cls.check_for_emptiness(tasks): + tp.TaskPrinter.print_tasks_all(tasks) + + @staticmethod + def check_for_emptiness(tasks) -> bool: if not tasks: print("!> You don't have any tasks") - return - - print("\n\t=== TASKS ===\n") - print(' TITLE\tDESCRIPTION\tDUE DATE\tSTATUS') - print('----' * 20) - for task in tasks: - print(f" {task.name}\t", - f" {task.description}\t" if task.description else "-\t", - f" {task.expiration_date}\t" if task.expiration_date else "-\t", - f" {task.status.value}\t") - print('----' * 20) - + return True + return False