Compare commits

...

3 commits

4 changed files with 28 additions and 12 deletions

View file

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

View file

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

View file

@ -315,7 +315,7 @@ async def shell(
if player.mode == "editor" and player.editor:
_writer.write(f" {player.editor.cursor + 1}> ")
elif player.mode == "if" and player.if_session:
_writer.write("> ")
_writer.write("\r\n> ")
else:
_writer.write("mud> ")
await _writer.drain()
@ -340,20 +340,22 @@ async def shell(
elif player.mode == "if" and player.if_session:
response = await player.if_session.handle_input(command)
if response.output:
await player.send(response.output)
# Ensure output ends with newline
output = response.output
if not output.endswith("\r\n"):
output += "\r\n"
await player.send(output)
# Broadcast to spectators unless it's an escape command
if not command.startswith("::"):
spectator_msg = (
f"[{player.name}'s terminal]\r\n"
f"> {command}\r\n"
f"{response.output}"
f"[{player.name}'s terminal]\r\n> {command}\r\n{output}"
)
await broadcast_to_spectators(player, spectator_msg)
if response.done:
await player.if_session.stop()
player.if_session = None
player.mode_stack.pop()
await player.send("you leave the terminal.\r\n")
await player.send("\r\nyou leave the terminal.\r\n")
# Notify spectators
leave_msg = f"{player.name} steps away from the terminal.\r\n"
await broadcast_to_spectators(player, leave_msg)

View file

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