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] One trailing newline ignored by rich.print in some cases #178

Closed
mportesdev opened this issue Jul 26, 2020 · 6 comments
Closed

[BUG] One trailing newline ignored by rich.print in some cases #178

mportesdev opened this issue Jul 26, 2020 · 6 comments
Labels
accepted Task was accepted bug Something isn't working

Comments

@mportesdev
Copy link

Hi, thanks for this great library.

Not sure if this is expected behavior or a bug. In certain cases, rich.print handles newlines in a slightly different manner than the print built-in.

Example:

>>> for i in range(3): print('Hey' + '\n' * i)
... 
Hey
Hey

Hey


>>> from rich import print
>>> for i in range(3): print('Hey' + '\n' * i)
... 
Hey
Hey
Hey

>>> 

Apparently, when the printed string contains at least one trailing newline (i.e. when i == 1 or i == 2), one newline is ignored by rich.print.

A screenshot of a similar example:
rich

(rich 3.3.2, Python 3.8.0, GNOME Terminal 3.18.3 on Linux Mint 18.2 64-bit)

@mportesdev
Copy link
Author

Reproduced with:

rich 4.0.0 on Python 3.8.0
rich 4.0.0 on Python 3.8.3
rich 4.0.0 on Python 3.9.0b5+

@willmcgugan willmcgugan added accepted Task was accepted bug Something isn't working and removed Needs triage labels Jul 26, 2020
@willmcgugan willmcgugan mentioned this issue Jul 26, 2020
9 tasks
@mportesdev
Copy link
Author

Reproduced with:
rich 4.1.0 on Python 3.7.5 for Windows
rich 4.1.0 on Python 3.8.0 for Windows

@willmcgugan
Copy link
Collaborator

Please try v4.2.0

@mportesdev
Copy link
Author

Looks good.

rich4 2 0_py3 7 5

rich4 2 0_py3 8 0

Thanks!

@mportesdev
Copy link
Author

Btw I don't know if you use doctest in your project, but this kind of output in the interactive interpreter can be easily tested with it, e.g.:

r"""
Test examples for `rich.print`:

    >>> from rich import print
    >>> for i in range(3): print('Hey' + '\n' * i)
    ...
    Hey
    Hey
    <BLANKLINE>
    Hey
    <BLANKLINE>
    <BLANKLINE>
    >>> print('[red]Hey[/]')
    Hey
    >>> print('[red]Hey[/]\n')
    Hey
    <BLANKLINE>
    >>> print('[red]Hey[/]\n\n')
    Hey
    <BLANKLINE>
    <BLANKLINE>

"""

import doctest

if __name__ == '__main__':
    doctest.testmod()

@willmcgugan
Copy link
Collaborator

Might be useful occasionally, but it would be difficult to test control codes and differences across platforms with doctests.

There are tests now for this case btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Task was accepted bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants