Refactor `Application` and `RichInterface` setup logic
- Added `is_configured` flag in `Application` to track configuration state. - Updated `RichInterface` to support multiple modes (`configure`, `detailed`, etc.) using structured logic. - Integrated TUI run modes and refined display messages. - Fixed minor imports and style inconsistencies in `RichInterface`.
This commit is contained in:
parent
f6a5c15eac
commit
772020a9e5
|
|
@ -2,6 +2,7 @@ import argparse
|
||||||
import sys
|
import sys
|
||||||
import rich
|
import rich
|
||||||
|
|
||||||
|
|
||||||
from metar_navigate.ui import RichInterface
|
from metar_navigate.ui import RichInterface
|
||||||
from metar_navigate.utils import ConfigManager
|
from metar_navigate.utils import ConfigManager
|
||||||
|
|
||||||
|
|
@ -11,11 +12,12 @@ class Application:
|
||||||
self.args = None
|
self.args = None
|
||||||
self.config = ConfigManager()
|
self.config = ConfigManager()
|
||||||
self.ui = None
|
self.ui = None
|
||||||
|
self.is_configured = False
|
||||||
|
|
||||||
def setup(self) -> None:
|
def setup(self) -> None:
|
||||||
|
|
||||||
if self.config.read_config() is None:
|
if self.config.read_config() is not None:
|
||||||
rich.print("[bold red]No config file found. Please run metarNavigate --configure[/bold red] ")
|
self.is_configured = True
|
||||||
|
|
||||||
self._validate_args()
|
self._validate_args()
|
||||||
|
|
||||||
|
|
@ -74,4 +76,4 @@ class Application:
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
pass
|
self.ui.run()
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
from .ui import RichInterface
|
from .ui import RichInterface
|
||||||
|
|
||||||
__all__ = ["RichInterface"]
|
__all__ = ["RichInterface",]
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
from rich import Console
|
from rich import console
|
||||||
|
|
||||||
|
|
||||||
class UIInterface(ABC):
|
class UIInterface(ABC):
|
||||||
|
|
@ -16,15 +16,31 @@ class UIInterface(ABC):
|
||||||
class RichInterface(UIInterface):
|
class RichInterface(UIInterface):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.console = Console()
|
self.console = console.Console()
|
||||||
self.console.show_cursor(False)
|
self.console.show_cursor(False)
|
||||||
self.mode = None
|
self.mode = None
|
||||||
|
|
||||||
def setup(self,**kwargs):
|
def setup(self,**kwargs):
|
||||||
for key, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
if key == "configures" and value == True:
|
match(key):
|
||||||
self.mode = "configure"
|
case "configure":
|
||||||
else:
|
if value:
|
||||||
self.mode = "run"
|
self.mode = "configure"
|
||||||
|
else:
|
||||||
|
self.mode = "run"
|
||||||
|
case "detailed":
|
||||||
|
self.mode = "detailed"
|
||||||
|
case _:
|
||||||
|
raise ValueError(f"Invalid mode: {key}")
|
||||||
|
def configure_run_mode(self):
|
||||||
|
self.console.print("This Application is in [bold red]Configure Mode[/bold red]")
|
||||||
|
self.console.print("This Application requires a CheckWX API Key to run")
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
pass
|
if self.mode == "configure":
|
||||||
|
self.configure_run_mode()
|
||||||
|
else:
|
||||||
|
self.console.print("This Application is in [bold red]Run Mode[/bold red]")
|
||||||
|
|
||||||
|
self.console.show_cursor(True)
|
||||||
Loading…
Reference in New Issue