Skip to main content

A fairly simple method for registering callables as prompt-toolkit completions (Fourteen fork)

Project description

Action Completer (Fourteen Fork)

Supported Versions Test Status Code Style: Black

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

Note: This is a fork of stephen-bunn/prompt-toolkit-action-completer maintained by Fourteen-IP with additional features and improvements.

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

Built Distribution

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

File details

Details for the file fourteen_prompt_toolkit_action_completer-1.2.2.tar.gz.

File metadata

File hashes

Hashes for fourteen_prompt_toolkit_action_completer-1.2.2.tar.gz
Algorithm Hash digest
SHA256 c6706bb3f5d10c290699723f26941a0ffb013e367f02c4fdb8a85cdcaa5a6280
MD5 483b1bbe87024b49901a13b60835dc9e
BLAKE2b-256 1310b3928d432c613ee3f4d1d318a2d05c82d02c2d3a4187ddebbcec57352f49

See more details on using hashes here.

Provenance

The following attestation bundles were made for fourteen_prompt_toolkit_action_completer-1.2.2.tar.gz:

Publisher: publish.yml on Fourteen-IP/prompt-toolkit-action-completer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fourteen_prompt_toolkit_action_completer-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fourteen_prompt_toolkit_action_completer-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 871013dfed752b4288e4a6e1b6a60af4b1097d7fd4136cf77286619b482b4eec
MD5 357bd642ce7c0d4da5ca826da0b2e53a
BLAKE2b-256 e146316a37a07b61751b7bed9a03381d29bc05fad332cdedd94fc803b9f90cf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fourteen_prompt_toolkit_action_completer-1.2.2-py3-none-any.whl:

Publisher: publish.yml on Fourteen-IP/prompt-toolkit-action-completer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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