@@ -1403,49 +1403,43 @@ def ppaged(self, msg: Any, *, end: str = '\n', chop: bool = False, dest: Optiona
1403
1403
1404
1404
WARNING: On Windows, the text always wraps regardless of what the chop argument is set to
1405
1405
"""
1406
- # msg can be any type, so convert to string before checking if it's blank
1407
- msg_str = str (msg )
1408
1406
dest = self .stdout if dest is None else dest
1409
1407
1410
- # Consider None to be no data to print
1411
- if msg is None or msg_str == '' :
1412
- return
1413
-
1414
- try :
1415
- import subprocess
1408
+ # Attempt to detect if we are not running within a fully functional terminal.
1409
+ # Don't try to use the pager when being run by a continuous integration system like Jenkins + pexpect.
1410
+ functional_terminal = False
1416
1411
1417
- # Attempt to detect if we are not running within a fully functional terminal.
1418
- # Don't try to use the pager when being run by a continuous integration system like Jenkins + pexpect.
1419
- functional_terminal = False
1412
+ if self . stdin . isatty () and dest . isatty ():
1413
+ if sys . platform . startswith ( 'win' ) or os . environ . get ( 'TERM' ) is not None :
1414
+ functional_terminal = True
1420
1415
1421
- if self .stdin .isatty () and dest .isatty ():
1422
- if sys .platform .startswith ('win' ) or os .environ .get ('TERM' ) is not None :
1423
- functional_terminal = True
1416
+ # Don't attempt to use a pager that can block if redirecting or running a script (either text or Python).
1417
+ # Also only attempt to use a pager if actually running in a real fully functional terminal.
1418
+ if functional_terminal and not self ._redirecting and not self .in_pyscript () and not self .in_script ():
1419
+ final_msg = f"{ msg } { end } "
1420
+ if ansi .allow_style == ansi .AllowStyle .NEVER :
1421
+ final_msg = ansi .strip_style (final_msg )
1424
1422
1425
- # Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
1426
- # Also only attempt to use a pager if actually running in a real fully functional terminal
1427
- if functional_terminal and not self ._redirecting and not self .in_pyscript () and not self .in_script ():
1428
- if ansi .allow_style == ansi .AllowStyle .NEVER :
1429
- msg_str = ansi .strip_style (msg_str )
1430
- msg_str += end
1431
-
1432
- pager = self .pager
1433
- if chop :
1434
- pager = self .pager_chop
1423
+ pager = self .pager
1424
+ if chop :
1425
+ pager = self .pager_chop
1435
1426
1427
+ try :
1436
1428
# Prevent KeyboardInterrupts while in the pager. The pager application will
1437
1429
# still receive the SIGINT since it is in the same process group as us.
1438
1430
with self .sigint_protection :
1431
+ import subprocess
1432
+
1439
1433
pipe_proc = subprocess .Popen (pager , shell = True , stdin = subprocess .PIPE , stdout = dest )
1440
- pipe_proc .communicate (msg_str .encode ('utf-8' , 'replace' ))
1441
- else :
1442
- ansi . style_aware_write ( dest , f' { msg_str } { end } ' )
1443
- except BrokenPipeError :
1444
- # This occurs if a command's output is being piped to another process and that process closes before the
1445
- # command is finished. If you would like your application to print a warning message, then set the
1446
- # broken_pipe_warning attribute to the message you want printed.`
1447
- if self . broken_pipe_warning :
1448
- sys . stderr . write ( self . broken_pipe_warning )
1434
+ pipe_proc .communicate (final_msg .encode ('utf-8' , 'replace' ))
1435
+ except BrokenPipeError :
1436
+ # This occurs if a command's output is being piped to another process and that process closes before the
1437
+ # command is finished. If you would like your application to print a warning message, then set the
1438
+ # broken_pipe_warning attribute to the message you want printed.`
1439
+ if self . broken_pipe_warning :
1440
+ sys . stderr . write ( self . broken_pipe_warning )
1441
+ else :
1442
+ self . print_to ( dest , msg , end = end , paged = False )
1449
1443
1450
1444
# ----- Methods related to tab completion -----
1451
1445
0 commit comments