Strip trailing > prompt from embedded z-machine output

This commit is contained in:
Jared Miller 2026-02-10 17:50:06 -05:00
parent 909ee0932b
commit ac1d16095e
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -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)