Add pending_input callback to Player for prompted input
This commit is contained in:
parent
a24e0c03c3
commit
6524116e97
3 changed files with 17 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
|
||||
import asyncio
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
|
|
@ -29,6 +30,7 @@ class Player(Entity):
|
|||
caps: ClientCaps = field(default_factory=lambda: ClientCaps(ansi=True))
|
||||
editor: Editor | None = None
|
||||
if_session: IFSession | EmbeddedIFSession | None = None
|
||||
pending_input: Callable[..., Any] | None = None
|
||||
paint_mode: bool = False
|
||||
painting: bool = False
|
||||
paint_brush: str = "."
|
||||
|
|
|
|||
|
|
@ -503,6 +503,12 @@ async def shell(
|
|||
# Notify spectators
|
||||
leave_msg = f"{player.name} steps away from the terminal.\r\n"
|
||||
await broadcast_to_spectators(player, leave_msg)
|
||||
else:
|
||||
# Check for pending input callback (used by @help create/edit prompts)
|
||||
if player.pending_input is not None:
|
||||
callback = player.pending_input
|
||||
player.pending_input = None
|
||||
await callback(player, command)
|
||||
else:
|
||||
# Dispatch normal command
|
||||
await mudlib.commands.dispatch(player, command)
|
||||
|
|
|
|||
|
|
@ -154,3 +154,10 @@ def test_zones_toml_loads_from_content():
|
|||
assert "zones" in topics
|
||||
assert topics["zones"].admin is True
|
||||
assert "@zones" in topics["zones"].body
|
||||
|
||||
|
||||
def test_player_has_pending_input():
|
||||
from mudlib.player import Player
|
||||
|
||||
p = Player(name="Test", x=0, y=0, reader=MagicMock(), writer=MagicMock())
|
||||
assert p.pending_input is None
|
||||
|
|
|
|||
Loading…
Reference in a new issue