From ac1d16095ea20bb65cd60c7422e65ec4a6f3eccb Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Tue, 10 Feb 2026 17:50:06 -0500 Subject: [PATCH] Strip trailing > prompt from embedded z-machine output --- src/mudlib/embedded_if_session.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/mudlib/embedded_if_session.py b/src/mudlib/embedded_if_session.py index c5404d3..93b3b6a 100644 --- a/src/mudlib/embedded_if_session.py +++ b/src/mudlib/embedded_if_session.py @@ -36,6 +36,17 @@ class EmbeddedIFSession: self._zmachine = ZMachine(story_bytes, self._ui) self._filesystem = self._ui.filesystem + def _strip_prompt(self, output: str) -> str: + """Strip trailing > prompt from game output (matches dfrotz behavior).""" + text = output.rstrip() + if text.endswith("\n>"): + return text[:-2].rstrip() + if text == ">": + return "" + if text.endswith(">"): + return text[:-1].rstrip() + return output + @property def save_path(self) -> Path: safe_name = re.sub(r"[^a-zA-Z0-9_-]", "_", self.player.name) @@ -100,6 +111,7 @@ class EmbeddedIFSession: # buffer), producing unwanted output. Suppress it and only show the # restore confirmation. return "restoring saved game...\r\nrestored." + output = self._strip_prompt(output) return output async def handle_input(self, text: str) -> IFResponse: @@ -130,6 +142,7 @@ class EmbeddedIFSession: await loop.run_in_executor(None, wait_for_next_input) output = self._screen.flush() + output = self._strip_prompt(output) if self._done and self._error: output = f"{output}\r\n{self._error}" if output else self._error return IFResponse(output=output, done=self._done)