"""Adapter wrapping Display as a Stage.""" from typing import Any from engine.pipeline.core import PipelineContext, Stage class DisplayStage(Stage): """Adapter wrapping Display as a Stage.""" def __init__(self, display, name: str = "terminal"): self._display = display self.name = name self.category = "display" self.optional = False @property def capabilities(self) -> set[str]: return {"display.output"} @property def dependencies(self) -> set[str]: return {"render.output"} # Display needs rendered content @property def inlet_types(self) -> set: from engine.pipeline.core import DataType return {DataType.TEXT_BUFFER} # Display consumes rendered text @property def outlet_types(self) -> set: from engine.pipeline.core import DataType return {DataType.NONE} # Display is a terminal stage (no output) def init(self, ctx: PipelineContext) -> bool: w = ctx.params.viewport_width if ctx.params else 80 h = ctx.params.viewport_height if ctx.params else 24 result = self._display.init(w, h, reuse=False) return result is not False def process(self, data: Any, ctx: PipelineContext) -> Any: """Output data to display.""" if data is not None: self._display.show(data) return data def cleanup(self) -> None: self._display.cleanup()