code: def pager(generator, color=None):
      """Decide what method to use for paging through text."""
      stdout = _default_text_stdout()
      if not isatty(sys.stdin) or not isatty(stdout):
          return _nullpager(stdout, generator, color)
      pager_cmd = (os.environ.get("PAGER", None) or "").strip()
      if pager_cmd:
          if WIN:
              return _tempfilepager(generator, pager_cmd, color)
          return _pipepager(generator, pager_cmd, color)
      if os.environ.get("TERM") in ("dumb", "emacs"):
          return _nullpager(stdout, generator, color)
      if WIN or sys.platform.startswith("os2"):
          return _tempfilepager(generator, "more <", color)
      if hasattr(os, "system") and os.system("(less) 2>/dev/null") == 0:
          return _pipepager(generator, "less", color)
  
      import tempfile
  
      fd, filename = tempfile.mkstemp()
      os.close(fd)
      try:
          if (
              hasattr(os, "system")
              and os.system('more "{}"'.format(filename)) == 0
          ):
              return _pipepager(generator, "more", color)
          return _nullpager(stdout, generator, color)
      finally:
          os.unlink(filename)
  
imports: import contextlib
  import math
  import os
  import sys
  import time
  from ._compat import _default_text_stdout
  from ._compat import CYGWIN
  from ._compat import get_best_encoding
  from ._compat import int_types
  from ._compat import isatty
  from ._compat import open_stream
  from ._compat import range_type
  from ._compat import strip_ansi
  from ._compat import term_len
  from ._compat import WIN
  from .exceptions import ClickException
  from .utils import echo
label_desc: Use image node_id 2 for calling a global function with example usage: pager(generator, color) and returns: _nullpager, _pipepager, _nullpager, _tempfilepager, _pipepager, _nullpager, _tempfilepager, _pipepager