✨ Add Epic Progress Bars & Smart Auto-completion! - 6 progress bar styles with animations - Smart fuzzy command completion - Interactive demos and feature showcase - Enhanced shell with suggestion system - Progress tracking for code execution - Multiple spinner animations - Package installation simulation
This commit is contained in:
277
commands/cmd_demo.py
Normal file
277
commands/cmd_demo.py
Normal file
@@ -0,0 +1,277 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Demo Command - Showcase OverCode features
|
||||
"""
|
||||
|
||||
import time
|
||||
import os
|
||||
from colorama import Fore, Style, init
|
||||
|
||||
# Import progress utilities
|
||||
try:
|
||||
from utils.progress import ProgressBar, SpinnerProgress, simulate_progress, demo_progress_bars, demo_spinner
|
||||
from utils.autocomplete import demo_autocomplete
|
||||
UTILS_AVAILABLE = True
|
||||
except ImportError:
|
||||
UTILS_AVAILABLE = False
|
||||
|
||||
init(autoreset=True)
|
||||
|
||||
class DemoCommand:
|
||||
"""Demonstrate OverCode features"""
|
||||
|
||||
def __init__(self, feature=""):
|
||||
self.feature = feature.strip().lower()
|
||||
self.features = {
|
||||
'progress': self._demo_progress_bars,
|
||||
'spinner': self._demo_spinners,
|
||||
'autocomplete': self._demo_autocomplete,
|
||||
'all': self._demo_all,
|
||||
'install': self._demo_install,
|
||||
'compile': self._demo_compile,
|
||||
'download': self._demo_download
|
||||
}
|
||||
|
||||
def run(self):
|
||||
"""Execute the demo command"""
|
||||
if not self.feature:
|
||||
self._show_demo_menu()
|
||||
return
|
||||
|
||||
if self.feature in self.features:
|
||||
print(Fore.CYAN + f"🚀 Demo: {self.feature.title()}")
|
||||
print(Fore.YELLOW + "=" * 40)
|
||||
self.features[self.feature]()
|
||||
else:
|
||||
print(Fore.RED + f"❌ Demo '{self.feature}' not found!")
|
||||
self._show_demo_menu()
|
||||
|
||||
def _show_demo_menu(self):
|
||||
"""Show available demos"""
|
||||
print(Fore.CYAN + "🎭 OverCode Feature Demos")
|
||||
print(Fore.YELLOW + "─" * 30)
|
||||
print()
|
||||
|
||||
demos = {
|
||||
'progress': '📊 Progress bar styles and animations',
|
||||
'spinner': '🔄 Loading spinners and animations',
|
||||
'autocomplete': '🔍 Smart command completion',
|
||||
'install': '📦 Simulated package installation',
|
||||
'compile': '⚙️ Code compilation simulation',
|
||||
'download': '⬇️ File download simulation',
|
||||
'all': '🌟 Run all demos'
|
||||
}
|
||||
|
||||
for demo, desc in demos.items():
|
||||
print(f"{Fore.GREEN}{demo:<15} {Fore.WHITE}→ {desc}")
|
||||
|
||||
print()
|
||||
print(Fore.MAGENTA + "Usage:")
|
||||
print(f"{Fore.WHITE} demo <feature_name>")
|
||||
print(f"{Fore.LIGHTBLACK_EX} Example: demo progress")
|
||||
|
||||
def _demo_progress_bars(self):
|
||||
"""Demonstrate progress bar styles"""
|
||||
if not UTILS_AVAILABLE:
|
||||
print(Fore.RED + "Progress bars not available - utils module missing")
|
||||
return
|
||||
|
||||
print(Fore.GREEN + "📊 Progress Bar Demo")
|
||||
print("Testing different styles and colors...\n")
|
||||
|
||||
# Modern style
|
||||
print(Fore.CYAN + "Modern Style (Cyan):")
|
||||
bar1 = ProgressBar(50, style='modern', color='cyan')
|
||||
for i in range(51):
|
||||
bar1.update(i, "Processing modern style...")
|
||||
time.sleep(0.03)
|
||||
|
||||
# Fire style
|
||||
print(f"\n{Fore.RED}Fire Style (Epic!):")
|
||||
bar2 = ProgressBar(30, style='fire', color='red')
|
||||
for i in range(31):
|
||||
bar2.update(i, "🔥 Blazing through tasks...")
|
||||
time.sleep(0.05)
|
||||
|
||||
# Dots style
|
||||
print(f"\n{Fore.YELLOW}Dots Style (Yellow):")
|
||||
bar3 = ProgressBar(40, style='dots', color='yellow')
|
||||
for i in range(41):
|
||||
bar3.update(i, "● Processing dots...")
|
||||
time.sleep(0.02)
|
||||
|
||||
print(f"\n{Fore.GREEN}✨ Progress bar demo complete!")
|
||||
|
||||
def _demo_spinners(self):
|
||||
"""Demonstrate spinner animations"""
|
||||
if not UTILS_AVAILABLE:
|
||||
print(Fore.RED + "Spinners not available - utils module missing")
|
||||
return
|
||||
|
||||
print(Fore.GREEN + "🔄 Spinner Animation Demo")
|
||||
|
||||
spinner_styles = [
|
||||
('dots', 'Braille dots animation'),
|
||||
('arrows', 'Rotating arrows'),
|
||||
('bars', 'Classic spinning bars'),
|
||||
('fire', 'Epic fire animation'),
|
||||
('blocks', 'Building blocks')
|
||||
]
|
||||
|
||||
for style, description in spinner_styles:
|
||||
print(f"\n{Fore.CYAN}{description}:")
|
||||
spinner = SpinnerProgress(f"Loading with {style} style", style)
|
||||
spinner.start()
|
||||
time.sleep(2)
|
||||
spinner.stop(f"{style.title()} complete!")
|
||||
|
||||
print(f"\n{Fore.GREEN}✨ Spinner demo complete!")
|
||||
|
||||
def _demo_autocomplete(self):
|
||||
"""Demonstrate auto-completion"""
|
||||
if not UTILS_AVAILABLE:
|
||||
print(Fore.RED + "Auto-completion not available - utils module missing")
|
||||
return
|
||||
|
||||
print(Fore.GREEN + "🔍 Auto-completion Demo")
|
||||
demo_autocomplete()
|
||||
|
||||
def _demo_install(self):
|
||||
"""Simulate package installation with progress"""
|
||||
if not UTILS_AVAILABLE:
|
||||
print(Fore.RED + "Progress bars not available - utils module missing")
|
||||
return
|
||||
|
||||
print(Fore.GREEN + "📦 Package Installation Simulation")
|
||||
|
||||
packages = [
|
||||
("awesome-games", 45),
|
||||
("ai-tools", 30),
|
||||
("theme-pack", 25),
|
||||
("dev-utils", 35)
|
||||
]
|
||||
|
||||
for package, size in packages:
|
||||
print(f"\n{Fore.CYAN}Installing {package}...")
|
||||
|
||||
# Download phase
|
||||
print(f"{Fore.YELLOW}⬇️ Downloading...")
|
||||
bar = ProgressBar(size, style='arrows', color='blue')
|
||||
for i in range(size + 1):
|
||||
bar.update(i, f"Downloading {package} ({i}/{size})")
|
||||
time.sleep(0.05)
|
||||
|
||||
# Installation phase
|
||||
print(f"\n{Fore.GREEN}📦 Installing...")
|
||||
spinner = SpinnerProgress(f"Installing {package}", 'dots')
|
||||
spinner.start()
|
||||
time.sleep(1.5)
|
||||
spinner.stop(f"✓ {package} installed successfully!")
|
||||
|
||||
print(f"\n{Fore.GREEN}🎉 All packages installed!")
|
||||
|
||||
def _demo_compile(self):
|
||||
"""Simulate code compilation"""
|
||||
if not UTILS_AVAILABLE:
|
||||
print(Fore.RED + "Progress bars not available - utils module missing")
|
||||
return
|
||||
|
||||
print(Fore.GREEN + "⚙️ Code Compilation Simulation")
|
||||
|
||||
stages = [
|
||||
("Parsing", 15, "Analyzing source code..."),
|
||||
("Lexing", 20, "Tokenizing input..."),
|
||||
("Compiling", 40, "Generating bytecode..."),
|
||||
("Optimizing", 25, "Applying optimizations..."),
|
||||
("Linking", 10, "Linking dependencies...")
|
||||
]
|
||||
|
||||
for stage, duration, description in stages:
|
||||
print(f"\n{Fore.CYAN}{stage}:")
|
||||
bar = ProgressBar(duration, style='blocks', color='green')
|
||||
|
||||
for i in range(duration + 1):
|
||||
bar.update(i, description)
|
||||
time.sleep(0.08)
|
||||
|
||||
print(f"\n{Fore.GREEN}✅ Compilation successful!")
|
||||
print(f"{Fore.YELLOW}Output: awesome_program.exe")
|
||||
|
||||
def _demo_download(self):
|
||||
"""Simulate file download with realistic progress"""
|
||||
if not UTILS_AVAILABLE:
|
||||
print(Fore.RED + "Progress bars not available - utils module missing")
|
||||
return
|
||||
|
||||
print(Fore.GREEN + "⬇️ Download Simulation")
|
||||
|
||||
files = [
|
||||
("overcode-themes.zip", 100, 'modern'),
|
||||
("game-pack-ultra.zip", 150, 'fire'),
|
||||
("dev-tools.tar.gz", 80, 'dots')
|
||||
]
|
||||
|
||||
for filename, size, style in files:
|
||||
print(f"\n{Fore.CYAN}Downloading {filename}...")
|
||||
|
||||
bar = ProgressBar(size, style=style, color='cyan')
|
||||
|
||||
# Simulate variable download speed
|
||||
downloaded = 0
|
||||
while downloaded < size:
|
||||
import random
|
||||
chunk = random.randint(1, 5)
|
||||
downloaded = min(downloaded + chunk, size)
|
||||
|
||||
speed = random.uniform(1.5, 3.0) # MB/s
|
||||
eta = (size - downloaded) / speed if speed > 0 else 0
|
||||
|
||||
bar.update(downloaded, f"Download speed: {speed:.1f} MB/s")
|
||||
time.sleep(0.03)
|
||||
|
||||
print(f"{Fore.GREEN}✓ {filename} downloaded successfully!")
|
||||
|
||||
print(f"\n{Fore.GREEN}🎉 All downloads complete!")
|
||||
|
||||
def _demo_all(self):
|
||||
"""Run all demos"""
|
||||
print(Fore.MAGENTA + "🌟 Running All OverCode Demos!")
|
||||
print(Fore.YELLOW + "=" * 50)
|
||||
|
||||
demos = ['progress', 'spinner', 'install', 'compile']
|
||||
|
||||
for i, demo in enumerate(demos, 1):
|
||||
print(f"\n{Fore.CYAN}[{i}/{len(demos)}] {demo.title()} Demo")
|
||||
print(Fore.YELLOW + "─" * 30)
|
||||
self.features[demo]()
|
||||
|
||||
if i < len(demos):
|
||||
print(f"\n{Fore.LIGHTBLACK_EX}(Next demo in 2 seconds...)")
|
||||
time.sleep(2)
|
||||
|
||||
print(f"\n{Fore.GREEN}🎊 All demos complete! OverCode is AMAZING!")
|
||||
|
||||
class SuggestCommand:
|
||||
"""Provide command suggestions"""
|
||||
|
||||
def __init__(self, shell_instance):
|
||||
self.shell = shell_instance
|
||||
|
||||
def run(self):
|
||||
"""Show command suggestions"""
|
||||
if hasattr(self.shell, 'autocomplete') and self.shell.autocomplete:
|
||||
print(Fore.CYAN + "💡 Smart Command Suggestions")
|
||||
print(Fore.YELLOW + "─" * 30)
|
||||
|
||||
# Show popular commands
|
||||
suggestions = self.shell.autocomplete.get_command_suggestions("")
|
||||
for cmd, desc in suggestions[:10]:
|
||||
print(f"{Fore.GREEN}{cmd:<12} {Fore.WHITE}→ {desc}")
|
||||
|
||||
print(f"\n{Fore.MAGENTA}💡 Pro Tips:")
|
||||
print(f"{Fore.WHITE}• Tab completion coming soon!")
|
||||
print(f"{Fore.WHITE}• Type partial commands for smart suggestions")
|
||||
print(f"{Fore.WHITE}• Mistype commands to see corrections")
|
||||
else:
|
||||
print(Fore.YELLOW + "Auto-completion not available")
|
||||
print(Fore.WHITE + "Available commands: help, new, run, game, theme, clear, ls, cd, exit")
|
||||
Reference in New Issue
Block a user