Created
February 19, 2026 13:51
-
-
Save sunmeat/f4b87f086e2e374af3f0d4e516f12796 to your computer and use it in GitHub Desktop.
альтернативне вью 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # view.py | |
| # py -m pip install rich (команда для терміналу PowerShell, якщо не встановлено) | |
| from rich.console import Console | |
| from rich.table import Table | |
| from rich.prompt import Prompt, IntPrompt | |
| console = Console(highlight=False) # глобальний об'єкт для зручності | |
| class ConsoleView: | |
| @staticmethod | |
| def show_tasks(tasks: list["Task"]): | |
| if not tasks: | |
| console.print("\n[yellow]Список завдань порожній.[/yellow]\n") | |
| return | |
| table = Table(title="Завдання", show_header=True, header_style="bold magenta") | |
| table.add_column("#", style="cyan", justify="right", width=4) | |
| table.add_column("Статус", style="green", justify="center", width=8) | |
| table.add_column("Опис", style="white") | |
| for i, task in enumerate(tasks, 1): | |
| status = "[green]✓[/green]" if task.done else "[dim]—[/dim]" | |
| table.add_row(str(i), status, task.description) | |
| console.print(table) | |
| console.print() | |
| @staticmethod | |
| def show_menu(): | |
| console.print("[bold]Меню To-Do List:[/bold]") | |
| console.print(" [cyan]1[/cyan] — Додати завдання") | |
| console.print(" [cyan]2[/cyan] — Показати всі завдання") | |
| console.print(" [cyan]3[/cyan] — Позначити як виконане") | |
| console.print(" [cyan]4[/cyan] — Видалити завдання") | |
| console.print(" [red]0[/red] — Вихід") | |
| console.print() | |
| @staticmethod | |
| def get_choice() -> str: | |
| return Prompt.ask( | |
| "[yellow]Виберіть дію[/yellow]", | |
| choices=["0", "1", "2", "3", "4"], | |
| default="2" | |
| ) | |
| @staticmethod | |
| def get_task_description() -> str: | |
| return Prompt.ask("[yellow]Опис завдання[/yellow]") | |
| @staticmethod | |
| def get_task_number(prompt: str) -> str: | |
| return str(IntPrompt.ask(f"[yellow]{prompt}[/yellow]", default=1)) | |
| @staticmethod | |
| def show_message(msg: str): | |
| console.print(f"\n[green]{msg}[/green]\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment