question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

[BUG] `console.Console.pager` not respecting `PAGER`

See original GitHub issue

Describe the bug Richโ€™s build in pager does not seem to respect PAGER on my machine, and behaves inconsistenly compared to using less manually.

To Reproduce

"""rich_pager_debug.py"""
from rich import console

rich_console = console.Console(color_system="standard")
text = "[red]Hello world![/red]\n"
with rich_console.pager(styles=True):
    rich_console.print(text)

No matter what I have set as PAGER, I cannot get rich to properly display colors.

โฏ PAGER=less python rich_pager_debug.py
31mHello world!0m

โฏ PAGER='less -r' python rich_pager_debug.py
31mHello world!0m

โฏ PAGER='less -R' python rich_pager_debug.py
31mHello world!0m

However, manually calling less results in colors as expected.

โฏ python rich_pager_debug.py | less -R
Screen Shot 2021-11-13 at 8 34 02 PM

Platform

  • macOS 11.6
  • iTerm2
  • macOS Terminal
  • less 590
  • less 487

Diagnose

Diagnosis
python -m rich.diagnose

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ <class 'rich.console.Console'> โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ A high level console interface.                                                  โ”‚
โ”‚                                                                                  โ”‚
โ”‚ โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚
โ”‚ โ”‚ <console width=250 ColorSystem.TRUECOLOR>                                    โ”‚ โ”‚
โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ โ”‚
โ”‚                                                                                  โ”‚
โ”‚     color_system = 'truecolor'                                                   โ”‚
โ”‚         encoding = 'utf-8'                                                       โ”‚
โ”‚             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> โ”‚
โ”‚           height = 70                                                            โ”‚
โ”‚    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=250, height=70),             โ”‚
โ”‚                        legacy_windows=False,                                     โ”‚
โ”‚                        min_width=1,                                              โ”‚
โ”‚                        max_width=250,                                            โ”‚
โ”‚                        is_terminal=True,                                         โ”‚
โ”‚                        encoding='utf-8',                                         โ”‚
โ”‚                        max_height=70,                                            โ”‚
โ”‚                        justify=None,                                             โ”‚
โ”‚                        overflow=None,                                            โ”‚
โ”‚                        no_wrap=False,                                            โ”‚
โ”‚                        highlight=None,                                           โ”‚
โ”‚                        markup=None,                                              โ”‚
โ”‚                        height=None                                               โ”‚
โ”‚                    )                                                             โ”‚
โ”‚            quiet = False                                                         โ”‚
โ”‚           record = False                                                         โ”‚
โ”‚         safe_box = True                                                          โ”‚
โ”‚             size = ConsoleDimensions(width=250, height=70)                       โ”‚
โ”‚        soft_wrap = False                                                         โ”‚
โ”‚           stderr = False                                                         โ”‚
โ”‚            style = None                                                          โ”‚
โ”‚         tab_size = 8                                                             โ”‚
โ”‚            width = 250                                                           โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

python -m rich._windows

platform="Darwin"
WindowsConsoleFeatures(vt=False, truecolor=False)

python -m pip freeze | grep rich

rich @ file:///Users/pawlu/Library/Caches/pypoetry/artifacts/3a/dc/af/ff80071ba5431c81f40a3c922ff1585e7a3060b5549088275f57ee6975/rich-10.12.0-py3-none-any.whl

As always, appreicate the work on the library and continued development!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
willmcgugancommented, Jan 27, 2022

@paw-lu Thanks for doing the investigation. Because weโ€™re using pydoc, thereโ€™s not much we can do. Weโ€™ve documented the behaviour for now. In the future we might have a better solution.

1reaction
willmcgugancommented, Nov 16, 2021

That actually works for me. I can see colour with both methods. Rich uses the stdlib pydoc module for the default paging, so it should use the same mechanism if you did help() from the REPL or pydoc sys from the command line.

Iโ€™m on a similar platform to you, so Iโ€™m not sure what could be different.

Can you print os.environ in your test code, just to check its not env var related.

Read more comments on GitHub >

github_iconTop Results From Across the Web

invoke a pager to display results ยท Issue #86 ยท BurntSushi/ripgrep
Would it make sense to invoke a pager automatically if the tool detects that its output is not piped?
Read more >
Ubuntu Manpage: console-log.conf - Main configuration file for ...
This mechanism can be used in any pager extension called from the logpager script. CONFIGURING THE LESS PAGER. For configuring the less pager,...
Read more >
bug #52556: Octave stops writing to console on Windows 7
While the following command. printf("รครถรผ\n");. does not stop octave from writing to console, the same string in a function documentationย ...
Read more >
How do I prevent 'git diff' from using a pager? - Stack Overflow
--no-pager to Git will tell it to not use a pager. Passing the option -F to less will tell it to not page...
Read more >
Getting on the same page with Paging 3
You told us that the Paging 2.0 API was not enough - that you wanted easier ... The following examples will be in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found