"""Shared fake input helper for REPL Behave scenarios."""

from __future__ import annotations


class FakeReplInput:
    """Feed predefined lines and then terminate input with EOFError."""

    def __init__(self, lines: list[str], *, interrupt_token: str | None = None) -> None:
        self._lines = list(lines)
        self._index = 0
        self._interrupt_token = interrupt_token

    def __call__(self, prompt: str = "") -> str:
        del prompt
        if self._index >= len(self._lines):
            raise EOFError
        line = self._lines[self._index]
        self._index += 1
        if self._interrupt_token is not None and line == self._interrupt_token:
            raise KeyboardInterrupt
        return line
