From c67023d7e209f99b22b9bbccc2f1f9f80ce6f028 Mon Sep 17 00:00:00 2001 From: haliphax Date: Thu, 28 Mar 2024 14:23:44 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20main=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- userland/scripts/main.py | 59 ++++++++++++++++++++++++++++++++++++++++ userland/scripts/nua.py | 51 ++++++++++++++++++++++++++++++++++ userland/scripts/top.py | 18 ++++++++---- 3 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 userland/scripts/main.py create mode 100644 userland/scripts/nua.py diff --git a/userland/scripts/main.py b/userland/scripts/main.py new file mode 100644 index 0000000..4e1eacb --- /dev/null +++ b/userland/scripts/main.py @@ -0,0 +1,59 @@ +"""Main menu script""" + +# 3rd party +from textual.app import ComposeResult +from textual.containers import Center, Middle, VerticalScroll +from textual.widgets import Button + +# api +from xthulu.ssh.console.app import XthuluApp +from xthulu.ssh.context import SSHContext + + +class MenuApp(XthuluApp): + """Main menu""" + + CSS = """ + Button { + margin-bottom: 1; + max-width: 100%; + width: 20; + } + + VerticalScroll { + height: auto; + width: 20; + } + """ + """Stylesheet""" + + def compose(self) -> ComposeResult: + yield Center( + Middle( + VerticalScroll( + Button("Messages", name="messages"), + Button("Node chat", name="chat"), + Button("Oneliners", name="oneliners"), + Button("Lock example", name="lock_example"), + Button("Log off", name="goto_logoff", variant="error"), + ) + ) + ) + + async def on_button_pressed(self, event: Button.Pressed) -> None: + assert event.button.name + + return self.exit(result=event.button.name) + + +async def main(cx: SSHContext) -> None: + while True: + result: str | None = await MenuApp(cx).run_async() + + if not result: + return + + if result.startswith("goto_"): + return cx.goto(result[5:]) + + await cx.gosub(result) diff --git a/userland/scripts/nua.py b/userland/scripts/nua.py new file mode 100644 index 0000000..4a22ca7 --- /dev/null +++ b/userland/scripts/nua.py @@ -0,0 +1,51 @@ +"""New user application script""" + +# 3rd party +from textual import events +from textual.app import ComposeResult +from textual.containers import Center, Middle +from textual.widgets import Button + +# api +from xthulu.ssh.console.app import XthuluApp +from xthulu.ssh.context import SSHContext + + +class NuaApp(XthuluApp): + """New user application""" + + CSS = """ + Button { + margin-bottom: 1; + width: 24; + } + """ + """Stylesheet""" + + def compose(self) -> ComposeResult: + yield Center( + Middle( + Button("Continue as guest", variant="success", name="guest"), + Button("Create an account", variant="primary", name="create"), + Button("Log off", variant="error", name="logoff"), + ), + ) + + async def on_button_pressed(self, event: Button.Pressed) -> None: + if event.button.name == "guest": + return self.exit(result="guest") + + if event.button.name == "logoff": + return self.exit(result="logoff") + + self.exit(result="create") + + async def on_key(self, event: events.Key) -> None: + if event.key != "escape": + return + + self.exit(result="logoff") + + +async def main(cx: SSHContext) -> str: + return await NuaApp(cx).run_async() # type: ignore diff --git a/userland/scripts/top.py b/userland/scripts/top.py index e9ccb59..21f7998 100644 --- a/userland/scripts/top.py +++ b/userland/scripts/top.py @@ -27,7 +27,18 @@ async def main(cx: SSHContext) -> None: cx.console.set_window_title(f"{cx.username}@79columns") await scroll_art(cx, "userland/artwork/login.ans", "cp437") - await cx.inkey("Press any key to continue", "dots8Bit") + await cx.inkey("Press any key to continue", "dots8Bit", timeout=5) + + # new user application + if cx.username == "guest": + result = await cx.gosub("nua") + + if result == "create": + cx.echo("Yeah, only that's not ready yet.\n\n") + return + + if not result or result == "logoff": + return cx.console.set_window_title("system information") await scroll_art(cx, "userland/artwork/sysinfo.ans", "amiga") @@ -58,7 +69,4 @@ async def main(cx: SSHContext) -> None: await cx.inkey(timeout=0.1) # show bar at 100% before switching screens await cx.gosub("oneliners") - await cx.gosub("messages") - await cx.gosub("lock_example") - await cx.gosub("chat") - cx.goto("logoff") + cx.goto("main")