-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters