Module userland.scripts.main

Main menu script

Functions

async def main(cx: SSHContext) ‑> None
Expand source code
async def main(cx: SSHContext) -> None:
    while True:
        cx.console.set_window_title("main menu")
        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)

Classes

class MenuApp (context: SSHContext,
**kwargs)
Expand source code
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)

Main menu

Create an instance of an app.

Args

driver_class
Driver class or None to auto-detect. This will be used by some Textual tools.
css_path
Path to CSS or None to use the CSS_PATH class variable. To load multiple CSS files, pass a list of strings or paths which will be loaded in order.
watch_css
Reload CSS if the files changed. This is set automatically if you are using textual run with the dev switch.
ansi_color
Allow ANSI colors if True, or convert ANSI colors to to RGB if False.

Raises

CssPathError
When the supplied CSS path(s) are an unexpected type.

Ancestors

  • XthuluApp
  • textual.app.App
  • typing.Generic
  • textual.dom.DOMNode
  • textual.message_pump.MessagePump

Class variables

var CSS

Stylesheet

Methods

def compose(self) ‑> Iterable[textual.widget.Widget]
Expand source code
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"),
            )
        )
    )

Yield child widgets for a container.

This method should be implemented in a subclass.

async def on_button_pressed(self, event: textual.widgets._button.Button.Pressed) ‑> None
Expand source code
async def on_button_pressed(self, event: Button.Pressed) -> None:
    assert event.button.name

    return self.exit(result=event.button.name)

Inherited members