Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some numbers are automatically formatted using rich.console, how to prevent this?

Tags:

The following code

from rich.console import Console

console = Console()

console.print("ciao-16S-123")

will print the number 123 highlighted (in blue, in my terminal). This happens on many strings with numbers, what could be the problem that causes this unwanted formatting, and how to prevent it?

enter image description here

like image 583
Andrea T. Avatar asked Jul 23 '21 13:07

Andrea T.


1 Answers

As per Rich documentation, "Rich can apply styles to patterns in text which you print() or log(). With the default settings, Rich will highlight things such as numbers, strings, collections, booleans, None, and a few more exotic patterns such as file paths, URLs and UUIDs."

You can disable it like this:

console.print("ciao-16S-123", highlight=False)

You can also define a custom highlighter better suited for your needs.

like image 136
Laurent Avatar answered Nov 25 '22 11:11

Laurent