The Rich API make it extremely easy to add colored text (up to 16.7million colors) and styles (bold, italic, underline etc.) to your script or application. Rich can also render pretty tables, markdown and source code with syntax highlighting.
The first step to using the rich console is to import and construct the `Console` object.
```python
from rich.console import Console
console = Console()
```
Most applications will require one `Console` instance. The easiest way to manage your console instance would be to construct an instance at the module level and import it where needed.
The Console object has a `print` method which has an intentionally similar interface to the builtin `print` function. Here's an example of use:
As you might expect, this will print `"Hello World!"` to the terminal. Not that unlike the `print` function, Rich will word-wrap your test to fit within the terminal width.
There are a few ways of adding color and style to your output. You can set a style for the entire output by adding a `style` keyword argument. Here's an example:
That's fine for styling a line of text at a time. For more finely grained styling, Rich renders a special markup which is similar in syntax to [bbcode](https://en.wikipedia.org/wiki/BBCode). Here's an example:
Note that the CSS hex and RGB style of color lets you chose one of 16.7 million colors, but some terminals (notably OSX terminal) only support 256 colors. If Rich detects that only 256 colors are supported it will pick the closest color available. In practice this means that you may not get exactly the color you ask for, but it is generally _close enough_.
Style attributes and colors may appear in any order, i.e. `"bold magenta on yellow"` has the same effect as `"on yellow magenta bold"`. The latter may be preferred by Yoda.
To render markdown import the `Markdown` class and construct it with a string containing markdown code. Then print it to the console. Here's an example:
This will produce output something like the following:
![markdown](./imgs/markdown.png)
## Syntax Highlighting
Rich uses the [pygments](https://pygments.org/) library to implement syntax highlighting. Usage is similar to rendering markdown; construct a `Syntax` object and print it to the console. Here's an example: