Package: cutie
CUTIECommand line User Tools for Input EasificationA 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 or vim 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).UsageThese are the main functions of cutie.example.pycontains an extended version of this also showing off theselect_multipleoption.importcutieifcutie.prompt_yes_or_no("Are you brave enough to continue?"):# List of names to select from, including some captionsnames=["Kings:","Arthur, King of the Britons","Knights of the Round Table:","Sir Lancelot the Brave","Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot","Sir Bedevere the Wise","Sir Galahad the Pure","Swedish captions:","Møøse",]# Names which are captions and thus not selectablecaptions=[0,2,7]# Get the namename=names[cutie.select(names,caption_indices=captions,selected_index=8)]print(f"Welcome,{name}")# Get an integer greater or equal to 0age=cutie.get_number("What is your age?",min_value=0,allow_float=False)# Get input without showing it being typedquest=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
Kings:
[ ] Arthur, King of the Britons
Knights of the Round Table:
[ ] Sir Lancelot the Brave
[x] Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot
[ ] Sir Bedevere the Wise
[ ] Sir Galahad the Pure
Swedish captions:
[ ] 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 find the holy grail.InstallationWith pip from pypi:pip3installcutieWith pip from source or in a virtual environment:pip3install-rrequirements.txtDocumentationAll functions of cutie are explained here.
If something is still unclear or you have questions about the implementation just take a look atcutie.py.
The implementation is rather straight forward.get_numberGet a number from user input.If an invalid number is entered the user will be prompted again.
A minimum and maximum value can be supplied. They are inclusive.
If theallow_floatoption, which isTrueby default is set toFalseit forces the user to enter an integer.Getting any three digit number for example could be done like that:number=cutie.get_number("Please enter a three digit number:",min_value=100,max_value=999,allow_float=False)# which is equivalent tonumber=cutie.get_number("Please enter a three digit number",100,999,False)ArgumentsargumenttypedefaultdescriptionpromptstrThe prompt asking the user to input.min_valuefloat, optional- infinityThe [inclusive] minimum value.max_valuefloat, optionalinfinityThe [inclusive] maximum value.allow_floatbool, optionalTrueAllow floats or force integers.ReturnsThe number input by the user.secure_inputGet secure input without showing it in the command line.This could be used for passwords:password=cutie.secure_input("Please enter your password:")ArgumentsargumenttypedescriptionpromptstrThe prompt asking the user to input.ReturnsThe secure input.selectSelect an option from a list.Captions or separators can be included between options by adding them as an option and including their index incaption_indices.
A preselected index can be supplied.In its simplest case it could be used like this:colors=["red","green","blue","yellow"]print("What is your favorite color?")favorite_color=colors[cutie.select(colors)]With the high degree of customizability, however it is possible to do things like:print("Select server to ping")server_id=cutie.select(servers,deselected_prefix="    ",selected_prefix="PING",selected_index=default_server_ip)ArgumentsargumenttypedefaultdescriptionoptionsList[str]The options to select from.caption_indicesList[int], optionalNoneNon-selectable indices.deselected_prefixstr, optional[ ]Prefix for deselected option.selected_prefixstr, optional[x]Prefix for selected option.caption_prefixstr, optionalPrefix for captions.selected_indexint, optional0The index to be selected at first.confirm_on_selectbool, optionalTrueSelect keys also confirm.ReturnsThe index that has been selected.select_multipleSelect multiple options from a list.It per default shows a "confirm" button.
In that case space bar and enter select a line.
The button can be hidden.
In that case space bar selects the line and enter confirms the selection.This is not in the example in this readme, but inexample.py.packages_to_update=cutie.select_multiple(outdated_packages,deselected_unticked_prefix="  KEEP  ",deselected_ticked_prefix=" UPDATE ",selected_unticked_prefix="[ KEEP ]",selected_ticked_prefix="[UPDATE]",ticked_indices=list(range(len(outdated_packages))),deselected_confirm_label="  [[[[ UPDATE ]]]]  ",selected_confirm_label="[ [[[[ UPDATE ]]]] ]")ArgumentsargumenttypedefaultdescriptionoptionsList[str]The options to select from.caption_indicesList[int], optionalNon-selectable indices.deselected_unticked_prefixstr, optional( )Prefix for lines that are not selected and not ticked .deselected_ticked_prefixstr, optional(x)Prefix for lines that are not selected but ticked .selected_unticked_prefixstr, optional{ }Prefix for lines that are selected but not ticked .selected_ticked_prefixstr, optional{x}Prefix for lines that are selected and ticked .caption_prefixstr, optionalPrefix for captions.ticked_indicesList[int], optional[]Indices that are ticked initially.cursor_indexint, optional0The index the cursor starts at.minimal_countint, optional0The minimal amount of lines that have to be ticked.maximal_countint, optionalinfinityThe maximal amount of lines that have to be ticked.hide_confirmbool, optionalTrueHide the confirm button. This causes<ENTER>to confirm the entire selection and not just tick the line.deselected_confirm_labelstr, optional(( confirm ))The confirm label if not selected.selected_confirm_labelstr, optional{{ confirm }}The confirm label if selected.ReturnsA list of indices that have been selected.prompt_yes_or_noPrompt the user to input yes or no.This again can range from very simple to very highly customized:ifcutie.prompt_yes_or_no("Do you want to continue?"):do_continue()ifcutie.prompt_yes_or_no("Do you want to hear ze funniest joke in ze world? Proceed at your own risk.",yes_text="JA",no_text="nein",has_to_match_case=True,# The user has to type the exact caseenter_empty_confirms=False,# An answer has to be selected)ArgumentsargumenttypedefaultdescriptionquestionstrThe prompt asking the user to input.yes_textstr, optionalYesThe text corresponding to "yes".no_textstr, optionalNoThe text corresponding to "no".has_to_match_casebool, optionalFalseDoes the case have to match.enter_empty_confirmsbool, optionalTrueDoes enter on empty string work.default_is_yesbool, optionalFalseIs yes selected by defaultdeselected_prefixstr, optionalPrefix if something is deselected.selected_prefixstr, optional>Prefix if something is selectedchar_promptbool, optionalTrueAdd a [Y/N] to the prompt.ReturnsThe bool what has been selected.Changelog0.3.2CircleCI Integration0.3.1Readme fixes for PyPi0.3.0Unittests byprovinzkrautTravis CI integrationVim Arrow keys (jk)Also showing error messages withhide_confirmoption enabled inselect_multipleConsistenly crash on keyboard interrupt (Removesprompt_yes_or_no'sabort_value)Sethide_confirmto default inselect_multiple(#9)Black code style0.2.2Fixed Python in examplesPEP8 Compliance byChristopher BilgerFixed critical issue with pypi download (#15)0.2.1Expanded readme descriptions0.2.0select_multipleTweaks to the readme0.1.1Fixed pypi download not working0.1.0caption_indicesoption bydherrada0.0.7Windows support byLhitrom0.0.xInitial upload and got everything workingContributingIf you want to contribute, please feel free to suggest features or implement them yourself.Alsoplease report any issues and bugs you might find!If you have a project that uses cutie please let me know and I'll link it here!AuthorsMain project byme.Unittests, issues and advice byprovinzkraut.Windows support byLhitrom.caption_indicesand tidbits bydherrada.PEP8 Compliance byChristopher Bilger.LicenseThe project is licensed under theMIT-License.AcknowledgmentsThis project uses the moduleReadcharfor direct input handling.GNU Terry Pratchett