Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and tidying #90

Merged
merged 13 commits into from
Oct 2, 2024
Prev Previous commit
Next Next commit
Fixing typing issues, ensure *args and **kwargs are passed to App sup…
…erclass to help compatibility. Use `get_default_screen` instead of pushing a screen on_mount.
darrenburns committed Oct 1, 2024
commit f92ea6d5355971b2abaec04e63c5e077881dff2f
6 changes: 3 additions & 3 deletions trogon/detect_run_string.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import os
import shlex
import sys
from types import ModuleType


def get_orig_argv() -> list[str]:
@@ -20,10 +21,9 @@ def get_orig_argv() -> list[str]:
return argv


def detect_run_string(path=None, _main=sys.modules["__main__"]) -> str:
def detect_run_string(_main: ModuleType = sys.modules["__main__"]) -> str:
"""This is a slightly modified version of a function from Click."""
if not path:
path = sys.argv[0]
path = sys.argv[0]

# The value of __package__ indicates how Python was called. It may
# not exist if a setuptools script is installed as an egg. It may be
22 changes: 15 additions & 7 deletions trogon/trogon.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import os
import shlex
from pathlib import Path
from typing import Any
from webbrowser import open as open_url

import click
@@ -202,12 +203,12 @@ async def _update_form_body(self, node: TreeNode[CommandSchema]) -> None:
command_form.focus()


class Trogon(App):
class Trogon(App[None]):
CSS_PATH = Path(__file__).parent / "trogon.scss"

def __init__(
self,
cli: click.Group,
cli: click.Group | click.Command,
app_name: str | None = None,
command_name: str = "tui",
click_context: click.Context | None = None,
@@ -220,11 +221,11 @@ def __init__(
if app_name is None and click_context is not None:
self.app_name = detect_run_string()
else:
self.app_name = app_name
self.app_name = app_name or "cli"
self.command_name = command_name

def on_mount(self):
self.push_screen(CommandBuilder(self.cli, self.app_name, self.command_name))
def get_default_screen(self) -> CommandBuilder:
return CommandBuilder(self.cli, self.app_name, self.command_name)

@on(Button.Pressed, "#home-exec-button")
def on_button_pressed(self):
@@ -233,13 +234,20 @@ def on_button_pressed(self):

def run(
self,
*,
*args: Any,
headless: bool = False,
size: tuple[int, int] | None = None,
auto_pilot: AutopilotCallbackType | None = None,
**kwargs: Any,
) -> None:
try:
super().run(headless=headless, size=size, auto_pilot=auto_pilot)
super().run(
*args,
headless=headless,
size=size,
auto_pilot=auto_pilot,
**kwargs,
)
finally:
if self.post_run_command:
console = Console()