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] log formating wrapping line numbers #1019

Closed
b4ldr opened this issue Feb 16, 2021 · 9 comments
Closed

[BUG] log formating wrapping line numbers #1019

b4ldr opened this issue Feb 16, 2021 · 9 comments

Comments

@b4ldr
Copy link

b4ldr commented Feb 16, 2021

Describe the bug
When printing with either Console().log() or using the RichHandler() logging handler line numbers are warped and printed on the next line, see below:

image

To Reproduce

import logging
from rich.logging import RichHandler
from rich.console import Console

logging.basicConfig(level=logging.DEBUG, handlers=[RichHandler()])
logging.error('test')
logging.warning('test')
logging.info('test')
logging.debug('test')
Console().log('test')

Platform
The test report is using a the debian:buster image after running the following commands

root@6e16bf7eb9df:/# apt-get update
root@6e16bf7eb9df:/# apt-get install python3 python3-pip vim
root@6e16bf7eb9df:/# pip3 install rich
root@6e16bf7eb9df:/# python3 --version
Python 3.7.3
root@6e16bf7eb9df:/# pip3 list | grep rich
rich              9.11.0 
root@6e16bf7eb9df:/# uname -a 
Linux 6e16bf7eb9df 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux

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

python -m rich.diagnose
python -m rich._windows
pip freeze | grep rich

root@6e16bf7eb9df:/# python3 -m rich.diagnose
╭────────────────────────────────────────────────────────────── <class 'rich.console.Console'> ──────────────────────────────────────────────────────────────╮
│ A high level console interface.                                                                                                                            │
│                                                                                                                                                            │
│ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=158 ColorSystem.STANDARD>                                                                                                               │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                                                            │
│     color_system = 'standard'                                                                                                                              │
│         encoding = 'utf-8'                                                                                                                                 │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>                                                                           │
│           height = 16                                                                                                                                      │
│ is_dumb_terminal = False                                                                                                                                   │
│   is_interactive = True                                                                                                                                    │
│       is_jupyter = False                                                                                                                                   │
│      is_terminal = True                                                                                                                                    │
│   legacy_windows = False                                                                                                                                   │
│         no_color = False                                                                                                                                   │
│          options = ConsoleOptions(size=ConsoleDimensions(width=158, height=16), legacy_windows=False, min_width=1, max_width=158, is_terminal=True,        │
│                    encoding='utf-8', justify=None, overflow=None, no_wrap=False, highlight=None, height=None)                                              │
│            quiet = False                                                                                                                                   │
│           record = False                                                                                                                                   │
│         safe_box = True                                                                                                                                    │
│             size = ConsoleDimensions(width=158, height=16)                                                                                                 │
│        soft_wrap = False                                                                                                                                   │
│           stderr = False                                                                                                                                   │
│            style = None                                                                                                                                    │
│         tab_size = 8                                                                                                                                       │
│            width = 158                                                                                                                                     │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
root@6e16bf7eb9df:/# python3 -m rich._windows
platform="Linux"
WindowsConsoleFeatures(vt=False, truecolor=False)
root@6e16bf7eb9df:/# pip3 freeze | grep rich
rich==9.11.
@b4ldr b4ldr changed the title [BUG] [BUG] log formating wrapping line numbers Feb 16, 2021
@willmcgugan
Copy link
Collaborator

Did you resize the terminal after running the code?

If not, it suggests that the terminal size is incorrectly detected. Do you have a COLUMNS env var set?

What do you get when you run this:

import shutil
shutil.get_terminal_size()

And does it match your terminal size?

@b4ldr
Copy link
Author

b4ldr commented Feb 17, 2021

Thanks for the response

Did you resize the terminal after running the code?

No, i have also tested it in a fresh window and using both konsole and yakuake and get the same issue (also tried sh, bash and zsh). however using a real tty (i.e. ctrl + alt + f1) works as expected

If not, it suggests that the terminal size is incorrectly detected. Do you have a COLUMNS env var set?

yes

$ echo $COLUMNS 
88

What do you get when you run this:

import shutil
shutil.get_terminal_size()

os.terminal_size(columns=88, lines=29)

And does it match your terminal size?

yes

$ stty size
29 88

@willmcgugan
Copy link
Collaborator

I think Rich may not be respecting the COLUMNS env var. I'll have a fix in the next minor version.

@b4ldr
Copy link
Author

b4ldr commented Feb 17, 2021

please ping if you want a tester

@willmcgugan
Copy link
Collaborator

Just notice something. The filenames in the right hand column have superfluous backslashes.

Those are terminal links, which are a relatively new addition to terminals. If terminals follow the spec precisely then the links won't render if not supported by the terminal, but it looks like some of the characters are. I'm fairly certain that's a bug in the terminal app.

As a workaround, you can add enable_link_path=False to RichHandler to disable those links.

@b4ldr
Copy link
Author

b4ldr commented Feb 19, 2021

Ahh awesome that worked a treat

import logging
import shutil
from rich.logging import RichHandler
from rich.console import Console

logging.basicConfig(level=logging.DEBUG, handlers=[RichHandler(enable_link_path=False)])
logging.error('test')
logging.warning('test')
logging.info('test')
logging.debug('test')
Console().print(shutil.get_terminal_size())

image

Im unsure if this is a bug or expected if the latter please close the issues other wise happy to help test anything if needed, thanks

@willmcgugan
Copy link
Collaborator

It's a bug in your terminal software I'm afraid. You could try raising an issue with that project.

@b4ldr
Copy link
Author

b4ldr commented Feb 19, 2021

Thanks i did some digging for otheres who may hit this issue:

As far as i can tell The feature was added to konsole in v20.11.80 (all though i couldn;t find a decent changelog so could have been earlier). im using buster and 18.04.0 so this is to be expected. As to yakuake afaik this uses konsol as the emulator

Also found this gist which seems usefull to add here

@perone
Copy link

perone commented Jul 8, 2023

I'm getting this same error with MacOS native terminal and rich==13.4.2, line numbers are being wrapped. It seems to be related when I use emoji in the logging.

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

3 participants