Skip to main content

A background command handler for python's command-line interface.

Project description

InputHandler Library

A lightweight Python library for creating interactive command-line interfaces with custom command registration and input handling. It supports threaded input processing and includes enhanced logging with color-coded output.

Features

  • Command registration system with descriptions
  • Threaded or non-threaded input handling
  • Colored logging with support for debug mode
  • Built-in help, debug, and exit commands
  • Error handling for missing or invalid command arguments
  • NEW: Register commands with decorators

Installation

pip install cli_ih

Quick Start

from cli_ih import InputHandler

def greet(args):
    print(f"Hello, {' '.join(args)}!")

handler = InputHandler(cursor="> ")
# NEW
@handler.command(name="add", description="Performs the `+` operator on the first 2 arguments.")
def add(args):
    print(int(args[0])+int(args[1]))

handler.register_command("greet", greet, "Greets the user. Usage: greet [name]")
handler.start()

# Now type commands like:
# > greet world
# Hello, world!
# > add 1 2
# 3
# > help
# Available commands:
#   help: Displays all the available commands
#   debug: If a logger is present changes the logging level to DEBUG.
#   exit: Exits the Input Handler irreversibly.
#   add: Performs the `+` operator on the first 2 arguments.
#   greet: Greets the user. Usage: greet [name]
#
# > debug
# > exit

Additional Info

  • You can also import the logging module from cli-ih to use the same config as the module
  • You can provide the thread_mode param to the InputHandler class to set if it shoud run in a thread or no. (If you are using the cli-ih module on its own without any other background task set thread_mode=False to false)
  • You can also provide a cursor param to the InputHandler class to set the cli cursor (default cusor is empty)

Project details


Download files

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

Source Distribution

cli_ih-0.6.0.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cli_ih-0.6.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file cli_ih-0.6.0.1.tar.gz.

File metadata

  • Download URL: cli_ih-0.6.0.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for cli_ih-0.6.0.1.tar.gz
Algorithm Hash digest
SHA256 bf7311426d7e3e93f5284ffad377d9d80c4fd6f106c81c13f053275a91b2ca4d
MD5 5034cc5f5d4b9aa96d34d932178e7fbe
BLAKE2b-256 eccc8dbc7bae369c2bcf6bc67c6bbd0c6641aefb05abef17cb5f793325731db0

See more details on using hashes here.

File details

Details for the file cli_ih-0.6.0.1-py3-none-any.whl.

File metadata

  • Download URL: cli_ih-0.6.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for cli_ih-0.6.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32c35a77ce802109ed7a96a9b87d5f44cd0c5e3f6daabf0fad1202e95d366911
MD5 d527195c7eb8a5d1f6d674747bb3c407
BLAKE2b-256 13579bb922c8ec71cfdd20cef3f09ce8d5a007333e070bdbc0f3f1236c29a311

See more details on using hashes here.

Supported by

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