GithubHelp home page GithubHelp logo

tonydero / cutie Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kamik423/cutie

0.0 1.0 0.0 4.93 MB

Commandline User Tools for Input Easification

Home Page: https://github.com/kamik423/cutie

License: MIT License

Python 100.00%

cutie's Introduction

CUTIE

Commandline User Tools for Input Easification

PRs Welcome PyPI version PyPI license PyPI pyversions PEP8

A tool for handling common user input functions in an elegant way. It supports asking yes or no questions, selecting an element from a list with arrow keys, forcing the user to input a number and secure text entry while having many customization options.

For example the yes or no input supports forcing the user to match case, tab autocomplete and switching option with the arrow keys. The number input allows setting a minum and a maximum, entering floats or forcing the user to use integers. It will only return once the user inputs a number in that format, showing a warning to them if it does not conform.

It should work on all major operating systems (Mac, Linux, Windows).

example

Usage

These are the main functions of cutie:

import cutie

if cutie.prompt_yes_or_no('Are you brave enough to continue?'):
    names = [
        'Arthur, King of the Britons',
        'Sir Lancelot the Brave',
        'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot',
        'Sir Bedevere the Wise',
        'Sir Galahad the Pure',
        'Møøse']
    name = names[cutie.select(names, selected_index=5)]
    print(f'Welcome, {name}')
    age = cutie.get_number(
        'What is your age?',
        min_value=0,
        allow_float=False)
    quest = cutie.secure_input('What is your quest?')
    print(f'{name}\'s quest (who is {age}) is {quest}.')

When run, as demonstrated in the gif above it yields this output:

Are you brave enough to continue? (Y/N) Yes
[ ] Arthur, King of the Britons
[ ] Sir Lancelot the Brave
[x] Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot
[ ] Sir Bedevere the Wise
[ ] Sir Galahad the Pure
[ ] Møøse
Welcome, Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot
What is your age? 31
What is your quest?
Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot's quest (who is 31) is to seek the holy grail.

Installation

pip3 install cutie

Documentation

get_number

Get a number from user input. If an invalid number is entered the user will be prompted again.

Arguments

argument type default description
prompt str The prompt asking the user to input.
min_value float, optional - infinity The [inclusive] minimum value.
max_value float, optional infinity The [inclusive] maximum value.
allow_float bool, optional True Allow floats or force integers.

Returns

The number input by the user.

secure_input

Get secure input without showing it in the command line.

Arguments

argument type description
prompt str The prompt asking the user to input.

Returns

The secure input.

select

Select an option from a list.

Arguments

argument type default description
options List[str] The options to select from.
deselected_prefix str, optional [ ] Prefix for deselected option.
selected_prefix str, optional [x] Prefix for selected option.
selected_index int, optional 0 The index to be selected at first.

Returns

The index that has been selected.

prompt_yes_or_no

Prompt the user to input yes or no.

Arguments

argument type default description
question str The prompt asking the user to input.
yes_text str, optional Yes The text corresponding to 'yes'.
no_text str, optional No The text corresponding to 'no'.
has_to_match_case bool, optional False Does the case have to match.
enter_empty_confirms bool, optional True Does enter on empty string work.
default_is_yes bool, optional False Is yes selected by default
deselected_prefix str, optional Prefix if something is deselected.
selected_prefix str, optional > Prefix if something is selected
abort_value Optional[bool], optional None The value on interrupt.
char_prompt bool, optional True Add a [Y/N] to the prompt.

Returns

The bool what has been selected.

Contributing

If you want to contribute, please feel free to suggest features or implement them yourself.

Also please report any issues and bugs you might find!

Authors

  • Main project by me.
  • Windows support by Lhitrom.

License

The project is licensed under the MIT-License.

Acknowledgments

  • This project uses the module Readchar for direct input handling.

GNU Terry Pratchett

cutie's People

Contributors

cchndl avatar kamik423 avatar

Watchers

 avatar

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.