Giter Site home page Giter Site logo

jeffrimko / qprompt Goto Github PK

View Code? Open in Web Editor NEW
53.0 4.0 7.0 5.7 MB

Python library for quick CLI user prompts, input, and menus.

Home Page: https://pypi.python.org/pypi/qprompt

License: MIT License

Python 92.77% Batchfile 7.23%
prompt cli python library user-input menus

qprompt's Introduction

Qprompt

License Build Status Documentation Status

Library for quick CLI user prompts, input, and menus.

Introduction

This project provides a Python 2.7/3.5+ library that allows the user to quickly create CLI prompts for user input. The main features of Qprompt are:

  • Simple multi-entry menus.

  • Prompt for typed (integer/float/string) input.

  • Optional default values and validity checks.

  • Various CLI convenience functions.

  • User input can optionally be supplied from script command-line arguments allowing for simple automation.

  • Should work on any platform without additional dependencies.

Demo

Status

Currently, this project is in the development release stage. While this project is suitable for use, please note that there may be incompatibilities in new releases.

Release notes are maintained in the project changelog.

Requirements

Qprompt should run on any Python 2.7/3.5+ interpreter and uses some third-party libraries.

Installation

Qprompt is available on PyPI here and can be installed with pip using the following command: pip install qprompt

Additionally, Qprompt can be installed from source by running: python setup.py install

Documentation

The full documentation for this project can be found here on Read the Docs.

Roadmap

The following potential updates are under consideration:

  • Accept multiple menu choices from user at once; e.g. space separated entries like 1 2 q.

  • Timeouts for prompt inputs; default value used if timed out.

Contributing

Contributions or feedback is welcome and encouraged!

A list of those who have helped with this project is available in the authors file.

Similar

The following projects are similar and may be worth checking out:

qprompt's People

Contributors

jeffrimko avatar mungewell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

qprompt's Issues

Pylint error on default value

Pylint gives an error on default values like:

qprompt.ask_yesno(default = 'n')
file:1:18: E1123: Unexpected keyword argument 'default' in function call (unexpected-keyword-arg)

Same goes for dft as keyword.

Accessing selected menu item

There seems to be a functional flaw in Qprompt menus: it returns the name - which is often unrelated to the actual value (description). See the following code:

import qprompt  # https://github.com/jeffrimko/Qprompt

menu = qprompt.Menu()
menu.add('1', 'Microsoft SQL Server')
menu.add('2', 'MySQL')
menu.add('3', 'Oracle')
menu.add('4', 'PostgreSQL')
menu.add('5', 'SQLite')

choice = menu.show()

choice would here a number between 1 and 5. How do I get to the database? I came up with menu.entries[int(choice) - 1].desc which is really cumbersome and only works because the names are numeric.

Indentation error?

Hello,

when trying to run this simple script:

import qprompt
qprompt.hrule(10)

I get the following:

Traceback (most recent call last):
File "p.py", line 1, in
import qprompt
File "/python3.7/site-packages/qprompt.py", line 175
self.add(*quit, func=lambda: quit[0])
^
IndentationError: unexpected indent

Is this something I'm doing wrong?

FeatureRequest: Default item for a menu

Can't figure out how to specify a default entry for a Menu (which will be selected if just enter is pressed). Guess it's not (yet) supported....

import qprompt

menu = qprompt.Menu(hdr="Fruit", msg="What's your favourite", returns="desc")
menu.add("1", "Apple")
menu.add("2", "Bananna")        # Make this the default
menu.add("3", "Carrot")

choice = menu.show()

print("I like %s too!" % choice)

qty = qprompt.ask_int(dft=1, msg="How many would you like")
print(qty)

Can not install Qprompt - missing requirements.txt

Can not install package by pip:

pip install qprompt-0.14.0.tar.gz
Processing qprompt-0.14.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "...Temp\pip-req-build-ud9nuave\setup.py", line 14, in
install_requires=open("requirements.txt").read().splitlines(),
FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'

Installing by python setup.py install also raise same exception
Workaround is to create empty requirements.txt file.

dft in ask_int()

Apologies if this is something obvious - still pretty new to python.

When calling

test = qprompt.ask_int("test", dft=0)

I get

File "/usr/local/lib/python3.4/dist-packages/qprompt.py", line 240, in ask
    vld = sorted(list(set([fmt(v) if fmt(v) else v for v in vld])))
TypeError: unorderable types: type() < int()

which is caused by the dft value. I tried int(0), "0", and some other combination with no luck. Bug?

Python 3.4.3. Qpromtp 0.8.1.

Keywords dft and blk should be mutually exclusive

See the following simple example:

>>> qprompt.ask_str(dft = 'abc', blk = True)
[?] Enter a string [abc]:
'abc'
>>> qprompt.ask_str(dft = 'abc')
[?] Enter a string [abc]:
'abc'
>>> qprompt.ask_str(blk = True)
[?] Enter a string:
''

Is this still being worked on?

Considering this hasn't been pushed to within a month, I presume that the package is getting out of date, but there were a few things I wanted to ask.

  • Are you working on a python3 version, or do you need help with that
  • How well is this used by your own knowledge and with what

Keyword arguments are difficult to remember

For the sake of brevity, keyword arguments have been shortened. Unfortunately they have become quite difficult to remember:

  • dft (?)
  • vld (?)
  • shw (?)
  • blk (black?, block?, bulk?)

LICENSE in sdist

It would be helpful for packaging if the sdist uploaded to PyPI included the LICENSE file.

This is now automatically done by recent setuptools, however the latest upload to PyPI doesnt include one. Normally it could be explicitly added by listing it in MANIFEST.in, but you have a quite different layout in your repos so I dont how you would want to achieve this.

Help is confusing with validation

See the following simple example:

>>> qprompt.ask_int('Port', vld = lambda n: 1 <= n <= 65535)
[?] Port: ?
[<function <lambda> at 0x000001704B7D5B70>]
[?] Port:

Default values accumulated in help

>>> qprompt.ask_int(dft = 1)
[?] Enter an integer [1]: ?
[1, <class 'int'>]
[?] Enter an integer [1]: 1
1
>>> qprompt.ask_int(dft = 2)
[?] Enter an integer [2]: ?
[1, 2, <class 'int'>]
[?] Enter an integer [2]: 33
33
>>> qprompt.ask_int(dft = 44)
[?] Enter an integer [44]: ?
[1, 2, 44, <class 'int'>]
[?] Enter an integer [44]:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.