Initial commit
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Custom theme demonstration for Edison.
|
||||
This script shows how to create and use a custom theme with Edison.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
from pygments.style import Style
|
||||
from pygments.token import (
|
||||
Comment, Error, Keyword, Literal, Name, Number, Operator, String, Text
|
||||
)
|
||||
from pygments.styles import STYLE_MAP
|
||||
from rich.console import Console
|
||||
from rich.syntax import Syntax
|
||||
from rich.panel import Panel
|
||||
|
||||
# Add the parent directory to the path so we can import Edison modules
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
# Import Edison's markdown_utils module
|
||||
from edison.utils.markdown_utils import print_command_rich
|
||||
|
||||
# Sample command to demonstrate syntax highlighting
|
||||
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"
|
||||
done
|
||||
fi
|
||||
|
||||
# Function definition
|
||||
function process_files() {
|
||||
local dir="$1"
|
||||
find "$dir" -type f -name "*.txt"
|
||||
}
|
||||
|
||||
# Call the function
|
||||
process_files "/var/log"
|
||||
"""
|
||||
|
||||
# Define custom themes
|
||||
class EdisonDarkTheme(Style):
|
||||
"""A custom dark theme for Edison."""
|
||||
|
||||
# Define colors
|
||||
background_color = "#1e1e2e" # Dark background
|
||||
highlight_color = "#313244"
|
||||
|
||||
# Define token colors
|
||||
styles = {
|
||||
Text: "#cdd6f4", # Light gray for regular text
|
||||
Error: "#f38ba8", # Red for errors
|
||||
Comment: "#6c7086", # Muted gray for comments
|
||||
Keyword: "#cba6f7", # Purple for keywords
|
||||
Keyword.Reserved: "#cba6f7",
|
||||
Keyword.Namespace: "#cba6f7",
|
||||
Name: "#cdd6f4", # Light gray for names
|
||||
Name.Builtin: "#f9e2af", # Yellow for builtins
|
||||
Name.Function: "#89b4fa", # Blue for functions
|
||||
Name.Class: "#f9e2af", # Yellow for classes
|
||||
Name.Decorator: "#89b4fa", # Blue for decorators
|
||||
Name.Variable: "#f5c2e7", # Pink for variables
|
||||
Number: "#fab387", # Orange for numbers
|
||||
Operator: "#94e2d5", # Teal for operators
|
||||
String: "#a6e3a1", # Green for strings
|
||||
}
|
||||
|
||||
class EdisonLightTheme(Style):
|
||||
"""A custom light theme for Edison."""
|
||||
|
||||
# Define colors
|
||||
background_color = "#fafafa" # Light background
|
||||
highlight_color = "#e6e6e6"
|
||||
|
||||
# Define token colors
|
||||
styles = {
|
||||
Text: "#383a42", # Dark gray for regular text
|
||||
Error: "#e45649", # Red for errors
|
||||
Comment: "#a0a1a7", # Gray for comments
|
||||
Keyword: "#a626a4", # Purple for keywords
|
||||
Keyword.Reserved: "#a626a4",
|
||||
Keyword.Namespace: "#a626a4",
|
||||
Name: "#383a42", # Dark gray for names
|
||||
Name.Builtin: "#c18401", # Yellow for builtins
|
||||
Name.Function: "#4078f2", # Blue for functions
|
||||
Name.Class: "#c18401", # Yellow for classes
|
||||
Name.Decorator: "#4078f2", # Blue for decorators
|
||||
Name.Variable: "#e45649", # Red for variables
|
||||
Number: "#986801", # Brown for numbers
|
||||
Operator: "#0184bc", # Teal for operators
|
||||
String: "#50a14f", # Green for strings
|
||||
}
|
||||
|
||||
def register_custom_themes():
|
||||
"""Register custom themes with Pygments."""
|
||||
STYLE_MAP["edison-dark"] = "custom_theme_demo.EdisonDarkTheme"
|
||||
STYLE_MAP["edison-light"] = "custom_theme_demo.EdisonLightTheme"
|
||||
|
||||
def main():
|
||||
"""Main function to demonstrate custom themes."""
|
||||
console = Console()
|
||||
|
||||
# Register custom themes
|
||||
register_custom_themes()
|
||||
|
||||
# Print header
|
||||
console.print("\n[bold cyan]Edison Custom Theme Demonstration[/bold cyan]")
|
||||
console.print("This shows how to create and use custom themes with Edison.\n")
|
||||
|
||||
# Display built-in theme for comparison
|
||||
console.print("[bold]Built-in Theme (monokai):[/bold]")
|
||||
print_command_rich(SAMPLE_COMMAND, theme="monokai")
|
||||
console.print()
|
||||
|
||||
# Display custom themes
|
||||
console.print("[bold]Custom Theme (edison-dark):[/bold]")
|
||||
print_command_rich(SAMPLE_COMMAND, theme="edison-dark")
|
||||
console.print()
|
||||
|
||||
console.print("[bold]Custom Theme (edison-light):[/bold]")
|
||||
print_command_rich(SAMPLE_COMMAND, theme="edison-light")
|
||||
console.print()
|
||||
|
||||
# Show how to create and use custom themes
|
||||
console.print("[bold]How to Create and Use Custom Themes:[/bold]")
|
||||
console.print("""
|
||||
1. Create a custom theme class that inherits from pygments.style.Style:
|
||||
|
||||
```python
|
||||
from pygments.style import Style
|
||||
from pygments.token import Comment, Keyword, Name, Number, Operator, String, Text
|
||||
|
||||
class MyCustomTheme(Style):
|
||||
background_color = "#1e1e2e"
|
||||
highlight_color = "#313244"
|
||||
|
||||
styles = {
|
||||
Text: "#cdd6f4",
|
||||
Comment: "#6c7086",
|
||||
Keyword: "#cba6f7",
|
||||
Name.Function: "#89b4fa",
|
||||
Name.Variable: "#f5c2e7",
|
||||
Number: "#fab387",
|
||||
Operator: "#94e2d5",
|
||||
String: "#a6e3a1",
|
||||
}
|
||||
```
|
||||
|
||||
2. Register your theme with Pygments:
|
||||
|
||||
```python
|
||||
from pygments.styles import STYLE_MAP
|
||||
STYLE_MAP["my-theme"] = "module_name.MyCustomTheme"
|
||||
```
|
||||
|
||||
3. Use your custom theme with Edison:
|
||||
|
||||
```python
|
||||
# In your code
|
||||
from edison.utils.markdown_utils import print_command_rich
|
||||
print_command_rich("ls -la", theme="my-theme")
|
||||
|
||||
# Or via command line
|
||||
edison --theme my-theme "list files"
|
||||
```
|
||||
|
||||
4. To make your theme permanently available, create a Python package and install it:
|
||||
|
||||
```python
|
||||
# setup.py
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name="edison-custom-themes",
|
||||
version="0.1.0",
|
||||
py_modules=["edison_themes"],
|
||||
entry_points={
|
||||
"pygments.styles": [
|
||||
"my-theme = edison_themes:MyCustomTheme",
|
||||
],
|
||||
},
|
||||
)
|
||||
```
|
||||
|
||||
Then install with: pip install -e .
|
||||
""")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user