124 lines
3.3 KiB
Python
124 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Theme demonstration for Edison's rich output formatting.
|
|
This script shows the same command rendered with different syntax highlighting themes.
|
|
"""
|
|
import sys
|
|
from rich.console import Console
|
|
from rich.syntax import Syntax
|
|
from rich.panel import Panel
|
|
from rich.columns import Columns
|
|
from rich.table import Table
|
|
|
|
# Sample bash command with various syntax elements to highlight theme differences
|
|
SAMPLE_COMMAND = """#!/bin/bash
|
|
|
|
# This is a comment
|
|
echo "Hello, world!"
|
|
|
|
# Define variables
|
|
name="User"
|
|
count=10
|
|
|
|
# Conditional statement
|
|
if [ "$count" -gt 5 ]; then
|
|
echo "Count is greater than 5"
|
|
for ((i=0; i<$count; i++)); do
|
|
echo "Processing item $i for $name"
|
|
if [ -f "/tmp/file_$i.txt" ]; then
|
|
rm "/tmp/file_$i.txt"
|
|
fi
|
|
done
|
|
else
|
|
echo "Count is less than or equal to 5"
|
|
fi
|
|
|
|
# Function definition
|
|
function process_files() {
|
|
local dir="$1"
|
|
find "$dir" -type f -name "*.txt" | while read file; do
|
|
echo "Found file: $file"
|
|
grep -q "ERROR" "$file" && echo "Error found in $file"
|
|
done
|
|
}
|
|
|
|
# Call the function
|
|
process_files "/var/log"
|
|
"""
|
|
|
|
def show_theme(theme_name):
|
|
"""Display a command with the specified theme."""
|
|
syntax = Syntax(
|
|
SAMPLE_COMMAND,
|
|
"bash",
|
|
theme=theme_name,
|
|
line_numbers=True,
|
|
word_wrap=True,
|
|
)
|
|
panel = Panel(
|
|
syntax,
|
|
title=f"Theme: {theme_name}",
|
|
border_style="blue",
|
|
padding=(1, 2),
|
|
)
|
|
return panel
|
|
|
|
def main():
|
|
"""Main function to display theme comparisons."""
|
|
console = Console()
|
|
|
|
# List of themes to demonstrate
|
|
themes = [
|
|
"monokai",
|
|
"github-dark",
|
|
"solarized-dark",
|
|
"dracula",
|
|
"nord",
|
|
"gruvbox-dark",
|
|
"one-dark",
|
|
"vs",
|
|
"solarized-light",
|
|
"gruvbox-light",
|
|
]
|
|
|
|
# Print header
|
|
console.print("\n[bold cyan]Edison Theme Demonstration[/bold cyan]")
|
|
console.print("This shows the same bash script rendered with different syntax highlighting themes.\n")
|
|
|
|
# Display theme comparison table
|
|
table = Table(title="Available Themes for Edison")
|
|
table.add_column("Theme Name", style="cyan")
|
|
table.add_column("Description", style="green")
|
|
|
|
theme_descriptions = {
|
|
"monokai": "Default theme with vibrant colors (dark)",
|
|
"github-dark": "Based on GitHub's dark theme",
|
|
"solarized-dark": "Popular dark theme with softer colors",
|
|
"dracula": "High contrast dark theme",
|
|
"nord": "Bluish dark theme",
|
|
"gruvbox-dark": "Retro dark theme with warm colors",
|
|
"one-dark": "Based on Atom's One Dark theme",
|
|
"vs": "Based on Visual Studio's default theme (light)",
|
|
"solarized-light": "Light version of the Solarized theme",
|
|
"gruvbox-light": "Light version of the Gruvbox theme",
|
|
}
|
|
|
|
for theme in themes:
|
|
table.add_row(theme, theme_descriptions.get(theme, ""))
|
|
|
|
console.print(table)
|
|
console.print()
|
|
|
|
# Display each theme one by one
|
|
for theme in themes:
|
|
console.print(show_theme(theme))
|
|
console.print()
|
|
|
|
# Optional: pause between themes for better viewing
|
|
if theme != themes[-1]:
|
|
console.print("[italic]Press Enter to see the next theme...[/italic]")
|
|
input()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|