diff --git a/content/commands/prompt.toml b/content/commands/prompt.toml new file mode 100644 index 0000000..0efa652 --- /dev/null +++ b/content/commands/prompt.toml @@ -0,0 +1,4 @@ +name = "prompt" +help = "view or customize your prompt" +mode = "*" +handler = "mudlib.commands.prompt:cmd_prompt" diff --git a/src/mudlib/commands/prompt.py b/src/mudlib/commands/prompt.py new file mode 100644 index 0000000..4dd3f42 --- /dev/null +++ b/src/mudlib/commands/prompt.py @@ -0,0 +1,51 @@ +"""Prompt customization command.""" + +from mudlib.player import Player +from mudlib.prompt import DEFAULT_TEMPLATES + + +async def cmd_prompt(player: Player, args: str) -> None: + """View or customize the player's prompt. + + With no arguments, shows the current template and available variables. + With a template string, sets the player's custom prompt. + With 'reset', clears the custom template back to mode default. + """ + args = args.strip() + + if not args: + # Show current template and available variables + current = player.prompt_template or DEFAULT_TEMPLATES.get( + player.mode, "{stamina_gauge} {pl} > " + ) + msg = f"Current prompt: {current}\r\n\r\n" + msg += "Available variables:\r\n" + msg += " stamina_pct - stamina percentage (0-100)\r\n" + msg += " stamina - current stamina value\r\n" + msg += " max_stamina - maximum stamina\r\n" + msg += " stamina_gauge - colored stamina percentage\r\n" + msg += " pl - current power level\r\n" + msg += " max_pl - maximum power level\r\n" + msg += " name - your character name\r\n" + msg += " mode - current mode (normal, combat, etc)\r\n" + msg += " x, y - coordinates\r\n" + msg += " opponent - combat opponent name\r\n" + msg += " move - current attack/defense move\r\n" + msg += " combat_state - combat state (idle/fighting)\r\n" + msg += "\r\n" + msg += "Examples:\r\n" + msg += " prompt {stamina_gauge} {pl} > (simple, default)\r\n" + msg += " prompt {stamina_gauge} {pl}/{max_pl} [{name}] > (full)\r\n" + msg += " prompt reset (back to default)\r\n" + await player.send(msg) + return + + if args.lower() == "reset": + # Clear custom template + player.prompt_template = None + await player.send("Prompt reset to default.\r\n") + return + + # Set custom template + player.prompt_template = args + await player.send(f"Prompt set to: {args}\r\n") diff --git a/tests/test_prompt_command.py b/tests/test_prompt_command.py new file mode 100644 index 0000000..3967bf9 --- /dev/null +++ b/tests/test_prompt_command.py @@ -0,0 +1,76 @@ +"""Tests for the prompt command.""" + +from unittest.mock import AsyncMock, MagicMock + +import pytest + +from mudlib.commands.prompt import cmd_prompt +from mudlib.prompt import render_prompt + + +@pytest.fixture +def mock_writer(): + writer = MagicMock() + writer.write = MagicMock() + writer.drain = AsyncMock() + return writer + + +@pytest.fixture +def mock_reader(): + return MagicMock() + + +@pytest.fixture +def player(mock_reader, mock_writer): + from mudlib.player import Player + + return Player(name="TestPlayer", x=5, y=5, reader=mock_reader, writer=mock_writer) + + +@pytest.mark.asyncio +async def test_prompt_bare_shows_current_and_variables(player): + """prompt with no args shows current template and available variables.""" + await cmd_prompt(player, "") + output = "".join([call[0][0] for call in player.writer.write.call_args_list]) + assert "current" in output.lower() + assert "variables" in output.lower() or "available" in output.lower() + # Should list some variables + assert "stamina" in output.lower() + + +@pytest.mark.asyncio +async def test_prompt_set_custom_template(player): + """prompt