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.
28 lines
741 B
Python
28 lines
741 B
Python
import inspect
|
|
from collections.abc import Callable, Mapping
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
from rich.console import ConsoleRenderable
|
|
|
|
from spiel.triggers import Triggers
|
|
|
|
|
|
@dataclass
|
|
class Presentable: # Why not an ABC? https://github.com/python/mypy/issues/5374
|
|
title: str = ""
|
|
|
|
def render(self, triggers: Triggers) -> ConsoleRenderable:
|
|
raise NotImplementedError
|
|
|
|
def get_render_kwargs(
|
|
self, function: Callable[..., ConsoleRenderable], triggers: Triggers
|
|
) -> Mapping[str, Any]:
|
|
signature = inspect.signature(function)
|
|
|
|
kwargs: dict[str, Any] = {}
|
|
if "triggers" in signature.parameters:
|
|
kwargs["triggers"] = triggers
|
|
|
|
return kwargs
|