You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/progress.rst
+23-1Lines changed: 23 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -118,7 +118,29 @@ To implement your own columns, extend the :class:`~rich.progress.Progress` and u
118
118
Print / log
119
119
~~~~~~~~~~~
120
120
121
-
When a progress display is running, printing or logging anything directly to the console will break the visuals. To work around this, the Progress class provides :meth:`~rich.progress.Progress.print` and :meth:`~rich.progress.Progress.log` which work the same as their counterparts on :class:`~rich.console.Console` but will move the cursor and refresh automatically -- ensure that everything renders properly.
121
+
The Progress class will create an internal Console object which you can access via ``progress.console``. If you print or log to this console, the output will be displayed *above* the progress display. Here's an example::
122
+
123
+
with Progress() as progress:
124
+
task = progress.add_task(total=10)
125
+
for job in range(10):
126
+
progress.console.print("Working on job #{job}")
127
+
run_job(job)
128
+
progress.advance(task)
129
+
130
+
If you have another Console object you want to use, pass it in to the :class:`~rich.progress.Progress` constructor. Here's an example::
131
+
132
+
from my_project import my_console
133
+
134
+
with Progress(console=my_console) as progress:
135
+
my_console.print("[bold blue]Starting work!")
136
+
do_work(progress)
137
+
138
+
139
+
Redirecting stdout / stderr
140
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
141
+
142
+
To avoid breaking the progress display visuals, Rich will redirect ``stdout`` and ``stdout`` so that you can use the builtin ``print`` statement. This feature is enabled by default, but you can disable by setting ``redirect_stdout`` or ``redirect_stderr`` to ``False``
0 commit comments