Compare commits

..

No commits in common. "108091bfae0228d9334b70920e9d1897a7e8c1c0" and "05c9a48bb350351b2a9e30cd41872e5b4af935f0" have entirely different histories.

4 changed files with 12 additions and 28 deletions

View file

@ -6,7 +6,7 @@ typecheck:
uvx ty check
test:
uv run pytest -n auto --no-testmon
uv run pytest -n auto --testmon
check: lint typecheck test

View file

@ -203,34 +203,20 @@ class IFSession:
buf += chunk
# Check for prompt at end of buffer
# 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
# dfrotz prompt is "\n> " (with trailing space)
text = buf.decode("latin-1").rstrip()
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
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
text = buf.decode("latin-1").rstrip()
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("\r\n> ")
_writer.write("> ")
else:
_writer.write("mud> ")
await _writer.drain()
@ -340,22 +340,20 @@ async def shell(
elif player.mode == "if" and player.if_session:
response = await player.if_session.handle_input(command)
if response.output:
# Ensure output ends with newline
output = response.output
if not output.endswith("\r\n"):
output += "\r\n"
await player.send(output)
await player.send(response.output)
# Broadcast to spectators unless it's an escape command
if not command.startswith("::"):
spectator_msg = (
f"[{player.name}'s terminal]\r\n> {command}\r\n{output}"
f"[{player.name}'s terminal]\r\n"
f"> {command}\r\n"
f"{response.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("\r\nyou leave the terminal.\r\n")
await player.send("you 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 "\n>" prompt
# Simulate dfrotz output: intro text followed by ">" prompt
intro_bytes = b"Welcome to the story!\nYou are in a room.\n>"
async def read_side_effect(n):