Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] multibyte characters in Progressbar TextColumn mess up render #3254

Closed
2 tasks
glensc opened this issue Jan 8, 2024 · 11 comments
Closed
2 tasks

[BUG] multibyte characters in Progressbar TextColumn mess up render #3254

glensc opened this issue Jan 8, 2024 · 11 comments

Comments

@glensc
Copy link
Contributor

glensc commented Jan 8, 2024

Describe the bug

So, I have a Progressbar:

            TextColumn("{task.fields[play_state]}  [bold blue]{task.description}", justify="left"),

and I put play_state an unicode character, for example "⏸️" (2 bytes), it messes up display:

image

also, if I put that character literally to TextColumn, display is still messed up:

            TextColumn("⏸️ [bold blue]{task.description}", justify="left"),

but progressbar is okay if I put some other character there "▶" (1 byte)

image

more complete Progress creation:

        progress = Progress(
            TextColumn("{task.fields[play_state]} [bold blue]{task.description}", justify="left"),
            BarColumn(bar_width=None),
            "[progress.percentage]{task.percentage:>3.1f}%",
            "•",
            TimeRemainingColumn(),
            console=console,
        )
        progress.start()
        progress.update(task_id, completed=progress, play_state="⏸️")

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.

If you're using Rich in a terminal:


╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=142 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 41                                                            │
│    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=142, height=41),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=142,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=41,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=142, height=41)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 142                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-kitty',         │
│     'COLORTERM': 'truecolor',      │
│     'CLICOLOR': None,              │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': None,        │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
Copy link

github-actions bot commented Jan 8, 2024

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

@glensc glensc changed the title [BUG] multibyte characters from task.fields mess up display [BUG] multibyte characters in Progressbar TextColumn mess up render Jan 8, 2024
@glensc glensc changed the title [BUG] multibyte characters in Progressbar TextColumn mess up render [BUG] long multibyte characters in Progressbar TextColumn mess up render Jan 8, 2024
@glensc glensc changed the title [BUG] long multibyte characters in Progressbar TextColumn mess up render [BUG] multibyte characters in Progressbar TextColumn mess up render Jan 8, 2024
@glensc
Copy link
Contributor Author

glensc commented Jan 8, 2024

Seems, to be an issue with Kitty terminal on macOS. iTerm2 works fine.

Also, python -m rich.spinner is messed up with Kitty but ok with iTerm2.

@glensc glensc closed this as completed Jan 8, 2024
Copy link

github-actions bot commented Jan 8, 2024

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

@glensc
Copy link
Contributor Author

glensc commented Jan 8, 2024

But with given Progressbar, how could I avoid the problem? I would make the whole progress shorter by some bytes, but that bar_width=None applies just to the TextColumn...

@glensc glensc reopened this Jan 8, 2024
@willmcgugan
Copy link
Collaborator

There is no way for Rich to know how wide some characters will render on any given terminal. This mostly effects emoji. There's no real solution to this, other than avoid the characters that are problematic.

@glensc
Copy link
Contributor Author

glensc commented Jan 8, 2024

@willmcgugan but I know I will be inserting 2-byte character there. how can I tell whole progressbar to be 1 byte (or, say 6 bytes to be sure) shorter?

btw, there's some wcwidth project, it doesn't help?

@willmcgugan
Copy link
Collaborator

The number of bytes in a codepoint has little to do with the width it will be rendered as. That is defined by the Unicode database, but different terminals use different versions of that database.

We use the same data as wcwidth.

@glensc
Copy link
Contributor Author

glensc commented Jan 8, 2024

so. the question again. can I make the progressbar not so wide as whole terminal:

        progress = Progress(
            TextColumn("{task.fields[play_state]} [bold blue]{task.description}", justify="left"),
            BarColumn(bar_width=None),
            "[progress.percentage]{task.percentage:>3.1f}%",
            "•",
            TimeRemainingColumn(),
            console=console,
        )

where do I put console.width - 6 to make it 6 cells narrower? can the progressbar be boxed somehow?

@glensc
Copy link
Contributor Author

glensc commented Jan 8, 2024

Solved with Panel and Live:

Panel accepts width parameter, Live is needed to keep it rendered. Seems Progress internally uses Live, so didn't use Live before.

@glensc glensc closed this as completed Jan 8, 2024
Copy link

github-actions bot commented Jan 8, 2024

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

@glensc
Copy link
Contributor Author

glensc commented Jan 11, 2024

@willmcgugan do you have an answer to my question:

How can I make the progressbar not so wide as whole terminal?

and have you checked my implementation? comments on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants