code: def print_with_pager(output):
      
      if sys.stdout.isatty():
          try:
              pager = subprocess.Popen(
                  ['less', '-F', '-r', '-S', '-X', '-K'],
                  stdin=subprocess.PIPE, stdout=sys.stdout)
          except subprocess.CalledProcessError:
              # Don't use the pager since starting it has failed.
              print(output)
              return
          else:
              pager.stdin.write(output.encode('utf-8'))
              pager.stdin.close()
              pager.wait()
      else:
          # Output directly to stdout since not in tty.
          print(output)
docs: Print the output to `stdout` using less when in a tty.