Skip to content

Commit 67fad4b

Browse files
committed
Add a test case for typer.enable_rich(<bool>)
Also, add a paragraph to the documentation.
1 parent 6a4ba06 commit 67fad4b

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

docs/tutorial/printing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ In general, **Typer** tends to be the entry point to your program, taking the fi
140140

141141
The best results for your command line application would be achieved combining both **Typer** and **Rich**.
142142

143+
### If you don't want to use Rich formated output
144+
145+
In case you'd rather like to use the simple text ouput, but need **Rich** to be installed in your environment for any other reason, you can disable the use of **Rich** by **Typer** with the following call:`typer.enable_rich(False)`. This is a global switch affecting all instances of `typer.Typer()`.
146+
147+
143148
## "Standard Output" and "Standard Error"
144149

145150
The way printing works underneath is that the **operating system** (Linux, Windows, macOS) treats what we print as if our CLI program was **writing text** to a "**virtual file**" called "**standard output**".

tests/assets/enable_rich.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import typer
2+
3+
typer.enable_rich(False)
4+
5+
app = typer.Typer()
6+
7+
8+
@app.command()
9+
def main(arg: str): # pragma: no cover
10+
pass
11+
12+
13+
if __name__ == "__main__":
14+
app()

tests/test_enable_rich.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import subprocess
2+
import sys
3+
from pathlib import Path
4+
5+
6+
def test_custom_prog_name():
7+
file_path = Path(__file__).parent / "assets/enable_rich.py"
8+
result = subprocess.run(
9+
[sys.executable, "-m", "coverage", "run", str(file_path), "--help"],
10+
stdout=subprocess.PIPE,
11+
stderr=subprocess.PIPE,
12+
encoding="utf-8",
13+
)
14+
assert "Arguments:" in result.stdout # as opposed to 'Arguments' without ':'
15+
# like in the Rich Panels

0 commit comments

Comments
 (0)