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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ui_cli_manager-0.2.0.tar.gz (10.6 kB view details)

Uploaded Source

File details

Details for the file ui_cli_manager-0.2.0.tar.gz.

File metadata

  • Download URL: ui_cli_manager-0.2.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for ui_cli_manager-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4f8a05affe849ca2e8122704812bdf47647a8086e45c5bbe531c75c406abb2d4
MD5 4dcd776516bd95621164f27fe138f8b1
BLAKE2b-256 47fd34f3831c3becf3b0b9026aa07fb3b573f7fbe74ade1331607fa810ee7e06

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 file

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page