code: def _tempfilepager(generator, cmd, color):
      """Page through text by invoking a program on a temporary file."""
      import tempfile
  
      filename = tempfile.mktemp()
      # TODO: This never terminates if the passed generator never terminates.
      text = "".join(generator)
      if not color:
          text = strip_ansi(text)
      encoding = get_best_encoding(sys.stdout)
      with open_stream(filename, "wb")[0] as f:
          f.write(text.encode(encoding))
      try:
          os.system('{} "{}"'.format(cmd, filename))
      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 4 for calling a global function with example usage: _tempfilepager(generator, cmd, color) without return types