Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Style Your Game With Rich

00:00 Style Your Game With Rich. In the last step, you laid the groundwork for bigger changes. Now it’s time to improve the user experience of your game dramatically.

00:11 You’ll use Rich, a library for adding color and style to text in the terminal. You’ll start by familiarizing yourself with Rich before adding some color and style to your game.

00:22 Rich was originally developed by Will McGugan and is currently maintained by his company Textualize.io. Rich helps you color, style, and format text in the terminal.

00:32 Rich is a third-party library that you need to install before you can use it. Before you install Rich, you should create a virtual environment where you can install your project dependencies. Depending on the platform you’re using, you’ll need slightly different commands. Here they are for Windows,

01:01 and here they are for Linux and macOS.

01:13 Once you’ve created and activated your virtual environment, you can install rich with pip, and this command is the same on both platforms.

01:25 Once Rich is installed, you can try it out. A quick way to get started using Rich is to override the print() function.

01:40 Rich renders the word Rich in bold with red text. Rich uses its own markup syntax that’s inspired by Bulletin Board Code. You add style directives in square brackets, such as the [bold red] just seen.

01:54 The style applies until you close it with a forward slash character [/]. You can also use emoji names enclosed between colons to print emoji.

02:03 You just used :snake: to print a snake emoji. You can see the full list of emoji that Rich supports with this command, but it’s a very big list, so you’ll need to spend some time scrolling to see every one.

02:21 Emoji support is limited on Windows 10 and earlier when using the command prompt. As you can see on-screen, the emoji are not displayed correctly. However, you can install Windows Terminal to get the full Rich experience as well as a much more performant and usable terminal compared to the dated command prompt.

02:44 Most Linux and macOS terminals have good support for emoji. While Rich’s implementation of print() is convenient, it’s not flexible in the long run.

02:54 But Rich has a solution, and that’s what you’ll be looking at in the next section of the course.

Become a Member to join the conversation.