# Copyright (C) 2025 AIDC-AI
# This project is licensed under the MIT License (SPDX-License-identifier: MIT).
"""Main menu for interactive mode."""
import questionary
from pathlib import Path
from rich.console import Console
from rich.panel import Panel
from pixelle.cli.utils.display import show_header_info, show_current_config, show_enhanced_help
from pixelle.cli.utils.server_utils import start_pixelle_server, check_service_status
from pixelle.cli.interactive.wizard import run_fresh_setup_wizard
console = Console()
def show_main_menu():
"""Show main menu"""
# Show header information
show_header_info()
console.print("\n๐ [bold]Current configuration status[/bold]")
show_current_config()
action = questionary.select(
"Please select the action to perform:",
choices=[
questionary.Choice("๐ [start] Start Pixelle MCP", "start"),
questionary.Choice("๐ [init] Initialize/reconfigure Pixelle MCP", "init"),
questionary.Choice("๐ [edit] Edit configuration", "edit"),
questionary.Choice("๐ง [workflow] View workflow information", "workflow"),
questionary.Choice("๐ [dev] Development & system status", "dev"),
questionary.Choice("โ [help] Help", "help"),
questionary.Choice("โ Exit", "exit")
]
).ask()
if action == "start":
start_pixelle_server()
elif action == "init":
run_fresh_setup_wizard()
elif action == "edit":
guide_edit_config()
elif action == "workflow":
from pixelle.cli.commands.workflow import workflow_command
workflow_command()
elif action == "dev":
from pixelle.cli.commands.dev import dev_command
dev_command()
elif action == "help":
show_enhanced_help()
elif action == "exit":
console.print("๐ Goodbye!")
else:
console.print(f"Feature {action} is under development...")
def guide_edit_config():
"""Guide user to edit configuration"""
console.print(Panel(
"โ๏ธ [bold]Manual edit configuration[/bold]\n\n"
"Configuration file contains detailed comments, you can directly edit to customize the configuration.\n"
"Configuration file location: .env\n\n"
"",
title="Manual configuration guide",
border_style="green"
))
# Show current configuration file path
from pixelle.utils.os_util import get_pixelle_root_path
pixelle_root = get_pixelle_root_path()
env_path = Path(pixelle_root) / ".env"
console.print(f"๐ Configuration file path: {env_path.absolute()}")
if not env_path.exists():
console.print("\nโ ๏ธ Configuration file does not exist!")
return
# Provide some common editors suggestions
console.print("\n๐ก Recommended editors:")
console.print("โข VS Code: [bold cyan]code .env[/bold cyan]")
console.print("โข Nano: [bold cyan]nano .env[/bold cyan]")
console.print("โข Vim: [bold cyan]vim .env[/bold cyan]")
console.print("โข Or any text editor")
console.print("\n๐ Common configuration modifications:")
console.print("โข Change port: modify PORT=9004")
console.print("โข Add new LLM: configure the corresponding API_KEY")
console.print("โข Disable LLM: delete or clear the corresponding API_KEY")
console.print("โข Change ComfyUI: modify COMFYUI_BASE_URL")
# Ask if open file
if questionary.confirm("Open configuration file in default editor?", default=True, instruction="(Y/n)").ask():
try:
import subprocess
import platform
if platform.system() == "Darwin": # macOS
subprocess.run(["open", str(env_path)])
elif platform.system() == "Windows":
subprocess.run(["notepad", str(env_path)])
else: # Linux
subprocess.run(["xdg-open", str(env_path)])
console.print("โ
Configuration file opened in default editor")
except Exception as e:
console.print(f"โ Cannot open automatically: {e}")
console.print("๐ก Please manually edit the file")
console.print("\n๐ After configuration, rerun [bold cyan]pixelle[/bold cyan] to apply the configuration")
console.print("๐๏ธ If you need to completely reconfigure, delete the .env file and rerun [bold cyan]pixelle[/bold cyan]")