@@ -324,7 +324,7 @@ class Progress:
324324 """Renders an auto-updating progress bar(s).
325325
326326 Args:
327- console (Console, optional): Optional Console instance. Default will create own internal Console instance.
327+ console (Console, optional): Optional Console instance. Default will an internal Console instance writing to stderr .
328328 auto_refresh (bool, optional): Enable auto refresh. If disabled, you will need to call `refresh()`.
329329 refresh_per_second (int, optional): Number of times per second to refresh the progress information. Defaults to 10.
330330 speed_estimate_period: (float, optional): Period (in seconds) used to calculate the speed estimate. Defaults to 30.
@@ -544,9 +544,10 @@ def refresh(self) -> None:
544544 """Refresh (render) the progress information."""
545545 with self ._lock :
546546 self ._live_render .set_renderable (self .get_renderable ())
547- with self .console :
548- self .console .print (self ._live_render .position_cursor ())
549- self .console .print (self ._live_render )
547+ if self .console .is_terminal :
548+ with self .console :
549+ self .console .print (self ._live_render .position_cursor ())
550+ self .console .print (self ._live_render )
550551 self ._refresh_count += 1
551552
552553 def get_renderable (self ) -> RenderableType :
@@ -652,9 +653,11 @@ def print(
652653 highlight : bool = None ,
653654 ) -> None :
654655 """Print to the terminal and preserve progress display. Parameters identical to :class:`~rich.console.Console.print`."""
655- with self .console :
656- self .console .print (self ._live_render .position_cursor ())
657- self .console .print (
656+ console = self .console
657+ with console :
658+ if console .is_terminal :
659+ console .print (self ._live_render .position_cursor ())
660+ console .print (
658661 * objects ,
659662 sep = sep ,
660663 end = end ,
@@ -663,7 +666,8 @@ def print(
663666 markup = markup ,
664667 highlight = highlight ,
665668 )
666- self .console .print (self ._live_render )
669+ if console .is_terminal :
670+ console .print (self ._live_render )
667671
668672 def log (
669673 self ,
@@ -677,19 +681,22 @@ def log(
677681 _stack_offset = 1 ,
678682 ) -> None :
679683 """Log to the terminal and preserve progress display. Parameters identical to :class:`~rich.console.Console.log`."""
680- with self .console :
681- self .console .print (self ._live_render .position_cursor ())
682- self .console .log (
684+ console = self .console
685+ with console :
686+ if console .is_terminal :
687+ console .print (self ._live_render .position_cursor ())
688+ console .log (
683689 * objects ,
684690 sep = sep ,
685691 end = end ,
686692 emoji = emoji ,
687693 markup = markup ,
688694 highlight = highlight ,
689695 log_locals = log_locals ,
690- _stack_offset = _stack_offset ,
696+ _stack_offset = _stack_offset + 1 ,
691697 )
692- self .console .print (self ._live_render )
698+ if console .is_terminal :
699+ console .print (self ._live_render )
693700
694701
695702if __name__ == "__main__" : # pragma: no coverage
0 commit comments