Module userland.scripts.oneliners
Oneliners script
Global variables
var LIMIT-
Total number of oneliners to load
Functions
async def main(cx: SSHContext) ‑> None-
Expand source code
async def main(cx: SSHContext) -> None: cx.console.set_window_title("oneliners") await OnelinersApp( cx, art_path=path.join("userland", "artwork", "oneliners.ans"), art_encoding="amiga", alt="79 Columns // Oneliners", ).run_async()
Classes
class OnelinersApp (context: SSHContext,
**kwargs)-
Expand source code
class OnelinersApp(BannerApp): """Oneliners Textual app""" AUTO_FOCUS = "Input" BANNER_PADDING = 15 CSS = """ $accent: ansi_red; Label { width: 100%; } ListView { width: 100%; } ListItem { background: $primary-background; } ListItem.even { background: $secondary-background; } ListView:focus ListItem.-highlight { background: $accent; } """ def __init__(self, context: SSHContext, **kwargs): "" # empty docstring super(OnelinersApp, self).__init__(context, **kwargs) self.bind("escape", "quit") def compose(self): for widget in super(OnelinersApp, self).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 # input yield Input( max_length=Oneliner.MAX_LENGTH, placeholder="Enter a oneliner or press ESC", ) async def on_input_submitted(self, event: Input.Submitted) -> None: val = event.input.value.strip() if val != "": async with db_session() as db: db.add(Oneliner(message=val, user_id=self.context.user.id)) await db.commit() self.exit() async def on_mount(self) -> None: recent = ( select(Oneliner.id) .order_by(col(Oneliner.id).desc()) .limit(LIMIT) .alias("recent") .select() ) async with db_session() as db: oneliners = ( await db.exec( select(Oneliner).where(col(Oneliner.id).in_(recent)) ) ).all() 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)Oneliners Textual app
Ancestors
- BannerApp
- XthuluApp
- textual.app.App
- typing.Generic
- textual.dom.DOMNode
- textual.message_pump.MessagePump
Class variables
var AUTO_FOCUSvar CSS
Methods
def compose(self)-
Expand source code
def compose(self): for widget in super(OnelinersApp, self).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 # input yield Input( max_length=Oneliner.MAX_LENGTH, placeholder="Enter a oneliner or press ESC", ) async def on_input_submitted(self, event: textual.widgets._input.Input.Submitted) ‑> None-
Expand source code
async def on_input_submitted(self, event: Input.Submitted) -> None: val = event.input.value.strip() if val != "": async with db_session() as db: db.add(Oneliner(message=val, user_id=self.context.user.id)) await db.commit() self.exit() async def on_mount(self) ‑> None-
Expand source code
async def on_mount(self) -> None: recent = ( select(Oneliner.id) .order_by(col(Oneliner.id).desc()) .limit(LIMIT) .alias("recent") .select() ) async with db_session() as db: oneliners = ( await db.exec( select(Oneliner).where(col(Oneliner.id).in_(recent)) ) ).all() 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)
Inherited members