Advertisement
Eccat

Untitled

Dec 4th, 2022
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. def center(var: str, space: int = None):  #
  2.     try:
  3.         if not space:
  4.             space = (os.get_terminal_size().columns - len(var.splitlines()[int(len(var.splitlines()) / 2)])) / 2
  5.  
  6.         return "\n".join((' ' * int(space)) + var for var in var.splitlines())
  7.     except:
  8.         print(
  9.             f'[{Fore.LIGHTRED_EX}Error{Fore.RESET}] Failed to center text. This is most likely due to being in debug '
  10.             f'mode.')
  11.         pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement