|
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 |
5 | 7 |
|
6 | 8 | console = Console()
|
7 | 9 |
|
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