From ed1bd917c46838021c8f5762d54e7899888cf539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C5=BEe=20Pe=C4=8Dar?= Date: Fri, 5 Jul 2024 01:26:44 +0100 Subject: [PATCH] Update version and prepare new release --- CHANGELOG.md | 13 ++++++ pyproject.toml | 4 +- src/django_tui/__about__.py | 2 +- src/django_tui/management/commands/ish.py | 15 ++++-- src/django_tui/management/commands/tui.py | 57 ++++++++--------------- 5 files changed, 45 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0a994f..842cbd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Calendar Versioning](https://calver.org). +## [24.3] - 2024-07-05 + +### Added + +Command highlighting on Python 3.12 +Django 5.1 support + +### Fixed + +Crash on startup when used with older Textual versions +Bug that prevented commands from working + + ## [24.2] - 2024-03-29 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index 4d91237..881178c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ classifiers = [ "Framework :: Django :: 4.1", "Framework :: Django :: 4.2", "Framework :: Django :: 5.0", + "Framework :: Django :: 5.1", "Programming Language :: Python", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", @@ -36,8 +37,7 @@ classifiers = [ ] dependencies = [ "django>=3.2", - "textual[syntax]>=0.54.0 ; python_version < '3.12'", - "textual>=0.54.0 ; python_version >= '3.12'", # tree-sitter-languages doesn't support 3.12 yet (https://github.com/grantjenks/py-tree-sitter-languages/issues/30) + "textual[syntax]>=0.64.0", "trogon", ] diff --git a/src/django_tui/__about__.py b/src/django_tui/__about__.py index 9fc5b4a..c221a46 100644 --- a/src/django_tui/__about__.py +++ b/src/django_tui/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2023-present Anže Pečar # # SPDX-License-Identifier: MIT -__version__ = "24.2" +__version__ = "24.3" diff --git a/src/django_tui/management/commands/ish.py b/src/django_tui/management/commands/ish.py index f78a09b..aef47b2 100644 --- a/src/django_tui/management/commands/ish.py +++ b/src/django_tui/management/commands/ish.py @@ -215,11 +215,7 @@ def compose(self) -> ComposeResult: class DefaultImportsInfo(ModalScreen[None]): BINDINGS = [ - Binding( - "escape", - "dismiss(None)", - "Close", - ), + Binding("escape", "dismiss(None)", "Close"), ] DEFAULT_CSS = """ @@ -394,3 +390,12 @@ def action_toggle_comment(self) -> None: def action_editor_keys(self) -> None: self.app.push_screen(TextEditorBindingsInfo()) + + def action_select_mode(self, mode_id: Literal["commands", "shell"]) -> None: + if mode_id == "commands": + from django_tui.management.commands.tui import DjangoCommandBuilder + + self.app.push_screen(DjangoCommandBuilder("pyhton manage.py", "Test command name")) + + elif mode_id == "shell": + self.app.push_screen(InteractiveShellScreen("Interactive Shell")) diff --git a/src/django_tui/management/commands/tui.py b/src/django_tui/management/commands/tui.py index b44840c..54f5146 100644 --- a/src/django_tui/management/commands/tui.py +++ b/src/django_tui/management/commands/tui.py @@ -153,7 +153,7 @@ class AboutDialog(TextDialog): """ def __init__(self) -> None: - title = f"About django-tui" + title = "About django-tui" message = Text.from_markup( "Built with [@click=app.visit('https://github.com/textualize/textual')]Textual[/] & [@click=app.visit('https://github.com/textualize/trogon')]Trogon[/] " "by [@click=app.visit('https://pecar.me')]Anže Pečar[/].\n\n" @@ -168,17 +168,6 @@ def __init__(self) -> None: class DjangoCommandBuilder(Screen): COMPONENT_CLASSES = {"version-string", "prompt", "command-name-syntax"} - BINDINGS = [ - Binding(key="ctrl+r", action="close_and_run", description="Close & Run"), - Binding(key="ctrl+z", action="copy_command", description="Copy Command to Clipboard"), - Binding(key="ctrl+t", action="focus_command_tree", description="Focus Command Tree"), - # Binding(key="ctrl+o", action="show_command_info", description="Command Info"), - Binding(key="ctrl+s", action="focus('search')", description="Search"), - Binding(key="ctrl+j", action="select_mode('shell')", description="Shell"), - ("escape", "app.back", "Back"), - Binding(key="f1", action="about", description="About"), - ] - def __init__( self, click_app_name: str, @@ -257,32 +246,6 @@ def action_close_and_run(self) -> None: self.app.execute_on_exit = True self.app.exit() - def action_copy_command(self) -> None: - if self.command_data is None: - return - - if sys.platform == "win32": - copy_command = ["clip"] - elif sys.platform == "darwin": - copy_command = ["pbcopy"] - else: - copy_command = ["xclip", "-selection", "clipboard"] - - try: - command = self.click_app_name + " " + " ".join(shlex.quote(str(x)) for x in self.command_data.to_cli_args()) - run( - copy_command, - input=command, - text=True, - check=False, - ) - self.notify(f"`{command}` copied to clipboard.") - except FileNotFoundError: - self.notify(f"Could not copy to clipboard. `{copy_command[0]}` not found.", severity="error") - - def action_about(self) -> None: - self.app.push_screen(AboutDialog()) - async def on_mount(self, event: events.Mount) -> None: await self._refresh_command_form() @@ -347,6 +310,16 @@ async def _update_form_body(self, node: TreeNode[CommandSchema]) -> None: class DjangoTui(App): CSS_PATH = Path(__file__).parent / "trogon.scss" + BINDINGS = [ + Binding(key="ctrl+r", action="close_and_run", description="Close & Run"), + Binding(key="ctrl+z", action="copy_command", description="Copy Command to Clipboard"), + Binding(key="ctrl+t", action="focus_command_tree", description="Focus Command Tree"), + # Binding(key="ctrl+o", action="show_command_info", description="Command Info"), + Binding(key="ctrl+s", action="focus('search')", description="Search"), + Binding(key="ctrl+j", action="select_mode('shell')", description="Shell"), + Binding(key="f1", action="about", description="About"), + ] + def __init__( self, *, @@ -426,6 +399,14 @@ def action_select_mode(self, mode_id: Literal["commands", "shell"]) -> None: elif mode_id == "shell": self.app.push_screen(InteractiveShellScreen("Interactive Shell")) + def action_copy_command(self) -> None: + command = self.app_name + " " + " ".join(shlex.quote(str(x)) for x in self.post_run_command) + self.copy_to_clipboard(command) + self.notify(f"`{command}` copied to clipboard.") + + def action_about(self) -> None: + self.app.push_screen(AboutDialog()) + class Command(BaseCommand): help = """Run and inspect Django commands in a text-based user interface (TUI)."""