A fairly simple method for registering callables as prompt-toolkit completions (Fourteen fork)
Project description
Action Completer (Fourteen Fork)
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)
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fourteen_prompt_toolkit_action_completer-1.2.2.tar.gz.
File metadata
- Download URL: fourteen_prompt_toolkit_action_completer-1.2.2.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6706bb3f5d10c290699723f26941a0ffb013e367f02c4fdb8a85cdcaa5a6280
|
|
| MD5 |
483b1bbe87024b49901a13b60835dc9e
|
|
| BLAKE2b-256 |
1310b3928d432c613ee3f4d1d318a2d05c82d02c2d3a4187ddebbcec57352f49
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fourteen_prompt_toolkit_action_completer-1.2.2.tar.gz -
Subject digest:
c6706bb3f5d10c290699723f26941a0ffb013e367f02c4fdb8a85cdcaa5a6280 - Sigstore transparency entry: 757623083
- Sigstore integration time:
-
Permalink:
Fourteen-IP/prompt-toolkit-action-completer@e599273af97069f2e944dfad02c7e7f40b63e58d -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Fourteen-IP
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e599273af97069f2e944dfad02c7e7f40b63e58d -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fourteen_prompt_toolkit_action_completer-1.2.2-py3-none-any.whl.
File metadata
- Download URL: fourteen_prompt_toolkit_action_completer-1.2.2-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
871013dfed752b4288e4a6e1b6a60af4b1097d7fd4136cf77286619b482b4eec
|
|
| MD5 |
357bd642ce7c0d4da5ca826da0b2e53a
|
|
| BLAKE2b-256 |
e146316a37a07b61751b7bed9a03381d29bc05fad332cdedd94fc803b9f90cf2
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fourteen_prompt_toolkit_action_completer-1.2.2-py3-none-any.whl -
Subject digest:
871013dfed752b4288e4a6e1b6a60af4b1097d7fd4136cf77286619b482b4eec - Sigstore transparency entry: 757623090
- Sigstore integration time:
-
Permalink:
Fourteen-IP/prompt-toolkit-action-completer@e599273af97069f2e944dfad02c7e7f40b63e58d -
Branch / Tag:
refs/heads/master - Owner: https://github.com/Fourteen-IP
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e599273af97069f2e944dfad02c7e7f40b63e58d -
Trigger Event:
workflow_dispatch
-
Statement type: