Skip to content

Commit

Permalink
Add a test case for typer.enable_rich(<bool>)
Browse files Browse the repository at this point in the history
Also, add a paragraph to the documentation.
  • Loading branch information
JacobKochems committed Aug 2, 2023
1 parent 6a4ba06 commit 67fad4b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/tutorial/printing.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ In general, **Typer** tends to be the entry point to your program, taking the fi

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

### If you don't want to use Rich formated output

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()`.


## "Standard Output" and "Standard Error"

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**".
Expand Down
14 changes: 14 additions & 0 deletions tests/assets/enable_rich.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import typer

typer.enable_rich(False)

app = typer.Typer()


@app.command()
def main(arg: str): # pragma: no cover
pass


if __name__ == "__main__":
app()
15 changes: 15 additions & 0 deletions tests/test_enable_rich.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import subprocess
import sys
from pathlib import Path


def test_custom_prog_name():
file_path = Path(__file__).parent / "assets/enable_rich.py"
result = subprocess.run(
[sys.executable, "-m", "coverage", "run", str(file_path), "--help"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
)
assert "Arguments:" in result.stdout # as opposed to 'Arguments' without ':'
# like in the Rich Panels

0 comments on commit 67fad4b

Please sign in to comment.