@@ -502,23 +502,26 @@ def pexcept(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> Non
502502 # Set apply_style to False since style has already been applied
503503 self .perror (final_msg , end = end , apply_style = False )
504504
505- def pfeedback (self , msg : str ) -> None :
505+ def pfeedback (self , msg : Any , * , end : str = ' \n ' ) -> None :
506506 """For printing nonessential feedback. Can be silenced with `quiet`.
507- Inclusion in redirected output is controlled by `feedback_to_output`."""
507+ Inclusion in redirected output is controlled by `feedback_to_output`.
508+ :param msg: message to print (anything convertible to a str with '{}'.format() is OK)
509+ :param end: string appended after the end of the message, default a newline
510+ """
508511 if not self .quiet :
509512 if self .feedback_to_output :
510- self .poutput (msg )
513+ self .poutput (msg , end = end )
511514 else :
512- ansi . ansi_aware_write ( sys . stderr , "{} \n " . format ( msg ) )
515+ self . perror ( msg , end = end , apply_style = False )
513516
514- def ppaged (self , msg : str , end : str = '\n ' , chop : bool = False ) -> None :
517+ def ppaged (self , msg : Any , * , end : str = '\n ' , chop : bool = False ) -> None :
515518 """Print output using a pager if it would go off screen and stdout isn't currently being redirected.
516519
517520 Never uses a pager inside of a script (Python or text) or when output is being redirected or piped or when
518521 stdout or stdin are not a fully functional terminal.
519522
520523 :param msg: message to print to current stdout (anything convertible to a str with '{}'.format() is OK)
521- :param end: string appended after the end of the message if not already present , default a newline
524+ :param end: string appended after the end of the message, default a newline
522525 :param chop: True -> causes lines longer than the screen width to be chopped (truncated) rather than wrapped
523526 - truncated text is still accessible by scrolling with the right & left arrow keys
524527 - chopping is ideal for displaying wide tabular data as is done in utilities like pgcli
@@ -528,43 +531,43 @@ def ppaged(self, msg: str, end: str = '\n', chop: bool = False) -> None:
528531 WARNING: On Windows, the text always wraps regardless of what the chop argument is set to
529532 """
530533 import subprocess
531- if msg is not None and msg != '' :
532- try :
533- msg_str = '{}' . format ( msg )
534- if not msg_str . endswith ( end ) :
535- msg_str += end
536-
537- # Attempt to detect if we are not running within a fully functional terminal.
538- # Don't try to use the pager when being run by a continuous integration system like Jenkins + pexpect.
539- functional_terminal = False
540-
541- if self .stdin .isatty () and self .stdout .isatty ():
542- if sys .platform .startswith ('win' ) or os .environ .get ('TERM' ) is not None :
543- functional_terminal = True
544-
545- # Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
546- # Also only attempt to use a pager if actually running in a real fully functional terminal
547- if functional_terminal and not self ._redirecting and not self .in_pyscript () and not self .in_script ():
548- if ansi .allow_ansi .lower () == ansi .ANSI_NEVER .lower ():
549- msg_str = ansi .strip_ansi (msg_str )
550-
551- pager = self .pager
552- if chop :
553- pager = self .pager_chop
554-
555- # Prevent KeyboardInterrupts while in the pager. The pager application will
556- # still receive the SIGINT since it is in the same process group as us.
557- with self .sigint_protection :
558- pipe_proc = subprocess .Popen (pager , shell = True , stdin = subprocess .PIPE )
559- pipe_proc .communicate (msg_str .encode ('utf-8' , 'replace' ))
560- else :
561- self .poutput (msg_str , end = '' )
562- except BrokenPipeError :
563- # This occurs if a command's output is being piped to another process and that process closes before the
564- # command is finished. If you would like your application to print a warning message, then set the
565- # broken_pipe_warning attribute to the message you want printed.`
566- if self .broken_pipe_warning :
567- sys .stderr .write (self .broken_pipe_warning )
534+ if not msg :
535+ return
536+
537+ try :
538+ msg_str = '{}{}' . format ( msg , end )
539+
540+ # Attempt to detect if we are not running within a fully functional terminal.
541+ # Don't try to use the pager when being run by a continuous integration system like Jenkins + pexpect.
542+ functional_terminal = False
543+
544+ if self .stdin .isatty () and self .stdout .isatty ():
545+ if sys .platform .startswith ('win' ) or os .environ .get ('TERM' ) is not None :
546+ functional_terminal = True
547+
548+ # Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
549+ # Also only attempt to use a pager if actually running in a real fully functional terminal
550+ if functional_terminal and not self ._redirecting and not self .in_pyscript () and not self .in_script ():
551+ if ansi .allow_ansi .lower () == ansi .ANSI_NEVER .lower ():
552+ msg_str = ansi .strip_ansi (msg_str )
553+
554+ pager = self .pager
555+ if chop :
556+ pager = self .pager_chop
557+
558+ # Prevent KeyboardInterrupts while in the pager. The pager application will
559+ # still receive the SIGINT since it is in the same process group as us.
560+ with self .sigint_protection :
561+ pipe_proc = subprocess .Popen (pager , shell = True , stdin = subprocess .PIPE )
562+ pipe_proc .communicate (msg_str .encode ('utf-8' , 'replace' ))
563+ else :
564+ self .poutput (msg_str , end = '' )
565+ except BrokenPipeError :
566+ # This occurs if a command's output is being piped to another process and that process closes before the
567+ # command is finished. If you would like your application to print a warning message, then set the
568+ # broken_pipe_warning attribute to the message you want printed.`
569+ if self .broken_pipe_warning :
570+ sys .stderr .write (self .broken_pipe_warning )
568571
569572 # ----- Methods related to tab completion -----
570573
0 commit comments