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:
parent
855f367727
commit
f6a5c15eac
|
|
@ -2,6 +2,7 @@ import argparse
|
|||
import sys
|
||||
import rich
|
||||
|
||||
from metar_navigate.ui import RichInterface
|
||||
from metar_navigate.utils import ConfigManager
|
||||
|
||||
class Application:
|
||||
|
|
@ -9,14 +10,25 @@ class Application:
|
|||
self.parser = None
|
||||
self.args = None
|
||||
self.config = ConfigManager()
|
||||
self.ui = None
|
||||
|
||||
|
||||
def setup(self):
|
||||
self._validate_args()
|
||||
def setup(self) -> None:
|
||||
|
||||
if self.config.read_config() is None:
|
||||
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):
|
||||
self.parser = argparse.ArgumentParser()
|
||||
self.parser.add_argument("--no-tui", action="store_true", help="disables the TUI")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
from .ui import RichInterface
|
||||
|
||||
__all__ = ["RichInterface"]
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue