#NEWLINE# def show_pager( formatted_text ) : #NEWLINE# #INDENT# "\n    Print a large text to the terminal using a pager.\n\n    :param formatted_text: The text to print to the terminal (a string).\n\n    The use of a pager helps to avoid the wall of text effect where the user\n    has to scroll up to see where the output began (not very user friendly).\n\n    If :data:`sys.stdout` is not connected to a terminal (see\n    :func:`connected_to_terminal()`) then the text is printed directly without\n    invoking a pager.\n\n    If the given text contains ANSI escape sequences the command ``less\n    --RAW-CONTROL-CHARS`` is used, otherwise ``$PAGER`` is used (if ``$PAGER``\n    isn't set the command ``less`` is used).\n    " #NEWLINE# if connected_to_terminal ( sys . stdout ) : #NEWLINE# #INDENT# if ( ANSI_CSI in formatted_text ) : #NEWLINE# #INDENT# pager_command = [ 'less' , '--RAW-CONTROL-CHARS' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pager_command = [ os . environ . get ( 'PAGER' , 'less' ) ] #NEWLINE# #UNINDENT# pager = subprocess . Popen ( pager_command , stdin = subprocess . PIPE ) #NEWLINE# pager . communicate ( input = formatted_text ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( formatted_text )