Skip to content

Commit

Permalink
command args and switch to shell key binding
Browse files Browse the repository at this point in the history
  • Loading branch information
shtayeb committed Dec 19, 2023
1 parent 8eeeb4a commit b260b8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/django_tui/management/commands/ish.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def __init__(
Binding(key="ctrl+underscore", action="toggle_comment", description="Toggle Comment",show=False),
Binding(key="f1", action="editor_keys", description="Key Bindings"),
Binding(key="f2", action="default_imports", description="Default imports"),
("escape", "app.back()", "Back")
Binding(key="ctrl+j", action="select_mode('commands')", description="Commands"),
]


Expand Down
26 changes: 22 additions & 4 deletions src/django_tui/management/commands/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ class DjangoCommandBuilder(Screen):
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"),
("escape", "app.pop_screen", "Back"),
Binding(key="ctrl+j", action="select_mode('shell')", description="Shell"),
("escape", "app.back", "Back"),
Binding(key="f1", action="about", description="About"),
]

Expand Down Expand Up @@ -386,17 +387,23 @@ class DjangoTui(App):

def __init__(
self,
open_shell: bool = False,
) -> None:
super().__init__()
self.post_run_command: list[str] = []
self.is_grouped_cli = True
self.execute_on_exit = False
self.app_name = "python manage.py"
self.command_name = "django-tui"
self.open_shell = open_shell


def on_mount(self):
# self.push_screen(DjangoCommandBuilder(self.app_name, self.command_name))
self.push_screen(HomeScreen(self.app_name))
if self.open_shell:
self.push_screen(InteractiveShellScreen("Interactive Shell"))
else:
self.push_screen(DjangoCommandBuilder(self.app_name, self.command_name))
# self.push_screen(HomeScreen(self.app_name))

@on(Button.Pressed, "#home-exec-button")
def on_button_pressed(self):
Expand Down Expand Up @@ -450,9 +457,20 @@ def action_visit(self, url: str) -> None:
"""
open_url(url)

def action_select_mode(self,mode_id:str) -> None:
if mode_id == "commands":
self.app.push_screen(DjangoCommandBuilder("pyhton manage.py", "Test command name"))

elif mode_id == "shell":
self.app.push_screen(InteractiveShellScreen("Interactive Shell"))
class Command(BaseCommand):
help = """Run and inspect Django commands in a text-based user interface (TUI)."""

def add_arguments(self, parser):
parser.add_argument("--shell",action="store_true", help="Open django shell")

def handle(self, *args: Any, **options: Any) -> None:
app = DjangoTui()
open_shell = options.get("shell")

app = DjangoTui(open_shell=open_shell)
app.run()

0 comments on commit b260b8e

Please sign in to comment.