Package: inputkit
inputkitlibrary of input functions. and an input APItested in windows 10('10.0.19041') and python 3(Python 3.9.2)installationRun the following to install:pip install inputkitorpython -m pip install inputkitif that didn't work, try replacingpipwithpip3.need help? or have bugs to report, my discord:labWelcome to the inputkit wiki!github wikilibrary of input functions. and an input APIthat can be used easily.that can be helpful when getting inputs from the userspagescodesinputlib moduleinputs moduleinputstools modulecodescodes to copy ;)import everythingimportinputkit.inputstoolsasinputstools# some functions that i made for testing&funimportinputkit.inputsasinputsprint("inputstools attrs",dir(inputstools))print("inputs attrs",dir(inputs))frominputkitimport*those wait for a char/key lkinputkey,char=any_input()# wait for user input. returns ((char|key) or together)char=char_input()# wait for user input. returns charkey=key_input()# wait for user input. returns keyhide a passwordpassword=password_input("Enter your password: ")# hide the input with (star="*")eval an inputtype=amazing_input("enter a type: ")# returns a type "10"=>int("10")parse an input to commandline listcmd,laststr=commandline_input("enter a command>")# parser the command returns list,laststr "hello \"hi i am a big string\" more stuff" => (['hello', 'hi i am a big string', 'more', 'stuff'], None)parser urlparserUrl,querys=urlparse_input("enter a url: ")# string to ParseUrl "https://google.com/kit?hi=1&yay=omg" => (ParseResult(snetloc='google.com', path='/kit', params='', query='hi=1&yay=omg', fragment=''), {'hi': ['1'], 'yay': ['omg']})wait for a type# going to change the default check functiondefcheck(i,x,y,z):# x is the input valueifx.__class__.__name__=="int":# check if the type is int by namei.stop()# i = Input(); stop(the loop)num=input_wait_for("int","enter a number",check=check)# wait for input type int,list,dict,etccheck inputdefcheck(cls,input):input=input.lower()ifinput=="hello":print("hello")elifinput=="yo":print("yo, bro")elifinput=="good":print("me too")else:print("whats up?")return"no input"# return before we stop the inputcls.stop()# stop the input loopreturn"bye"output=check_input(prompt,check=check)# check_input(prompt="",check=None,input=input); (input = input) default input functionprint(output)# output: byelimit input lengthlimited_string=limit_input("prompt:",length=14)# Limit an input length return when the len(input) is equal to lengthchild process# porcess keyword is a function. that can be replacedproc=subprocess_input("enter process command:")# run a child process. warpper for commandline_input"""another example subprocess_input(prompt="",process=None,*args,**kw):>>> subprocess_input("enter process command:",timeout=10,stdout=-1,process=subprocess.run)enter process command:python -c "print('Hello')"CompletedProcess(args=['python', '-c', "print('Hello')"], returncode=0, stdout=b'Hello\r\n')"""os.system inputcode=system_input("enter a command:")# run a commandline command returns the exit codeignore inputignore_input() # a just input to ignore any inputs. help ("""ignore_input will wait for enter or ^C""")yes or no inputf_t=yn_input("Do you want to eat some vegetables?(y/n):")# warpper for check_input """ yes|no input wait for the user to input ([yes,y,true] or [no,n,false]) returns booling""""""another example yn_input(prompt=""):>>> yn_input("Do you want to eat some vegetables?(y/n):")Do you want to eat some vegetables?(y/n):whatinvalid option for (y/n). try againDo you want to eat some vegetables?(y/n):noFalse # returns False cuz i enter no"""Input classInput API(tested in windows 10)fromInputimport*frominputstoolsimportparser_keys# how to create attr 'proxy_string'withInput("Hello World!:",proxy_string=[],extra_events=dict())as_input:_input.add_event("on_newline",built_in_events_Input.on_newline)@_input.eventdefon_update(cls,start="\x0D",deleted=False):ifdeleted:# going to delete char from the prompttry:cls.proxy_string[len(cls)]=" "# replace it withprint(start+cls.prompt+"".join(cls.proxy_string),end="")delcls.proxy_string[len(cls)]# deleted the space after printing itexceptIndexError:# handlercls.proxy_string=list(cls)# replace cls.proxy_string with the inputprint(start+cls.prompt+"".join(cls.proxy_string),end="")@_input.eventdefon_write(cls,module,prompt):cls.dispatch("update")# create an event@_input.eventdefon_start(cls):cls.run()# start running@_input.eventdefon_read(cls,k,c):ifc==b"\r":# pressed enter or ^Mcls.stop()# stop runningelifk==b"\x08":# on press BackSpacecls-=1cls.dispatch("update",deleted=True)# create an eventelifk==b'\xe0'ork==b"\x00":# type ignore#key = parser_keys(c.decode())  # get KeyError if the key is not defind#print(key,"has been prassed")# Parser(UP = "H", DOWN = "P", RIGHT = "M", LEFT = "K")pass# we're going to ignore this.else:cls+=c.decode()# add char to cls.inputcls.proxy_string=list(cls)@_input.eventdefon_close(cls,output):print(cls.proxy_string)output=_input.start()print()print(repr(output))# the inputNotecls.input type of String not str.
str doesn't support -=Change Log0.2.0 (2022/09/19)First Releasesupporting linuxremoving join, filter. and debugging password_input_fixing install_requires