Last active
January 18, 2022 04:11
-
-
Save USLTD/9b64c971da5426f59a0c488267466cca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from wcwidth import wcswidth | |
import shutil | |
def print_centre(text: str): | |
width = shutil.get_terminal_size()[0] | |
length = wcswidth(text) | |
l = len(text) | |
d = length // l | |
space = width - length | |
if space >= 0: | |
pads = " " * (space // 2) | |
print(f"{pads}{text}{pads}") | |
else: | |
print(text[:(width//d)]) | |
left = text[(width//d):] | |
print_centre(left) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment