def _pipepager(text, cmd, color):
import subprocess<EOL>env = dict(os.environ)<EOL>cmd_detail = cmd.rsplit('<STR_LIT:/>', <NUM_LIT:1>)[-<NUM_LIT:1>].split()<EOL>if color is None and cmd_detail[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>less_flags = os.environ.get('<STR_LIT>', '<STR_LIT>') + '<STR_LIT:U+0020>'.join(cmd_detail[<NUM_LIT:1>:])<EOL>if not less_flags:<EOL><INDENT>env['<STR_LIT>'] = '<STR_LIT>'<EOL>color = True<EOL><DEDENT>elif '<STR_LIT:r>' in less_flags or '<STR_LIT:R>' in less_flags:<EOL><INDENT>color = True<EOL><DEDENT><DEDENT>if not color:<EOL><INDENT>text = strip_ansi(text)<EOL><DEDENT>c = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,<EOL>env=env)<EOL>encoding = get_best_encoding(c.stdin)<EOL>try:<EOL><INDENT>c.stdin.write(text.encode(encoding, '<STR_LIT:replace>'))<EOL>c.stdin.close()<EOL><DEDENT>except (IOError, KeyboardInterrupt):<EOL><INDENT>pass<EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>c.wait()<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>
Page through text by feeding it to another program.  Invoking a
    pager through this might support colors.