Package: py-inquirer-cli
Update: We are looking for a successor/maintainance. Here: <https://github.com/CITGuru/PyInquirer/issues/159>Github is starting to invite developers in from the GitHub Sponsors waitlist!Your recommendations matter, so be sure to nominateme and other contributorsof this project you’d like to see on GitHub Sponsors next by using the form in this link:http://github.co/2IHdeOwPyInquirer is a collection of common interactive command line user interfaces.PyInquirer 1.0.3 Bugfix UpdatePyInquirer 1.0.3 <https://github.com/CITGuru/PyInquirer/releases/tag/1.0.3>Table of ContentsDocumentationInstallationExamplesQuickstartQuestion TypesQuestion PropertiesUser Interfaces and StylesWindows PlatformSupportContributionAcknowledgmentsLicenseGoal and PhilosophyPyInquirerstrives to be an easily embeddable and beautiful
command line interface forPython.PyInquirerwants to make it easy for existing Inquirer.js users
to write immersive command line applications in Python. We are convinced
that its feature-set is the most complete for building immersive CLI
applications. We also hope thatPyInquirerproves itself useful
to Python users.PyInquirershould ease the process of - providingerror
feedback-asking questions-parsinginput -validatinganswers
- managinghierarchical promptsNote:PyInquirerprovides the user interface and the inquiry
session flow. >DocumentationInstallationLike most Python packages PyInquirer is available onPyPi.
Simply use pip to install the PyInquirer packagepipinstallPyInquirerIn case you encounter any prompt_toolkit error, that means you’ve the
wrong prompt_toolkit version.You can correct that by doingpipinstallprompt_toolkit==1.0.14or download the wheel file from here:https://pypi.org/project/prompt_toolkit/1.0.14/#filesQuickstartLike Inquirer.js, using inquirer is structured into two simple steps:you define alist of questionsand hand them topromptprompt returns alist of answersfrom__future__importprint_function,unicode_literalsfromPyInquirerimportprompt,print_jsonquestions=[{'type':'input','name':'first_name','message':'What\'s your first name',}]answers=prompt(questions)print_json(answers)# use the answers as input for your appA good starting point from here is probably the examples section.ExamplesMost of the examples intend to demonstrate a single question type or
feature:editor.pyexpand.pylist.pypassword.pywhen.pycheckbox.pyconfirm.pyhierarchical.pypizza.py- demonstrate using different question typesinput.pyrawlist.pyIf you want to launch examples with the code from repository instead of
installing a package you need to executepip install-e.within project
directory.Question Typesquestionsis a list of questions. Each question has a type.List -{type: 'list'}Taketype,name,message,choices[,default,filter] properties. (Note that default must be the choiceindexin the array or a choicevalue)s —Raw List -{type: 'rawlist'}Taketype,name,message,choices[,default,filter] properties. (Note that default must the choiceindexin
the array)Raw list promptExpand -{type: 'expand'}Taketype,name,message,choices[,default]
properties. (Note that default must be the choiceindexin the
array. Ifdefaultkey not provided, thenhelpwill be used as
default choice)Note that thechoicesobject will take an extra parameter calledkeyfor theexpandprompt. This parameter must be a single
(lowercased) character. Thehoption is added by the prompt and
shouldn’t be defined by the user.Seeexamples/expand.pyfor a running example.Checkbox -{type: 'checkbox'}Taketype,name,message,choices[,filter,validate] properties.Choices marked as{'checked': True}will be checked by default.Choices whose propertydisabledis truthy will be unselectable. Ifdisabledis a string, then the string will be outputted next to the
disabled choice, otherwise it’ll default to"Disabled". Thedisabledproperty can also be a synchronous function receiving the
current answers as argument and returning a boolean or a string.Thepointer_indexkwarg can be used to specify initial pointer position.Checkbox promptConfirm -{type: 'confirm'}Taketype,name,message[,default] properties.defaultis expected to be a boolean if used.Confirm promptInput -{type: 'input'}Taketype,name,message[,default,filter,validate] properties.Input promptPassword -{type: 'password'}Taketype,name,message[,default,filter,validate] properties.Password promptEditor -{type: 'editor'}Taketype,name,message[,default,filter,validate,eargs] propertiesEditor Arguments -eargsOpens an empty or edits the default text in the defined editor.  If an editor is given
(should be the full path to the executable but the regular operating
system search path is used for finding the executable) it overrides
the detected editor.  Optionally, some environment variables can be
used.  If the editor is closed without changes,Noneis returned.  In
case a file is edited directly the return value is alwaysNoneandsaveandextare ignored.Takes:editor: acceptsdefaultto get the default platform editor. But
you can also provide the path to an editor e.gvi.ext: the extension to tell the editor about. This defaults to.txtbut changing this might change syntax highlighting e.g “.py”save: acceptsTrueorFalseto determine to save a file.filename: accepts the path of a file you’d like to edit.env: accepts any given environment variables to pass to the editorLaunches an instance of the users preferred editor on a temporary file.
Once the user exits their editor, the contents of the temporary file are
read in as the result. The editor to use is determined by reading the
VISUAL or EDITOR environment variables. If neither of those
are present, notepad (on Windows) or vim (Linux or Mac) is used.Question PropertiesA question is a dictionary containing question related values:type: (String) Type of the prompt. Defaults: input - Possible values:
input, confirm, list, rawlist, expand, checkbox, password, editorname: (String) The name to use when storing the answer in the answers
hash. If the name contains periods, it will define a path in the
answers hash.message: (String|Function) The question to print. If defined as a
function, the first parameter will be the current inquirer session
answers.default: (String|Number|Array|Function) Default value(s) to use if
nothing is entered, or a function that returns the default value(s).
If defined as a function, the first parameter will be the current
inquirer session answers.choices: (Array|Function) Choices array or a function returning a
choices array. If defined as a function, the first parameter will be
the current inquirer session answers. Array values can be simple
strings, or objects containing a name (to display in list), a value
(to save in the answers hash) and a short (to display after
selection) properties. The choices array can also contain a
Separator.validate: (Function) Receive the user input and should return true if
the value is valid, and an error message (String) otherwise. If false
is returned, a default error message is provided.filter: (Function) Receive the user input and return the filtered
value to be used inside the program. The value returned will be added
to the Answers hash.when: (Function, Boolean) Receive the current user answers hash and
should return true or false depending on whether or not this question
should be asked. The value can also be a simple boolean.pageSize: (Number) Change the number of lines that will be rendered
when using list, rawList, expand or checkbox.User Interfaces and StylesTODOWindows Platform``PyInquirer``is build on prompt_toolkit which is cross platform,
and everything that you build on top should run fine on both Unix and
Windows systems. On Windows, it uses a different event loop
(WaitForMultipleObjects instead of select), and another input and output
system. (Win32 APIs instead of pseudo-terminals and VT100.)It’s worth noting that the implementation is a “best effort of what is
possible”. Both Unix and Windows terminals have their limitations. But
in general, the Unix experience will still be a little better.For Windows, it’s recommended to use either cmder or conemu.SupportMost of the questions are probably related to using a question type or
feature. Please lookup and study the appropriate examples.Issue on Github TODO linkFor many issues like for example common Python programming issues
stackoverflow might be a good place to search for an answer. TODO linkContribution$gitclonegit@github.com:CITGuru/PyInquirer.git$cdPyInquirer$python-mvenvvenv$sourcevenv/bin/activate$pipinstall--upgradepip$pipinstall-rrequirements.txt$pipinstall-rrequirements_dev.txtWith an environment ready you can add new feature and check everything works
just fine$pytest-svtests/That’s it, now you can fork a project and submit PR with your change!CreditsContributorsThis project exists thanks to all the people who contribute!BackersThank you to all our backers!Become a backer.SponsorsSupport us by becoming a sponsor. Your logo will show up here with a link to your website.Become a sponsor.LicenseCopyright (c) 2018 Oyetoke Toby (twitter: @oyetokeT)Licensed under the MIT license.