Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
48.13k stars 1.69k forks source link

[BUG] Center looks strange #3323

Closed sus2790 closed 2 months ago

sus2790 commented 2 months ago

Describe the bug

Original:

image

Output:

image

Expect:

image

The banner just looks werid, not much to say.

Platform

Click to expand What platform (Win/Linux/Mac) are you running on? Windows 11 What terminal software are you using? Python 3.12.2 / Vscode 1.88.0 ╭───────────────────────── ─────────────────────────╮ │ A high level console interface. │ │ │ │ ╭──────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = 'truecolor' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 20 │ │ is_alt_screen = False │ │ is_dumb_terminal = False │ │ is_interactive = True │ │ is_jupyter = False │ │ is_terminal = True │ │ legacy_windows = False │ │ no_color = False │ │ options = ConsoleOptions( │ │ size=ConsoleDimensions(width=188, height=20), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=188, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=20, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=188, height=20) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 188 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭── ───╮ │ Windows features available. │ │ │ │ ╭─────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=True, truecolor=True) │ │ │ ╰─────────────────────────────────────────────────╯ │ │ │ │ truecolor = True │ │ vt = True │ ╰─────────────────────────────────────────────────────╯ ╭────── Environment Variables ───────╮ │ { │ │ 'TERM': None, │ │ 'COLORTERM': 'truecolor', │ │ 'CLICOLOR': None, │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': 'vscode', │ │ 'COLUMNS': None, │ │ 'LINES': None, │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'JPY_PARENT_PID': None, │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ ╰────────────────────────────────────╯ platform="Windows"
github-actions[bot] commented 2 months ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

TomJGooding commented 2 months ago

You probably want to use align rather than justify for multi-line text:

from rich.align import Align
from rich.console import Console
from rich.text import Text

BANNER = """
'||'  '||'
 ||    ||  .... ... ... ...    ....  ... ..
 ||''''||   '|.  |   ||'  || .|...||  ||' ''
 ||    ||    '|.|    ||    | ||       ||
.||.  .||.    '|     ||...'   '|...' .||.
           .. |      ||
            ''      ''''
"""

console = Console()
banner_text = Align.center(Text(BANNER))
console.print(banner_text)
github-actions[bot] commented 2 months ago

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

sus2790 commented 2 months ago

ohh.... I didn't notice that..