Skip to main content

a wrapper to prompt-toolkit, designed to provide a fallback for some of prompt-toolkit's functionality when operating from a place where prompt-toolkit can't run

Project description

safer-prompt-toolkit

a wrapper to prompt-toolkit, designed to provide a fallback for some of prompt-toolkit's functionality when operating from a place where prompt-toolkit can't run.

intent:

prompt-toolkit is a powerfull, command line UI, built in to almost every python interpreter. I love using it when asking the user for some input. However, prompt toolkit often complains and crashes when asked to run in certain non-terminal invorments (for example pycharms python console). and I find that this to be a major downside to using prompt toolkit as a minor UI part in some major project, that might somtimes be run in some context that is not the terminal.
after making several projects that needed this functionality, and after deciding that copy pasting this prompt-toolkit fallback project is tedius and unhealthy, I desided to make this thing a project and upload it ot pypi.

Installation

pip install safer-prompt-toolkit

Documentation

after installing, you can import like so:

import safer_prompt_toolkit

and you can send some prompt via:

safer_prompt_toolkit.prompt("some query with validation and completion options")

function documentation

safer_prompt_toolkit.prompt(message,max_failcase_completion_lines=3,max_chars_in_completion_line=150,**prompt_toolkit_kwargs)

use prompt_toolkit's prompt function with a fail-safe
Parameters:

  • message - the prompt messege to be printed to the user, (add \n at the end if you want to get the response in a new line)
  • max_failcase_completion_lines - defaults to 3, in case the regular prompt toolkit fails, max_failcase_completion_lines is the maximum amount of lines in the completion
  • max_chars_in_completion_line - defaults to 150, in case the regular prompt toolkit fails, max_chars_in_completion_line is the maximum amount of chars in a line in the completion
  • **prompt_toolkit_kwargs - any of prompt-toolkits keywords. in case the regular prompt toolkit fails, "validator" and "completer" are used if supplied.

returns:

  • the users response

info:

prompt_toolkit_kwargs allows you to enter some prompt_toolkit.validation.Validator instance. for example 'validator=prompt_toolkit.validation.Validator.DummyValidator()'.
prompt_toolkit_kwargs allows you to enter some prompt_toolkit.completion.Completer instance. for example 'completer=prompt_toolkit.completion.Completer.DummyCompleter()'

call_example:

import safer_prompt_toolkit
import prompt_toolkit.validation,prompt_toolkit.completion

validator1 = prompt_toolkit.validation.DummyValidator() # Could be any prompt_toolkit.validation.Validator instance.
completer1 = prompt_toolkit.completion.DummyCompleter() # Could be any prompt_toolkit.completion.Completer instance.

response = safer_prompt_toolkit.prompt("some prompt message\n",validator=validator1,completer=completer1)
print(f"{response} is the users response.") 

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

safer_prompt_toolkit-1.8.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

safer_prompt_toolkit-1.8-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file safer_prompt_toolkit-1.8.tar.gz.

File metadata

  • Download URL: safer_prompt_toolkit-1.8.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.7

File hashes

Hashes for safer_prompt_toolkit-1.8.tar.gz
Algorithm Hash digest
SHA256 21b93c298cdf68b6baf014d14068774c0acd75b9dfc4af5b0f10cdb361cb9b8a
MD5 ab026919646385c31e82d07a62bf8da5
BLAKE2b-256 9c0c318a24510b203e1551500e2c174b7d5eced91e7ca2df8d5753d62746cb3f

See more details on using hashes here.

File details

Details for the file safer_prompt_toolkit-1.8-py3-none-any.whl.

File metadata

  • Download URL: safer_prompt_toolkit-1.8-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.7.7

File hashes

Hashes for safer_prompt_toolkit-1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d71a1b11856b4bd84549b8693b47363f85f755518ac1a6daced035da26b720e1
MD5 af4da5c163e106e6beac38dc78ce710e
BLAKE2b-256 179872fa624e276239ecc9d0cee0c759abd507cc6593bbb48f98a687c2dc78ef

See more details on using hashes here.

Supported by

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