Skip to main content

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_connections cap (default 10): when every slot is taken, new connections are refused — the client receives Server is full and the connection is closed. 0 falls back to the default, <0 raises ValueError. Pass max_connections=N to 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; each cli_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.

Metadata

Release files for ui-cli-manager 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ui-cli-manager 0.2.0
File Size Uploaded
ui_cli_manager-0.2.0.tar.gz 10.6 kB Details

Release files / ui_cli_manager-0.2.0.tar.gz

Download URL ui_cli_manager-0.2.0.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4f8a05affe849ca2e8122704812bdf47647a8086e45c5bbe531c75c406abb2d4
BLAKE2b-256 checksum
How to use checksums
47fd34f3831c3becf3b0b9026aa07fb3b573f7fbe74ade1331607fa810ee7e06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page