UI - CLI Manager
Building CLI-native integration for UI apps for E2E tests and agents.
Basically every action that is is doable via clicks or keyboard (peripherics) should be doable via the CLI. This builds you the boilerplate that creates a local socket for interacting with tools such as netcat to control the UI app.
On the app-side, the integration should be included in the IO handler exactly as rl.IsKeyPressed or IsMousePressed would appear. Every message must be responded to.
Try it
python3 examples/1-raylib-hello-cli-world.py --headless # run the app
printf 'set_text "speed: 12 m/s" 620 340\nclear_text\n' | ncat localhost 42069
Usage
from ui_cli_manager import UICLIManager
cli = UICLIManager(host="0.0.0.0", port=42069, cli_commands={"set_text": 3, "clear_text": 0})
cli.start() # background thread: accept + answer TCP clients
while not rl.WindowShouldClose():
# I/O handling: polls the channel like rl.IsKeyPressed, never blocks
cli_cmd = cli.get_cli_command()
if cli_cmd is not None:
if cli_cmd.command == "clear_text":
cli_cmd.respond("Cleared all text from the UI")
# ... apply to app state
rl.BeginDrawing()
# ... draw
rl.EndDrawing()
Every command gets exactly one reply: get_cli_command() polls the channels, and cli_cmd.respond() sends the reply back to the waiting client (the thread blocks until you answer — never leave a command unresponded).
Concurrency
- Thread per client: the listener only accepts connections and hands each one to its own daemon thread. A slow/stalled client can never starve the listener or other clients.
max_connectionscap (default 10): when every slot is taken, new connections are refused — the client receivesServer is fulland the connection is closed.0falls back to the default,<0raisesValueError. Passmax_connections=Nto bound the thread count.- One channel per slot: each connection owns a
Channel(two 1-deep queues,primitives.py).get_cli_command()polls the channels in order; eachcli_cmd.respond()routes its reply back to the client that sent the command — interleaved clients never cross wires. Strict-channel semantics: a client can have at most one outstanding request; answer before sending it the next command. - Scripted commands (
script_lines/--script): run first, in order, before any live client command; their responses are logged, never sent to a client (they have no channel).
Protocol
- ASCII, newline-delimited; one line = one command.
- Double-quoted arguments with spaces arrive as one argument (
shlex). - Lines starting with
#are comments. - Every command gets exactly one response; invalid input gets an error response.
- Half-close your write side (Ctrl-D / pipe EOF) to disconnect.
Installation
Python 3.11+. The library is meant to be packaged into your main project. Just add it as a module.
Dependencies: pip install -e . (add [dev] for pytest).
For the example: pip install raylib as well.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ui_cli_manager-0.1.0.tar.gz.
File metadata
- Download URL: ui_cli_manager-0.1.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea3a3c48951112abd2bd1802306a9acfd93e0926f103cc91ce1587eca0b2f1a5
|
|
| MD5 |
f57490913c52a8b959d0aa844b077361
|
|
| BLAKE2b-256 |
6486433a45eb2954774550984804d3e245fab94bbc995ab27ebf34f97d4adca1
|