This commit is contained in:
Firepup Sixfifty 2024-06-03 15:05:00 -05:00
parent 2f1c9be49e
commit ec7ad5845c
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
3 changed files with 23 additions and 3 deletions

View file

@ -1,7 +1,9 @@
# 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 #### v.1.0.38:
Mappings for much larger menu sizes, hopefully no one should ever hit that limit.
#### 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`) 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

View file

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "firepup650" name = "firepup650"
version = "1.0.37" version = "1.0.38"
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"

View file

@ -880,6 +880,24 @@ def menu(options: dict, title: str = "") -> object:
UP = [fkey.KEYS["UP"], b"w", b"a", fkey.KEYS["LEFT"]] UP = [fkey.KEYS["UP"], b"w", b"a", fkey.KEYS["LEFT"]]
DOWN = [fkey.KEYS["DOWN"], b"s", b"d", fkey.KEYS["RIGHT"]] DOWN = [fkey.KEYS["DOWN"], b"s", b"d", fkey.KEYS["RIGHT"]]
indicatorSize = len(str(limit)) * 2 + 1 indicatorSize = len(str(limit)) * 2 + 1
indicatorOffset = 999
match indicatorSize:
case 3: # 1-9 options
indicatorOffset = 1
case 5: # 10-99 options
indicatorOffset = 0
case 7: # 100-999 options
indicatorOffset = -1
case 9: # 1000-9999 options
indicatorOffset = -2
case 11: # 10000-99999 options
indicatorOffset = -3
case 13: # 100000-999999 options
indicatorOffset = -4
case _:
raise ValueError(
f"You have more menu options than was ever expected to be used, please notify the package author to add a offset mappting for an indicator size of {indicatorSize}."
)
menuWidth = max( menuWidth = max(
[max([len(choice) for choice in choices]) + 4, indicatorSize * 2 + 7] [max([len(choice) for choice in choices]) + 4, indicatorSize * 2 + 7]
) )
@ -888,7 +906,7 @@ def menu(options: dict, title: str = "") -> object:
flushPrint( flushPrint(
(title + "\n" if title else "") (title + "\n" if title else "")
+ f"{''*menuWidth}\n" + f"{''*menuWidth}\n"
+ f"{f'{current+1}'}{' '*(len(str(limit))-len(str(current+1)))}/{limit}{' '*int(menuWidth/2-indicatorSize-2.5)}{' '*int((menuWidth-indicatorSize)/2-(0 if indicatorSize!=3 else 1)+(1 if menuWidth%2==0 else 0))}\n" + f"{f'{current+1}'}{' '*(len(str(limit))-len(str(current+1)))}/{limit}{' '*int(menuWidth/2-indicatorSize-2.5)}{' '*int((menuWidth-indicatorSize)/2-indicatorOffset+(1 if menuWidth%2==0 else 0))}\n"
+ f"║←{' '*int(((menuWidth-len(choices[current]))/2)-1)}{choices[current]}{' '*int((menuWidth-len(choices[current]))/2-.5)}→║\n" + f"║←{' '*int(((menuWidth-len(choices[current]))/2)-1)}{choices[current]}{' '*int((menuWidth-len(choices[current]))/2-.5)}→║\n"
+ f"{' '*int((menuWidth-1)/2)}{' '*int((menuWidth-1)/2+.5)}\n" + f"{' '*int((menuWidth-1)/2)}{' '*int((menuWidth-1)/2+.5)}\n"
+ f"{''*menuWidth}\n" + f"{''*menuWidth}\n"