Package: koinput
Table of contentskoinputWhat’s new?InstallationHow to useInputsExplanation of input parametersUsage exampleMenuUsage exampleProgressBarUsage examplekoinputMaximal simplification of Input / Output for text programs.PyPI for releases|Github for sourceWhat’s new?0.3.2Minor improvements and bug fixes.Fixed inaccuracies in README file.0.3.1Added multiple input for int_input and float_input.0.3.0Added a new ProgressBar function. How to use see below.Added input_suggestion_style for Menu and Inputs.InstallationRequirementscoloramalibrary.pipinstallkoinputHow to useInputsThe library has two types of inputs:int_inputfloat_inputThey have the same settings and differ only in the type of output.Explanation of input parametersdefint_input(input_suggestion:str='',greater:floatorint=float('-inf'),less:floatorint=float('inf'),console_style:str=Fore.RESET,error_message:str='Invalid number format.\n',error_message_style:str=Fore.RED,multiple_numbers_in_line:bool=False,input_is_greater_than_less_error:str="The number is greater than acceptable.\n",input_is_less_than_greater_error:str="The number is less than acceptable.\n",input_is_less_error_style:str=None,input_is_greater_error_style:str=None,strictly_greater:bool=True,strictly_less:bool=True,input_suggestion_style:str=None)->intorlist:input_suggestion=""Input suggestion that will be displayed when the function is run.greater=float('-inf'),less=float('inf')The range in which the entered number should be included.strictly_greater=True, strictly_less=TrueControlling the mathematical strictly of comparisons.console_style=colorama.Fore.RESETSets the base display style for the terminal. I recommend using the colorama library for easier style customization. You can also use standard sequences (example: “x1b[39m”).error_message='Invalidnumberformat.\n'Error message when converting input to number.error_message_style=colorama.Fore.REDError message style.input_is_greater_than_less_error="Thenumber is greater thanacceptable.\n"The message issued when the number is greater than allowed.input_is_less_than_greater_error="Thenumber is less thanacceptable.\n"The message issued when the number is less than allowed.input_is_less_error_style=None, input_is_greater_error_style=NoneOut of range error styles.input_suggestion_style=NoneInput suggestion style.multiple_numbers_in_line=FalseIf True the function will return a list of numbers entered in one line.Usage exampledefarea_triangle(base,height):return0.5*base*heightprint(area_triangle(float_input(input_suggestion='Enter the base of the triangle: '),float_input(input_suggestion='Введите высоту треугольника: ')))mas=[randint(0,999)foriinrange(int_input(input_suggestion="Enter the size of the array: "))]MenuThe menu class is used to quickly create a text menu based on existing functions.First, you need to create an instance of the class:fromkoinputimportMenumenu=Menu()The next step is to add function calls to the menu. This can be done in 2 ways: using a decorator or a function.@menu.add_to_menu_dec('Name shown in the menu',*arguments_passed_to_the_function)defz2(a,b,c):defarea_circle(radius):returnmath.pi*radius**2print(area_circle(float_input(input_suggestion='Введите радиус круга: ')))ORdefz2(a,b,c):defarea_circle(radius):returnmath.pi*radius**2print(area_circle(float_input(input_suggestion='Введите радиус круга: ')))menu.add_to_menu('Name shown in the menu',z2,*arguments_passed_to_the_function)Use the show_menu command to display the menu.defshow_menu(self,title:str=None,title_style:str=None,number_of_leading_spaces_title:int=2,console_style:str=Fore.RESET,order_of_items:tuple=None,number_of_leading_spaces:int=4,separator:str=' - ',items_style:str=None,input_suggestion:str='Select a menu item: ',enable_menu_item_exit:bool=True,menu_item_exit:str='Exit',exit_offer:str='Press Enter to exit...',input_suggestion_style:str=None):title=NoneMenu title.title_style=NoneSets the title display style. I recommend using the colorama library for easier style customization. You can also use standard sequences (example: “x1b[39m”).number_of_leading_spaces_title=2Sets the number of spaces before the menu title.console_style=Fore.RESETSets the base display style for the terminal. I recommend using the colorama library for easier style customization. You can also use standard sequences (example: “x1b[39m”).number_of_leading_spaces=4Sets the number of spaces before the menu items.separator=' - 'Separator between number and menu item name.items_style=NoneSets the menu item display style.input_suggestion='Selecta menu item: 'Input suggestion at the end of the menu.input_suggestion_style=NoneInput suggestion style.enable_menu_item_exit=TrueEnabling the menu item exit. If False, then after selecting one of the items the menu will close.menu_item_exit='Exit'The name of the menu exit item.exit_offer='PressEnter toexit...'Exit message.order_of_items=NoneCustom order of issuing menu items. It is either a tuple of int or a tuple of str. A tuple of int must contain the ordinal numbers of items starting from 0 (the numbers are given in the order in which they are declared). The str tuple must contain the names of the menu items in the order they appear.Change the function of output from the menu.This is necessary when you do not need an exit confirmation or when you exit you need to launch another menu or some function.Example with disabling the exit confirmation:@menu.reassign_menu_exit()defmenu_exit(exit_offer):deff():passreturnfExample with displaying another menu:@menu.reassign_menu_exit()defmenu_exit(exit_offer):deff():menu2.show_menu(title='MENU',title_colour=colorama.Fore.BLUE,enable_menu_item_exit=False)returnfUsage exampleimportmathfromkoinputimportfloat_input,Menuimportcoloramamenu=Menu()@menu.add_to_menu_dec('Площадь треугольника')defz1():defarea_triangle(base,height):return0.5*base*heightprint(area_triangle(float_input(input_suggestion='Введите основание треугольника: '),float_input(input_suggestion='Введите высоту треугольника: ')))@menu.add_to_menu_dec('Площадь круга')defz2():defarea_circle(radius):returnmath.pi*radius**2print(area_circle(float_input(input_suggestion='Введите радиус круга: ')))@menu.add_to_menu_dec('Расстояние от точки до точки')defz3():defdistance(x1,y1,x2,y2):returnmath.sqrt((x2-x1)**2+(y2-y1)**2)print(distance(float_input(input_suggestion='Введите X первой точки: '),float_input(input_suggestion='Введите Y первой точки: '),float_input(input_suggestion='Введите X второй точки: '),float_input(input_suggestion='Введите Y второй точки: ')))defz4():defcapitalize_word(word):returnword[0].upper()+word[1::]defcapitalize_string(s):ss=s.split()forwordinss:s=s.replace(word,capitalize_word(word))returnsprint('Введите строку для изменения: ')print(capitalize_string(input()))@menu.reassign_menu_exit()defmenu_exit(exit_offer):deff():passreturnfdefmain():menu.add_to_menu('Capitalize',z4)menu.show_menu(title='МЕНЮ',title_colour=colorama.Fore.BLUE)if__name__=='__main__':main()ProgressBarThe progress bar is designed to show the progress of long-running tasks.First, we import the ProgressBar class.fromkoinputimportProgressBarThe class has properties:ProgressBar.max_value: int or float = 100The maximum value from which the percentage is calculated or indicated in the counter mode.ProgressBar.counter: bool = FalseEnables counter mode. It displays not percentages, but value from max_value.ProgressBar.string: str ="[########################################]@@@%"Indicates the view of the Progress Bar.ProgressBar.progressbar_symbol: str = "#"A symbol indicating the placement of a progress bar.ProgressBar.percent_symbol: str = "@"The symbol indicating the placement of percent (as well as the number of decimal places) or in counter mode only indicates its location.ProgressBar.counter_separator: str = '/'A character or string to be displayed between value and max_value in counter mode.To display the progress bar, use the show function.ProgressBar.show(value:intorfloat,text:str=None)valueThe current value of the progress bar.text=NoneComment for the current operation.Usage examplefromkoinputimportProgressBarfromtimeimportsleepProgressBar.max_value=123foriinrange(124):ProgressBar.show(i)sleep(0.07)ProgressBar.max_value=10ProgressBar.counter=TrueProgressBar.string="|&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&| {*}"ProgressBar.progressbar_symbol="&"ProgressBar.percent_symbol="*"ProgressBar.counter_separator=' element of 'foriinrange(11):ProgressBar.show(i,f"Element{i}")sleep(0.7)