SmartInput
Much better implementation of the python input function, with hints and history support.
Installation
Use the package manager pip to install smartinput.
Note: Windows support is temporarily dropped. We are working on a fix and will update it soon.
pip install smartinput --upgrade
Or alternatively, you can install the latest version using git:
git clone https://github.com/shivamsn97/smartinput
cd smartinput
python setup.py install
Usage
Using Smart Input:
from smartinput import sinput
mystr = sinput("Enter your name: ") #This parameter is optional
#This will work as a normal input function.
mystr2 = sinput("Enter your designation: ", hints=["teacher","student","developer","hobbyist"])
#This will show hints whenever user will input something.
You can further customize the input field:
from smartinput import sinput, Fore
mystr = sinput("Name: ", hints=["Shivam", "Tushar", "Pulkit", "Imran"], color=Fore.BLUE, hintcolor=Fore.GREEN)
Input History
Yes. You heard it right. sinput supports History. Which means you can use up/down arrow keys to navigate to previously used inputs. By default, previously used history is also treated as hints, and current input is automatically added to the provided History object.
from smartinput import sinput, History, Fore
myhistory = History()
str1 = sinput(">> ", history=myhistory, color=Fore.BLUE)
str2 = sinput(">> ", history=myhistory, color=Fore.BLUE)
str3 = sinput(">> ", history=myhistory, color=Fore.BLUE)
str4 = sinput(">> ", history=myhistory, color=Fore.BLUE)
#You can use up and down arrow keys to navigate to history. Also, history will be shown as hints.
str5 = sinput(">> ", history=myhistory, historyAsHint=False, color=Fore.BLUE)
#Here, history will not be considered as hints.
str6 = sinput(">> ", history=myhistory,autohistory=False, color=Fore.BLUE)
#The input of this command will not be added to history automatically.
Create a Shell
You can create a fully interactive shell using smartinput, in just a few lines.
Making a callback function
To create a shell, you must have a function that accepts two positional parameters, first is the input provided by the user, and second is a instance of a class that will be used to interact with shell in runtime.
def handle_query(query, shell):
shell.out("You said: " + query) #This will output the first parameter on the shell.
#TODO: in future versions, you will also be able to use return in place of shell.out.
You can also exit from the shell using shell.exit()
def handle_query(query, shell):
if("bye" in query):
shell.exit() #will exit the shell when the input is bye.
shell.out("You said: " + query) #This will output the first parameter on the shell.
Alert message (Something like Please Wait...) It automatically disappears on next alert or output.
from time import sleep
def handle_query(query, shell):
shell.alert("Please wait. Thinking...")
sleep(3) #Do processing here.
if("bye" in query):
shell.exit() #will exit the shell when the input is bye.
shell.out("You said: " + query)
Making our Shell
from smartinput import Shell, Fore
myshell = Shell()
#Important:
myshell.setcallback(handle_query) #handle_query function was defined in the above section
#Optional:
myshell.setintitle("Input: ") #defaults to "> "
myshell.setouttitle("Output: ") #defaults to "< "
myshell.setinputcolor(Fore.BLUE)
myshell.setoutputcolor(Fore.GREEN)
myshell.setalertcolor(Fore.RED) # Color for the alert messsage.
myshell.setexiton("quit") #defaults to "exit". Whenever user inputes this or press ctrl+d (EOF, linux), the shell exits.
#You can also pass all these in the Shell constructor:
#myshell = Shell(callback=handle_query, intitle="Input: ", outtitle="Output: ", inputcolor=Fore.BLUE, outputcolor=Fore.GREEN, alertcolor=Fore.RED, exiton="quit")
#Start the shell using:
myshell.start()
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
Metadata
Release files for smartinput 1.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| smartinput-1.0.8.tar.gz | 5.9 kB | Without provenance | Details |
Release files / smartinput-1.0.8.tar.gz
| Download URL | smartinput-1.0.8.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce31d3e0bdd6e06b490f4eb35967065a793619aa062c17536f4513054ab85b4e
|
|
BLAKE2b-256 checksum How to use checksums |
310912b8552c56293e587c41231eef665f8792e4903f2fb894fbf63f746c5718
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
|
Security for smartinput 1.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.