pager.py 838 B

12345678910111213141516171819202122232425262728293031323334
  1. from abc import ABC, abstractmethod
  2. from typing import Any, Callable
  3. class Pager(ABC):
  4. """Base class for a pager."""
  5. @abstractmethod
  6. def show(self, content: str) -> None:
  7. """Show content in pager.
  8. Args:
  9. content (str): Content to be displayed.
  10. """
  11. class SystemPager(Pager):
  12. """Uses the pager installed on the system."""
  13. def _pager(self, content: str) -> Any: #  pragma: no cover
  14. return __import__("pydoc").pager(content)
  15. def show(self, content: str) -> None:
  16. """Use the same pager used by pydoc."""
  17. self._pager(content)
  18. if __name__ == "__main__": # pragma: no cover
  19. from .__main__ import make_test_card
  20. from .console import Console
  21. console = Console()
  22. with console.pager(styles=True):
  23. console.print(make_test_card())