1.0.37
This commit is contained in:
parent
e9346c46e3
commit
2f1c9be49e
3 changed files with 44 additions and 17 deletions
|
@ -1,6 +1,8 @@
|
||||||
# Firepup650
|
# Firepup650
|
||||||
Package containing various shorthand things I use, and a few imports I almost always use
|
Package containing various shorthand things I use, and a few imports I almost always use
|
||||||
### Change log:
|
### 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:
|
#### 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
|
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:
|
#### v.1.0.35:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "firepup650"
|
name = "firepup650"
|
||||||
version = "1.0.36"
|
version = "1.0.37"
|
||||||
authors = ["Firepup650 <firepyp650@gmail.com>"]
|
authors = ["Firepup650 <firepyp650@gmail.com>"]
|
||||||
description = "Package containing various shorthand things I use, and a few imports I almost always use"
|
description = "Package containing various shorthand things I use, and a few imports I almost always use"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
|
@ -118,7 +118,11 @@ def e(code: Union[str, int, None] = None) -> NoReturn:
|
||||||
|
|
||||||
|
|
||||||
def gp(
|
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]:
|
) -> Union[str, bytes]:
|
||||||
"""# Function: gp
|
"""# Function: gp
|
||||||
Get keys and print them.
|
Get keys and print them.
|
||||||
|
@ -126,6 +130,8 @@ def gp(
|
||||||
keycount: int - Number of keys to get, defaults to 1
|
keycount: int - Number of keys to get, defaults to 1
|
||||||
chars: list - List of keys to accept, defaults to ["1", "2"]
|
chars: list - List of keys to accept, defaults to ["1", "2"]
|
||||||
bytes: bool - Wether to return the kyes as bytes, defaults to False
|
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:
|
# Returns:
|
||||||
Union[str, bytes] - Keys pressed
|
Union[str, bytes] - Keys pressed
|
||||||
|
@ -133,21 +139,32 @@ def gp(
|
||||||
# Raises:
|
# Raises:
|
||||||
None"""
|
None"""
|
||||||
got = 0
|
got = 0
|
||||||
keys = ""
|
keys = []
|
||||||
while got < keycount:
|
if allowDelete:
|
||||||
key = fkey.getchars(1, chars) # type: str #type: ignore
|
chars.append(fkey.KEYS["BACKSPACE"].decode())
|
||||||
keys = f"{keys}{key}"
|
flushPrint(filler * keycount)
|
||||||
flushPrint(key)
|
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
|
got += 1
|
||||||
print()
|
print()
|
||||||
if not bytes:
|
if not bytes:
|
||||||
return keys
|
return "".join(keys)
|
||||||
else:
|
else:
|
||||||
return keys.encode()
|
return ("".join(keys)).encode()
|
||||||
|
|
||||||
|
|
||||||
def gh(
|
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]:
|
) -> Union[str, bytes]:
|
||||||
"""# Function: gh
|
"""# Function: gh
|
||||||
Get keys and print `char` in their place.
|
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"]
|
chars: list - List of keys to accept, defaults to ["1", "2"]
|
||||||
char: str - Character to use to obfuscate the keys, defaults to *
|
char: str - Character to use to obfuscate the keys, defaults to *
|
||||||
bytes: bool - Wether to return the kyes as bytes, defaults to False
|
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:
|
# Returns:
|
||||||
Union[str, bytes] - Keys pressed
|
Union[str, bytes] - Keys pressed
|
||||||
|
@ -163,17 +182,23 @@ def gh(
|
||||||
# Raises:
|
# Raises:
|
||||||
None"""
|
None"""
|
||||||
got = 0
|
got = 0
|
||||||
keys = ""
|
keys = []
|
||||||
while got < keycount:
|
if allowDelete:
|
||||||
key = fkey.getchars(1, chars) # type: str#type: ignore
|
chars.append(fkey.KEYS["BACKSPACE"].decode())
|
||||||
keys = f"{keys}{key}"
|
flushPrint(filler * keycount)
|
||||||
flushPrint("*")
|
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
|
got += 1
|
||||||
print()
|
print()
|
||||||
if not bytes:
|
if not bytes:
|
||||||
return keys
|
return "".join(keys)
|
||||||
else:
|
else:
|
||||||
return keys.encode()
|
return ("".join(keys)).encode()
|
||||||
|
|
||||||
|
|
||||||
def printt(text: str, delay: float = 0.1, newline: bool = True) -> None:
|
def printt(text: str, delay: float = 0.1, newline: bool = True) -> None:
|
||||||
|
|
Loading…
Reference in a new issue