Files
oai/oai/tui/screens/commands_screen.py
2026-02-06 09:48:37 +01:00

175 lines
5.9 KiB
Python

"""Commands reference screen for oAI TUI."""
from textual.app import ComposeResult
from textual.containers import Container, Vertical, VerticalScroll
from textual.screen import ModalScreen
from textual.widgets import Button, Static
class CommandsScreen(ModalScreen[None]):
"""Modal screen showing all available commands."""
DEFAULT_CSS = """
CommandsScreen {
align: center middle;
}
CommandsScreen > Container {
width: 90;
height: 40;
background: #1e1e1e;
border: solid #555555;
}
CommandsScreen .header {
dock: top;
width: 100%;
height: auto;
background: #2d2d2d;
color: #cccccc;
padding: 0 2;
}
CommandsScreen .content {
width: 100%;
height: 1fr;
background: #1e1e1e;
padding: 2;
color: #cccccc;
overflow-y: auto;
scrollbar-background: #1e1e1e;
scrollbar-color: #555555;
scrollbar-size: 1 1;
}
CommandsScreen .footer {
dock: bottom;
width: 100%;
height: auto;
background: #2d2d2d;
padding: 1 2;
align: center middle;
}
"""
def compose(self) -> ComposeResult:
"""Compose the commands screen."""
with Container():
yield Static("[bold]Commands Reference[/]", classes="header")
with VerticalScroll(classes="content"):
yield Static(self._get_commands_text(), markup=True)
with Vertical(classes="footer"):
yield Button("Close", id="close-button", variant="primary")
def _get_commands_text(self) -> str:
"""Generate formatted commands text."""
return """[bold cyan]General Commands[/]
[green]/help[/] - Show help screen with keyboard shortcuts
[green]/commands[/] - Show this commands reference
[green]/model[/] - Open model selector (or press F2)
[green]/info[/] - Show detailed information about current model
[green]/stats[/] - Show session statistics (or press Ctrl+S)
[green]/credits[/] - Check account credits (OpenRouter) or view console link
[green]/clear[/] - Clear chat display
[green]/reset[/] - Reset conversation history
[green]/retry[/] - Retry last prompt
[green]/paste[/] - Paste from clipboard
[bold cyan]Provider Commands[/]
[green]/provider[/] - Show current provider
[green]/provider openrouter[/] - Switch to OpenRouter
[green]/provider anthropic[/] - Switch to Anthropic (Claude)
[green]/provider openai[/] - Switch to OpenAI (ChatGPT)
[green]/provider ollama[/] - Switch to Ollama (local)
[bold cyan]Online Mode (Web Search)[/]
[green]/online[/] - Show online mode status
[green]/online on[/] - Enable web search
[green]/online off[/] - Disable web search
[dim]Search Providers:[/]
• [yellow]anthropic_native[/] - Anthropic's native search with citations ($0.01/search)
• [yellow]duckduckgo[/] - Free web scraping (default, works with all providers)
• [yellow]google[/] - Google Custom Search (requires API key)
[bold cyan]Configuration Commands[/]
[green]/config[/] - View all settings
[green]/config provider <name>[/] - Set default provider
[green]/config search_provider <provider>[/] - Set search provider (anthropic_native/duckduckgo/google)
[green]/config openrouter_api_key <key>[/] - Set OpenRouter API key
[green]/config anthropic_api_key <key>[/] - Set Anthropic API key
[green]/config openai_api_key <key>[/] - Set OpenAI API key
[green]/config ollama_base_url <url>[/] - Set Ollama server URL
[green]/config google_api_key <key>[/] - Set Google API key (for Google search)
[green]/config google_search_engine_id <id>[/] - Set Google Search Engine ID
[green]/config online on|off[/] - Set default online mode
[green]/config stream on|off[/] - Toggle streaming
[green]/config model <id>[/] - Set default model
[green]/config system <prompt>[/] - Set system prompt
[green]/config maxtoken <num>[/] - Set token limit
[green]/config log <level>[/] - Set log level (debug/info/warning/error/critical)
[bold cyan]Memory & Context[/]
[green]/memory on[/] - Enable conversation memory
[green]/memory off[/] - Disable memory (fresh context each message)
[bold cyan]Conversation Management[/]
[green]/save <name>[/] - Save current conversation
[green]/load <name>[/] - Load saved conversation
[green]/list[/] - List all saved conversations
[green]/delete <name>[/] - Delete a conversation
[green]/prev[/] - Show previous message
[green]/next[/] - Show next message
[bold cyan]Export Commands[/]
[green]/export md <file>[/] - Export conversation as Markdown
[green]/export json <file>[/] - Export as JSON
[green]/export html <file>[/] - Export as HTML
[bold cyan]MCP (Model Context Protocol)[/]
[green]/mcp on[/] - Enable MCP file access
[green]/mcp off[/] - Disable MCP
[green]/mcp status[/] - Show MCP status
[green]/mcp add <path>[/] - Add folder for file access
[green]/mcp add db <path>[/] - Add SQLite database
[green]/mcp remove <path>[/] - Remove folder/database
[green]/mcp list[/] - List allowed folders
[green]/mcp db list[/] - List added databases
[green]/mcp db <n>[/] - Switch to database mode
[green]/mcp files[/] - Switch to file mode
[green]/mcp write on[/] - Enable write mode (allows file modifications)
[green]/mcp write off[/] - Disable write mode
[bold cyan]System Prompt[/]
[green]/system <prompt>[/] - Set custom system prompt for session
[green]/config system <prompt>[/] - Set default system prompt
[bold cyan]Keyboard Shortcuts[/]
• [yellow]F1[/] - Help screen
• [yellow]F2[/] - Model selector
• [yellow]Ctrl+S[/] - Statistics
• [yellow]Ctrl+Q[/] - Quit
• [yellow]Ctrl+Y[/] - Copy latest reply in Markdown
• [yellow]Up/Down[/] - Command history
• [yellow]Tab[/] - Command completion
"""
def on_button_pressed(self, event: Button.Pressed) -> None:
"""Handle button press."""
self.dismiss()
def on_key(self, event) -> None:
"""Handle keyboard shortcuts."""
if event.key in ("escape", "enter"):
self.dismiss()