-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Migrated from `quo` to `rich` for better terminal output and functionality. - Added **syntax-highlighted JSON** output using `rich.syntax.Syntax. - Implemented **progress bar** with animated spinner using `rich.progress.Progress. - Introduced **structured table display** with `rich.table.Table` for system metrics. - Enhanced user feedback with a **completion success message**. - Improved readability and interactivity for a better terminal experience.
- Loading branch information
Showing
1 changed file
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,54 @@ | ||
## This script prints a multicolored line | ||
# quo can be installed using pip | ||
|
||
from quo.console import Console | ||
from rich.console import Console | ||
from rich.syntax import Syntax | ||
from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn | ||
from rich.table import Table | ||
import time | ||
import json | ||
|
||
console = Console() | ||
|
||
console.rule(multiclored=True) | ||
# Fancy separator | ||
console.rule("[bold]Welcome to Rich Terminal[/bold]", style="rainbow") | ||
|
||
# Define some JSON data | ||
json_data = { | ||
"message": "Hello, World!", | ||
"status": "success", | ||
"code": 200 | ||
} | ||
|
||
# Print JSON with syntax highlighting | ||
syntax = Syntax(json.dumps(json_data, indent=4), "json", theme="monokai", line_numbers=True) | ||
console.print(syntax) | ||
|
||
# Simulating a progress bar | ||
console.print("\n[bold cyan]Processing data...[/bold cyan]\n") | ||
|
||
with Progress( | ||
SpinnerColumn(), | ||
TextColumn("[progress.description]{task.description}"), | ||
BarColumn(), | ||
TextColumn("{task.percentage:>3.0f}%"), | ||
console=console, | ||
) as progress: | ||
task = progress.add_task("[cyan]Loading...", total=100) | ||
for _ in range(100): | ||
time.sleep(0.02) | ||
progress.update(task, advance=1) | ||
|
||
# Create a rich table | ||
console.print("\n[bold magenta]Results Summary:[/bold magenta]\n") | ||
|
||
table = Table(title="System Report", show_header=True, header_style="bold cyan") | ||
table.add_column("Metric", style="bold yellow") | ||
table.add_column("Value", justify="right", style="bold green") | ||
|
||
table.add_row("CPU Usage", "12.5%") | ||
table.add_row("Memory Usage", "68.3%") | ||
table.add_row("Disk Space", "45.7% free") | ||
|
||
console.print(table) | ||
|
||
# Success message | ||
console.print("\n[bold green]🎉 Process completed successfully![/bold green]\n") | ||
console.rule(style="rainbow") |