Creating an informative tasks display
Python3
from time import sleep from rich.console import Console console = Console() tasks = [f "Task {n}" for n in range ( 1 , 8 )] with console.status( "[bold dark_orange]Finishing tasks..." ) as status: while tasks: task = tasks.pop( 0 ) sleep( 1 ) console.log(f "{task} complete" ) |
The above example shows the process of displaying various tasks in a loop. This is done with the Console Wrapper API. The Console class provides some extended functionalities specifically for terminal content. So, we instantiate a Console object and use the log method to display the output. The status method is used for displaying the ongoing process while being in the loop.
For more options and functions in the Console class, you can refer to the documentation of the Rich library.
Installing and Using Rich Package in Python
In this article, We are going to learn how to install and use rich packages in Python.
RIch is a python package for creating some awesome terminal formatting and logging. It has several features and functions that can make your application look nicer and even add a new look to your CLI application. We will be understanding the process of installing and basic usage of the RICH package in Python in this article.