Skip to main content

A fairly simple method for registering callables as prompt-toolkit completions

Project description

Action Completer

Supported Versions Test Status codecov Documentation Status Code Style: Black

A fairly simple method for registering callables as prompt-toolkit completions.

This package provides the basic features to easily construct a custom completer using decorators to reduce the amount of boilerplate needed to build basic tooling through prompt-toolkit. A quick example is provided below, but if you are interested in the available features and patterns you should read through the documentation.

This is a project that I originally created for myself several times when building personal utilities with prompt-toolkit, and figured it might be useful for other people to eventually use or extend. As a side-effect of this being a personal utility, the provided functionality may not exactly fit what you are looking for and the provided tests do not check all edge cases properly yet.

from pathlib import Path

from action_completer import ActionCompleter
from prompt_toolkit.shortcuts import prompt
from prompt_toolkit.completion import PathCompleter
from prompt_toolkit.validation import Validator

completer = ActionCompleter()


@completer.action("cat")
@completer.param(
  PathCompleter(),
  cast=Path,
  validators=[
      Validator.from_callable(
        lambda p: Path(p).is_file(),
        error_message="Path is not an existing file"
      )
  ]
)
def _cat_action(filepath: Path):
  with filepath.open("r") as file_handle:
      print(file_handle.read())


prompt_result = prompt(
  ">>> ",
  completer=completer,
  validator=completer.get_validator()
)
completer.run_action(prompt_result)

Example Recording

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

prompt-toolkit-action-completer-1.1.1.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file prompt-toolkit-action-completer-1.1.1.tar.gz.

File metadata

  • Download URL: prompt-toolkit-action-completer-1.1.1.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

File hashes

Hashes for prompt-toolkit-action-completer-1.1.1.tar.gz
Algorithm Hash digest
SHA256 8c3e4a344f61cf4c0e3252fe65f0150c7f06b882b2795e71567a2185a6c520bf
MD5 e7cc7750c6580e74b621f492674541a2
BLAKE2b-256 2009c0ea90f66ac5b798a87b5c212a087cce3c83cfee56da1f3faa62f5bbb3dc

See more details on using hashes here.

File details

Details for the file prompt_toolkit_action_completer-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: prompt_toolkit_action_completer-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

File hashes

Hashes for prompt_toolkit_action_completer-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff3d487efc07ecebea5ae851623ec1658c03820b5f058932169de7e360ecf464
MD5 ad08a4f1adea0b538b0bfd752e0b492e
BLAKE2b-256 3f263d3378d37e1ab031128a3c812d360f7472a843f6ffa2b5a0ab50fb21e0b4

See more details on using hashes here.

Supported by

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