Skip to content

Commit

Permalink
✨ main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax committed Mar 28, 2024
1 parent d5f5c35 commit c67023d
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 5 deletions.
59 changes: 59 additions & 0 deletions userland/scripts/main.py
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 51 additions & 0 deletions userland/scripts/nua.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 13 additions & 5 deletions userland/scripts/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")

0 comments on commit c67023d

Please sign in to comment.