mirror of https://github.com/JoshKarpel/spiel
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
737 B
Python
31 lines
737 B
Python
from __future__ import annotations
|
|
|
|
import inspect
|
|
from dataclasses import dataclass, field
|
|
from typing import Callable, Mapping
|
|
|
|
from rich.console import RenderableType
|
|
from rich.text import Text
|
|
|
|
from spiel.triggers import Triggers
|
|
|
|
TRIGGERS = "triggers"
|
|
|
|
Content = Callable[..., RenderableType]
|
|
|
|
|
|
@dataclass
|
|
class Slide:
|
|
title: str = ""
|
|
content: Content = lambda: Text()
|
|
bindings: Mapping[str, Callable[..., None]] = field(default_factory=dict)
|
|
|
|
def render(self, triggers: Triggers) -> RenderableType:
|
|
signature = inspect.signature(self.content)
|
|
|
|
kwargs: dict[str, object] = {}
|
|
if TRIGGERS in signature.parameters:
|
|
kwargs[TRIGGERS] = triggers
|
|
|
|
return self.content(**kwargs)
|