0

I'm trying to print the following string in a centralised position in the console, but .center() doesn't seem to work

"""             ,      ,
             (.-""-.)
        |\  \/      \/  /|
        | \ / =.  .= \ / |
        \( \   o\/o   / )/
         \_, '-/  \-' ,_/
           v   \__/   v
           \ \__/\__/ /
         ___\ \|--|/ /___
       /`    \      /    `\
"""
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
AlexiBoxi
  • 13
  • 1

1 Answers1

2

The problem is that in your input string you have spaces before your pixel art. I used also the answer provided in the comments (link).

import shutil

SIZE = shutil.get_terminal_size()
COLUMNS = SIZE.columns


def tty_center_str(s: str):
    print(s.center(COLUMNS))


def tty_center_multiline(s: str):
    for line in s.splitlines():
        tty_center_str(line.strip())

Output:

>>> tty_center_multiline(s)
                                    ,      ,                                    
                                    (.-""-.)                                    
                               |\  \/      \/  /|                               
                               | \ / =.  .= \ / |                               
                               \( \   o\/o   / )/                               
                                \_, '-/  \-' ,_/                                
                                  v   \__/   v                                  
                                  \ \__/\__/ /                                  
                                ___\ \|--|/ /___                                
                              /`    \      /    `\                               

crissal
  • 2,547
  • 7
  • 25