diff --git a/rich/pager.py b/rich/pager.py index 06f51372..a17b6bc3 100644 --- a/rich/pager.py +++ b/rich/pager.py @@ -17,9 +17,11 @@ class Pager(ABC): class SystemPager(Pager): """Uses the pager installed on the system.""" + _pager = pydoc.pager + def show(self, content: str) -> None: """Use the same pager used by pydoc.""" - pydoc.pager(content) + self._pager(content) if __name__ == "__main__": # pragma: no cover diff --git a/tests/test_console.py b/tests/test_console.py index 3df8e7ce..153658d1 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -2,12 +2,14 @@ import io import os import sys import tempfile +from threading import setprofile import pytest from rich.color import ColorSystem from rich.console import CaptureError, Console, ConsoleOptions from rich import errors +from rich.pager import SystemPager from rich.panel import Panel from rich.style import Style @@ -346,3 +348,21 @@ def test_bell() -> None: console.begin_capture() console.bell() assert console.end_capture() == "\x07" + + +def test_pager() -> None: + console = Console() + + pager_called = False + + def mock_pager(content: str) -> None: + nonlocal pager_called + pager_called = True + + pager = SystemPager() + pager._pager = dummy_pager + + with console.pager(pager): + console.print("Hello World") + + assert pager_called \ No newline at end of file