MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / getpager

Function getpager

tools/python-3.11.9-amd64/Lib/pydoc.py:1641–1675  ·  view source on GitHub ↗

Decide what method to use for paging through text.

()

Source from the content-addressed store, hash-verified

1639 pager(text)
1640
1641def getpager():
1642 """Decide what method to use for paging through text."""
1643 if not hasattr(sys.stdin, "isatty"):
1644 return plainpager
1645 if not hasattr(sys.stdout, "isatty"):
1646 return plainpager
1647 if not sys.stdin.isatty() or not sys.stdout.isatty():
1648 return plainpager
1649 if sys.platform == "emscripten":
1650 return plainpager
1651 use_pager = os.environ.get('MANPAGER') or os.environ.get('PAGER')
1652 if use_pager:
1653 if sys.platform == 'win32': # pipes completely broken in Windows
1654 return lambda text: tempfilepager(plain(text), use_pager)
1655 elif os.environ.get('TERM') in ('dumb', 'emacs'):
1656 return lambda text: pipepager(plain(text), use_pager)
1657 else:
1658 return lambda text: pipepager(text, use_pager)
1659 if os.environ.get('TERM') in ('dumb', 'emacs'):
1660 return plainpager
1661 if sys.platform == 'win32':
1662 return lambda text: tempfilepager(plain(text), 'more <')
1663 if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
1664 return lambda text: pipepager(text, 'less')
1665
1666 import tempfile
1667 (fd, filename) = tempfile.mkstemp()
1668 os.close(fd)
1669 try:
1670 if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:
1671 return lambda text: pipepager(text, 'more')
1672 else:
1673 return ttypager
1674 finally:
1675 os.unlink(filename)
1676
1677def plain(text):
1678 """Remove boldface formatting from text."""

Callers 1

pagerFunction · 0.85

Calls 8

tempfilepagerFunction · 0.85
plainFunction · 0.85
pipepagerFunction · 0.85
systemMethod · 0.80
isattyMethod · 0.45
getMethod · 0.45
closeMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected