Module userland.scripts.oneliners
Oneliners script
Global variables
var LIMIT
-
Total number of oneliners to load
Functions
async def main(cx: SSHContext) ‑> None
Classes
class OnlinersApp (context: SSHContext, **kwargs)
-
Oneliners Textual app
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 theCSS_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 thedev
switch.
Raises
CssPathError
- When the supplied CSS path(s) are an unexpected type.
Expand source code
class OnlinersApp(BannerApp): """Oneliners Textual app""" CSS = """ $accent: ansi_red; $error: ansi_bright_red; Label { width: 100%; } ListItem { background: $primary-background; } ListItem.even { background: $secondary-background; } ListView:focus ListItem.--highlight { background: $accent; } #err { background: $error; color: black; } """ """Stylesheet""" def __init__(self, context: SSHContext, **kwargs): super().__init__(context, **kwargs) self.bind("escape", "quit") def compose(self): for widget in super().compose(): yield widget # oneliners lv = ListView() lv.styles.scrollbar_background = "black" lv.styles.scrollbar_color = "ansi_yellow" lv.styles.scrollbar_color_active = "white" lv.styles.scrollbar_color_hover = "ansi_bright_yellow" yield lv # error message err = Label(id="err") err.display = False yield err # input input_widget = Input( max_length=Oneliner.MAX_LENGTH, placeholder="Enter a oneliner or press ESC", ) input_widget.focus() yield input_widget async def on_input_submitted(self, event: Input.Submitted) -> None: val = event.input.value.strip() if val != "": await Oneliner.create(message=val, user_id=self.context.user.id) self.exit() async def on_mount(self) -> None: db = Resources().db recent = ( Oneliner.select("id") .order_by(Oneliner.id.desc()) .limit(LIMIT) .alias("recent") .select() ) oneliners: list[Oneliner] = await db.all( Oneliner.query.where(Oneliner.id.in_(recent)) ) lv = self.query_one(ListView) for idx, o in enumerate(oneliners): lv.mount( ListItem(Label(o.message), classes="even" if idx % 2 else "") ) lv.index = len(oneliners) - 1 lv.scroll_end(animate=False)
Ancestors
- BannerApp
- XthuluApp
- textual.app.App
- typing.Generic
- textual.dom.DOMNode
- textual.message_pump.MessagePump
Class variables
var CSS
-
Stylesheet
Methods
async def on_input_submitted(self, event: textual.widgets._input.Input.Submitted) ‑> None
async def on_mount(self) ‑> None
Inherited members