Add TUI integration and refactor setup logic

- Introduced `RichInterface` to support Textual User Interface (TUI) functionality.
- Enhanced `Application` class to initialize and configure TUI based on arguments.
- Added `ui` module with a base `UIInterface` and `RichInterface` implementation.
- Updated argument parsing logic to handle TUI-specific options.
This commit is contained in:
Gustavo Henrique Santos Souza de Miranda 2025-10-30 00:32:21 -03:00
parent 855f367727
commit f6a5c15eac
3 changed files with 48 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import argparse
import sys import sys
import rich import rich
from metar_navigate.ui import RichInterface
from metar_navigate.utils import ConfigManager from metar_navigate.utils import ConfigManager
class Application: class Application:
@ -9,14 +10,25 @@ class Application:
self.parser = None self.parser = None
self.args = None self.args = None
self.config = ConfigManager() self.config = ConfigManager()
self.ui = None
def setup(self) -> None:
def setup(self):
self._validate_args()
if self.config.read_config() is None: if self.config.read_config() is None:
rich.print("[bold red]No config file found. Please run metarNavigate --configure[/bold red] ") rich.print("[bold red]No config file found. Please run metarNavigate --configure[/bold red] ")
self._validate_args()
if self.args.no_tui:
self.ui = RichInterface()
if self.args.configure:
self.ui.setup(configure=True)
if self.args.detailed:
self.ui.setup(detailed=True)
def _validate_args(self): def _validate_args(self):
self.parser = argparse.ArgumentParser() self.parser = argparse.ArgumentParser()
self.parser.add_argument("--no-tui", action="store_true", help="disables the TUI") self.parser.add_argument("--no-tui", action="store_true", help="disables the TUI")

View File

@ -0,0 +1,3 @@
from .ui import RichInterface
__all__ = ["RichInterface"]

View File

@ -0,0 +1,30 @@
from abc import ABC, abstractmethod
from rich import Console
class UIInterface(ABC):
@abstractmethod
def setup(self):
pass
@abstractmethod
def run(self):
pass
class RichInterface(UIInterface):
def __init__(self):
super().__init__()
self.console = Console()
self.console.show_cursor(False)
self.mode = None
def setup(self,**kwargs):
for key, value in kwargs.items():
if key == "configures" and value == True:
self.mode = "configure"
else:
self.mode = "run"
def run(self):
pass