Skip to content

Commit 23da936

Browse files
authored
Update multicoloredline.py
- 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.
1 parent dcef9c7 commit 23da936

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

Diff for: Colors/multicoloredline.py

+51-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
1-
## This script prints a multicolored line
2-
# quo can be installed using pip
3-
4-
from quo.console import Console
1+
from rich.console import Console
2+
from rich.syntax import Syntax
3+
from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn
4+
from rich.table import Table
5+
import time
6+
import json
57

68
console = Console()
79

8-
console.rule(multiclored=True)
10+
# Fancy separator
11+
console.rule("[bold]Welcome to Rich Terminal[/bold]", style="rainbow")
12+
13+
# Define some JSON data
14+
json_data = {
15+
"message": "Hello, World!",
16+
"status": "success",
17+
"code": 200
18+
}
19+
20+
# Print JSON with syntax highlighting
21+
syntax = Syntax(json.dumps(json_data, indent=4), "json", theme="monokai", line_numbers=True)
22+
console.print(syntax)
23+
24+
# Simulating a progress bar
25+
console.print("\n[bold cyan]Processing data...[/bold cyan]\n")
26+
27+
with Progress(
28+
SpinnerColumn(),
29+
TextColumn("[progress.description]{task.description}"),
30+
BarColumn(),
31+
TextColumn("{task.percentage:>3.0f}%"),
32+
console=console,
33+
) as progress:
34+
task = progress.add_task("[cyan]Loading...", total=100)
35+
for _ in range(100):
36+
time.sleep(0.02)
37+
progress.update(task, advance=1)
38+
39+
# Create a rich table
40+
console.print("\n[bold magenta]Results Summary:[/bold magenta]\n")
41+
42+
table = Table(title="System Report", show_header=True, header_style="bold cyan")
43+
table.add_column("Metric", style="bold yellow")
44+
table.add_column("Value", justify="right", style="bold green")
45+
46+
table.add_row("CPU Usage", "12.5%")
47+
table.add_row("Memory Usage", "68.3%")
48+
table.add_row("Disk Space", "45.7% free")
49+
50+
console.print(table)
51+
52+
# Success message
53+
console.print("\n[bold green]🎉 Process completed successfully![/bold green]\n")
54+
console.rule(style="rainbow")

0 commit comments

Comments
 (0)