Compare commits

..

1 Commits

Author SHA1 Message Date
cb6f302208 docs(prof.py): add CommandCallback, TimedCallback, WindowCallback protocols
Some checks failed
CI / Check spelling (pull_request) Successful in 22s
CI / Test C API Documentation Generation (pull_request) Successful in 26s
CI / Check coding style (pull_request) Successful in 36s
CI / Test Python API Documentation Generation (pull_request) Failing after 28s
CI / Linux (debian) (pull_request) Has been cancelled
CI / Linux (arch) (pull_request) Has been cancelled
CI / Linux (ubuntu) (pull_request) Has been cancelled
- Defined callback protocols for register_command, register_timed, win_create.
- Fixed Sphinx callable warnings with proper type hints.
- Align docs with the code
2025-09-15 15:47:10 +02:00

View File

@@ -119,8 +119,8 @@ def register_command(
"""Registers a new command in CProof with help information and a callback.
CProof validates the number of arguments (between min_args and max_args) when
the command is invoked. The callback function should accept a list of strings
representing the command arguments.
the command is invoked. The callback function accepts variable string arguments
representing the command parameters.
Args:
name: The command name, including the leading slash (e.g., ``/say``).
@@ -130,8 +130,7 @@ def register_command(
description: Short description of the command.
arguments: List of [argument, description] pairs for help text.
examples: List of example command invocations.
callback: Function to call when the command is executed, taking a list of
strings as arguments.
callback: Function to call when the command is executed, taking variable string arguments.
Returns:
None
@@ -140,18 +139,24 @@ def register_command(
::
def my_command(args: list[str]) -> None:
def command_handler(*args: str) -> None:
prof.cons_show(f"Received: {args}")
if len(args) == 1 and args[0] in ("on", "off"):
prof.cons_show(f"{args[0].capitalize()}ing something")
elif len(args) == 2 and args[0] == "print":
prof.cons_show(args[1])
else:
prof.cons_bad_cmd_usage("/new_command")
synopsis = ["/newcommand action1|action2", "/newcommand print <arg>"]
description = "Performs an action or prints an argument."
synopsis = ["/new_command on|off", "/new_command print <arg>"]
description = "Enables, disables, or prints an argument."
arguments = [
["action1|action2", "Perform action1 or action2"],
["print <arg>", "Print the argument"]
["on|off", "Enable or disable something."],
["print <arg>", "Print the argument."]
]
examples = ["/newcommand action1", "/newcommand print 'test'"]
examples = ["/new_command on", "/new_command print 'test'"]
prof.register_command(
"/newcommand", 1, 2, synopsis, description, arguments, examples, my_command
"/new_command", 1, 2, synopsis, description, arguments, examples, command_handler
)
"""
pass
@@ -190,8 +195,7 @@ def completer_add(key: str, items: list[str]) -> None:
list.
Args:
key: The prefix to trigger autocompletion (e.g., ``/mycommand`` or
``/mycommand action``).
key: The prefix to trigger autocompletion (e.g., ``/mycommand`` or ``/mycommand action``).
items: The items to return on autocompletion.
Returns: