Strip dfrotz prompt even without preceding newline
This commit is contained in:
parent
05c9a48bb3
commit
54cd0f6656
3 changed files with 20 additions and 6 deletions
2
justfile
2
justfile
|
|
@ -6,7 +6,7 @@ typecheck:
|
|||
uvx ty check
|
||||
|
||||
test:
|
||||
uv run pytest -n auto --testmon
|
||||
uv run pytest -n auto --no-testmon
|
||||
|
||||
check: lint typecheck test
|
||||
|
||||
|
|
|
|||
|
|
@ -203,20 +203,34 @@ class IFSession:
|
|||
buf += chunk
|
||||
|
||||
# Check for prompt at end of buffer
|
||||
# dfrotz prompt is "\n> " (with trailing space)
|
||||
text = buf.decode("latin-1").rstrip()
|
||||
# dfrotz prompt is always "> " (with trailing space/newline)
|
||||
raw = buf.decode("latin-1")
|
||||
has_prompt = (
|
||||
raw.endswith("> ") or raw.endswith(">\n") or raw.endswith(">\r\n")
|
||||
)
|
||||
text = raw.rstrip()
|
||||
# \n> is always the dfrotz prompt — strip unconditionally
|
||||
if text.endswith("\n>"):
|
||||
return text[:-2].rstrip()
|
||||
if text == ">":
|
||||
return ""
|
||||
# bare > (no preceding newline) — only strip when raw confirms prompt
|
||||
if has_prompt and text.endswith(">"):
|
||||
return text[:-1].rstrip()
|
||||
except TimeoutError:
|
||||
pass
|
||||
|
||||
text = buf.decode("latin-1").rstrip()
|
||||
raw = buf.decode("latin-1")
|
||||
has_prompt = raw.endswith("> ") or raw.endswith(">\n") or raw.endswith(">\r\n")
|
||||
text = raw.rstrip()
|
||||
# \n> is always the dfrotz prompt — strip unconditionally
|
||||
if text.endswith("\n>"):
|
||||
return text[:-2].rstrip()
|
||||
if text == ">":
|
||||
return ""
|
||||
# bare > (no preceding newline) — only strip when raw confirms prompt
|
||||
if has_prompt and text.endswith(">"):
|
||||
return text[:-1].rstrip()
|
||||
return text
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ async def test_start_spawns_subprocess_and_returns_intro():
|
|||
mock_process.stdout = AsyncMock()
|
||||
mock_process.stdin = AsyncMock()
|
||||
|
||||
# Simulate dfrotz output: intro text followed by ">" prompt
|
||||
# Simulate dfrotz output: intro text followed by "\n>" prompt
|
||||
intro_bytes = b"Welcome to the story!\nYou are in a room.\n>"
|
||||
|
||||
async def read_side_effect(n):
|
||||
|
|
@ -599,7 +599,7 @@ async def test_quit_then_stop_does_not_double_save(tmp_path):
|
|||
session.process = mock_process
|
||||
|
||||
# Simulate dfrotz save responses (only expect one save)
|
||||
responses = [b"Enter saved game: \n>", b"Ok.\n>"]
|
||||
responses = [b"Enter saved game: \n> ", b"Ok.\n> "]
|
||||
response_data = b"".join(responses)
|
||||
|
||||
async def read_side_effect(n):
|
||||
|
|
|
|||
Loading…
Reference in a new issue