Skip to content

Commit 8745ee5

Browse files
committed
progress docs
1 parent 56227ab commit 8745ee5

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

docs/source/progress.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ If the :class:`~rich.progress.Progress` class doesn't offer exactly what you nee
212212
Reading from a file
213213
~~~~~~~~~~~~~~~~~~~
214214

215-
Rich provides an easy way to generate a progress bar for reading a file. If you call :func:`~rich.progress.open` it will return a context manager which displays a progress bar while you read.
215+
Rich provides an easy way to generate a progress bar for reading a file. If you call :func:`~rich.progress.open` it will return a context manager which displays a progress bar while you read. This is particularly useful when you can't easily modify the code that does the reading.
216216

217217
The following example shows how we might show progress for reading a JSON file::
218218

@@ -223,7 +223,7 @@ The following example shows how we might show progress for reading a JSON file::
223223
data = json.load(file)
224224
print(data)
225225

226-
If you already have a file object, you can call :func:`~rich.progress.wrap_file` which returns a context manager that wraps your file so that it generates a progress bar. If you use this function you will need to set the number of bytes or characters you expect to read.
226+
If you already have a file object, you can call :func:`~rich.progress.wrap_file` which returns a context manager that wraps your file so that it displays a progress bar. If you use this function you will need to set the number of bytes or characters you expect to read.
227227

228228
Here's an example that reads a url from the internet::
229229

examples/file_progress.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from time import sleep
2+
from urllib.request import urlopen
3+
4+
from rich.progress import wrap_file
5+
6+
# Read a URL with urlopen
7+
response = urlopen("https://www.textualize.io")
8+
# Get the size from the headers
9+
size = int(response.headers["Content-Length"])
10+
11+
# Wrap the response so that it update progress
12+
13+
with wrap_file(response, size) as file:
14+
for line in file:
15+
print(line.decode("utf-8"), end="")
16+
sleep(0.1)

examples/save_table_svg.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Demonstrates how to export a SVG
3+
"""
4+
5+
from rich.console import Console
6+
from rich.table import Table
7+
8+
table = Table(title="Star Wars Movies")
9+
10+
table.add_column("Released", style="cyan", no_wrap=True)
11+
table.add_column("Title", style="magenta")
12+
table.add_column("Box Office", justify="right", style="green")
13+
14+
table.add_row("Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$952,110,690")
15+
table.add_row("May 25, 2018", "Solo: A Star Wars Story", "$393,151,347")
16+
table.add_row("Dec 15, 2017", "Star Wars Ep. V111: The Last Jedi", "$1,332,539,889")
17+
table.add_row("Dec 16, 2016", "Rogue One: A Star Wars Story", "$1,332,439,889")
18+
19+
console = Console(record=True)
20+
console.print(table, justify="center")
21+
console.save_svg("table.svg", title="save_table_svg.py")
22+
23+
import os
24+
import webbrowser
25+
26+
webbrowser.open(f"file://{os.path.abspath('table.svg')}")

rich/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,7 @@ def export_svg(
23502350
)
23512351
)
23522352

2353-
fragments = []
2353+
fragments: List[str] = []
23542354
theme_foreground_color = _theme.foreground_color.hex
23552355
theme_background_color = _theme.background_color.hex
23562356

0 commit comments

Comments
 (0)