Compare commits
2 commits
74716df0a1
...
2f1c9be49e
Author | SHA1 | Date | |
---|---|---|---|
2f1c9be49e | |||
e9346c46e3 |
3 changed files with 48 additions and 19 deletions
|
@ -1,6 +1,10 @@
|
|||
# Firepup650
|
||||
Package containing various shorthand things I use, and a few imports I almost always use
|
||||
### Change log:
|
||||
#### v.1.0.37
|
||||
Upgrades to gp and gh, they now function as stand-alone prompts, and allow deletion of characters as well (`allowDelete` must be set to `True`)
|
||||
#### v.1.0.36:
|
||||
Fix an old annoying bug with menus having an incorrect size calculation if the width of the menu was an even number
|
||||
#### v.1.0.35:
|
||||
Adds a few missing docstrings and fixes a bug with the menu function
|
||||
#### v.1.0.34:
|
||||
|
@ -74,4 +78,4 @@ Random shorthand (literally)
|
|||
#### v.1.0.1:
|
||||
Added animated typing function, sleep shorthand
|
||||
#### v.1.0.0:
|
||||
Initial Release!
|
||||
Initial Release!
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "firepup650"
|
||||
version = "1.0.35"
|
||||
version = "1.0.37"
|
||||
authors = ["Firepup650 <firepyp650@gmail.com>"]
|
||||
description = "Package containing various shorthand things I use, and a few imports I almost always use"
|
||||
readme = "README.md"
|
||||
|
@ -28,4 +28,4 @@ fpsql = "^1, !=1.0.26"
|
|||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
|
|
@ -118,7 +118,11 @@ def e(code: Union[str, int, None] = None) -> NoReturn:
|
|||
|
||||
|
||||
def gp(
|
||||
keycount: int = 1, chars: list = ["1", "2"], bytes: bool = False
|
||||
keycount: int = 1,
|
||||
chars: list = ["1", "2"],
|
||||
bytes: bool = False,
|
||||
allowDelete: bool = False,
|
||||
filler: str = "-",
|
||||
) -> Union[str, bytes]:
|
||||
"""# Function: gp
|
||||
Get keys and print them.
|
||||
|
@ -126,6 +130,8 @@ def gp(
|
|||
keycount: int - Number of keys to get, defaults to 1
|
||||
chars: list - List of keys to accept, defaults to ["1", "2"]
|
||||
bytes: bool - Wether to return the kyes as bytes, defaults to False
|
||||
allowDelete: bool - Wether to allow deleting chars, defaults to False
|
||||
filler: str - The character to use as filler when waiting on more chars, defaults to "-"
|
||||
|
||||
# Returns:
|
||||
Union[str, bytes] - Keys pressed
|
||||
|
@ -133,21 +139,32 @@ def gp(
|
|||
# Raises:
|
||||
None"""
|
||||
got = 0
|
||||
keys = ""
|
||||
while got < keycount:
|
||||
key = fkey.getchars(1, chars) # type: str #type: ignore
|
||||
keys = f"{keys}{key}"
|
||||
flushPrint(key)
|
||||
keys = []
|
||||
if allowDelete:
|
||||
chars.append(fkey.KEYS["BACKSPACE"].decode())
|
||||
flushPrint(filler * keycount)
|
||||
while len(keys) < keycount:
|
||||
key = fkey.getchars(1, chars, True) # type: bytes #type: ignore
|
||||
if not allowDelete or key != fkey.KEYS["BACKSPACE"]:
|
||||
keys.append(key.decode())
|
||||
elif len(keys):
|
||||
keys.pop()
|
||||
flushPrint(f"\033[{keycount}D{''.join(keys)}{filler*(keycount-len(keys))}")
|
||||
got += 1
|
||||
print()
|
||||
if not bytes:
|
||||
return keys
|
||||
return "".join(keys)
|
||||
else:
|
||||
return keys.encode()
|
||||
return ("".join(keys)).encode()
|
||||
|
||||
|
||||
def gh(
|
||||
keycount: int = 1, chars: list = ["1", "2"], char: str = "*", bytes: bool = False
|
||||
keycount: int = 1,
|
||||
chars: list = ["1", "2"],
|
||||
char: str = "*",
|
||||
bytes: bool = False,
|
||||
allowDelete: bool = False,
|
||||
filler: str = "-",
|
||||
) -> Union[str, bytes]:
|
||||
"""# Function: gh
|
||||
Get keys and print `char` in their place.
|
||||
|
@ -156,6 +173,8 @@ def gh(
|
|||
chars: list - List of keys to accept, defaults to ["1", "2"]
|
||||
char: str - Character to use to obfuscate the keys, defaults to *
|
||||
bytes: bool - Wether to return the kyes as bytes, defaults to False
|
||||
allowDelete: bool - Wether to allow deleting chars, defaults to False
|
||||
filler: str - The character to use as filler when waiting on more chars, defaults to "-"
|
||||
|
||||
# Returns:
|
||||
Union[str, bytes] - Keys pressed
|
||||
|
@ -163,17 +182,23 @@ def gh(
|
|||
# Raises:
|
||||
None"""
|
||||
got = 0
|
||||
keys = ""
|
||||
while got < keycount:
|
||||
key = fkey.getchars(1, chars) # type: str#type: ignore
|
||||
keys = f"{keys}{key}"
|
||||
flushPrint("*")
|
||||
keys = []
|
||||
if allowDelete:
|
||||
chars.append(fkey.KEYS["BACKSPACE"].decode())
|
||||
flushPrint(filler * keycount)
|
||||
while len(keys) < keycount:
|
||||
key = fkey.getchars(1, chars, True) # type: bytes #type: ignore
|
||||
if not allowDelete or key != fkey.KEYS["BACKSPACE"]:
|
||||
keys.append(key.decode())
|
||||
elif len(keys):
|
||||
keys.pop()
|
||||
flushPrint(f"\033[{keycount}D{char*len(keys)}{filler*(keycount-len(keys))}")
|
||||
got += 1
|
||||
print()
|
||||
if not bytes:
|
||||
return keys
|
||||
return "".join(keys)
|
||||
else:
|
||||
return keys.encode()
|
||||
return ("".join(keys)).encode()
|
||||
|
||||
|
||||
def printt(text: str, delay: float = 0.1, newline: bool = True) -> None:
|
||||
|
|
Loading…
Reference in a new issue