From 2f1c9be49e15dde923c2801766d1a03fe2809d06 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Mon, 3 Jun 2024 14:27:14 -0500 Subject: [PATCH] 1.0.37 --- package/README.md | 2 ++ package/pyproject.toml | 2 +- package/src/firepup650/__init__.py | 57 +++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/package/README.md b/package/README.md index 45277d6..52883bc 100644 --- a/package/README.md +++ b/package/README.md @@ -1,6 +1,8 @@ # 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: diff --git a/package/pyproject.toml b/package/pyproject.toml index 40adeed..c000db4 100644 --- a/package/pyproject.toml +++ b/package/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "firepup650" -version = "1.0.36" +version = "1.0.37" authors = ["Firepup650 "] description = "Package containing various shorthand things I use, and a few imports I almost always use" readme = "README.md" diff --git a/package/src/firepup650/__init__.py b/package/src/firepup650/__init__.py index 782caa0..e79f2ce 100644 --- a/package/src/firepup650/__init__.py +++ b/package/src/firepup650/__init__.py @@ -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: