code-puppy 0.0.169__py3-none-any.whl → 0.0.366__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- code_puppy/__init__.py +7 -1
- code_puppy/agents/__init__.py +8 -8
- code_puppy/agents/agent_c_reviewer.py +155 -0
- code_puppy/agents/agent_code_puppy.py +9 -2
- code_puppy/agents/agent_code_reviewer.py +90 -0
- code_puppy/agents/agent_cpp_reviewer.py +132 -0
- code_puppy/agents/agent_creator_agent.py +48 -9
- code_puppy/agents/agent_golang_reviewer.py +151 -0
- code_puppy/agents/agent_javascript_reviewer.py +160 -0
- code_puppy/agents/agent_manager.py +146 -199
- code_puppy/agents/agent_pack_leader.py +383 -0
- code_puppy/agents/agent_planning.py +163 -0
- code_puppy/agents/agent_python_programmer.py +165 -0
- code_puppy/agents/agent_python_reviewer.py +90 -0
- code_puppy/agents/agent_qa_expert.py +163 -0
- code_puppy/agents/agent_qa_kitten.py +208 -0
- code_puppy/agents/agent_security_auditor.py +181 -0
- code_puppy/agents/agent_terminal_qa.py +323 -0
- code_puppy/agents/agent_typescript_reviewer.py +166 -0
- code_puppy/agents/base_agent.py +1713 -1
- code_puppy/agents/event_stream_handler.py +350 -0
- code_puppy/agents/json_agent.py +12 -1
- code_puppy/agents/pack/__init__.py +34 -0
- code_puppy/agents/pack/bloodhound.py +304 -0
- code_puppy/agents/pack/husky.py +321 -0
- code_puppy/agents/pack/retriever.py +393 -0
- code_puppy/agents/pack/shepherd.py +348 -0
- code_puppy/agents/pack/terrier.py +287 -0
- code_puppy/agents/pack/watchdog.py +367 -0
- code_puppy/agents/prompt_reviewer.py +145 -0
- code_puppy/agents/subagent_stream_handler.py +276 -0
- code_puppy/api/__init__.py +13 -0
- code_puppy/api/app.py +169 -0
- code_puppy/api/main.py +21 -0
- code_puppy/api/pty_manager.py +446 -0
- code_puppy/api/routers/__init__.py +12 -0
- code_puppy/api/routers/agents.py +36 -0
- code_puppy/api/routers/commands.py +217 -0
- code_puppy/api/routers/config.py +74 -0
- code_puppy/api/routers/sessions.py +232 -0
- code_puppy/api/templates/terminal.html +361 -0
- code_puppy/api/websocket.py +154 -0
- code_puppy/callbacks.py +174 -4
- code_puppy/chatgpt_codex_client.py +283 -0
- code_puppy/claude_cache_client.py +586 -0
- code_puppy/cli_runner.py +916 -0
- code_puppy/command_line/add_model_menu.py +1079 -0
- code_puppy/command_line/agent_menu.py +395 -0
- code_puppy/command_line/attachments.py +395 -0
- code_puppy/command_line/autosave_menu.py +605 -0
- code_puppy/command_line/clipboard.py +527 -0
- code_puppy/command_line/colors_menu.py +520 -0
- code_puppy/command_line/command_handler.py +233 -627
- code_puppy/command_line/command_registry.py +150 -0
- code_puppy/command_line/config_commands.py +715 -0
- code_puppy/command_line/core_commands.py +792 -0
- code_puppy/command_line/diff_menu.py +863 -0
- code_puppy/command_line/load_context_completion.py +15 -22
- code_puppy/command_line/mcp/base.py +1 -4
- code_puppy/command_line/mcp/catalog_server_installer.py +175 -0
- code_puppy/command_line/mcp/custom_server_form.py +688 -0
- code_puppy/command_line/mcp/custom_server_installer.py +195 -0
- code_puppy/command_line/mcp/edit_command.py +148 -0
- code_puppy/command_line/mcp/handler.py +9 -4
- code_puppy/command_line/mcp/help_command.py +6 -5
- code_puppy/command_line/mcp/install_command.py +16 -27
- code_puppy/command_line/mcp/install_menu.py +685 -0
- code_puppy/command_line/mcp/list_command.py +3 -3
- code_puppy/command_line/mcp/logs_command.py +174 -65
- code_puppy/command_line/mcp/remove_command.py +2 -2
- code_puppy/command_line/mcp/restart_command.py +12 -4
- code_puppy/command_line/mcp/search_command.py +17 -11
- code_puppy/command_line/mcp/start_all_command.py +22 -13
- code_puppy/command_line/mcp/start_command.py +50 -31
- code_puppy/command_line/mcp/status_command.py +6 -7
- code_puppy/command_line/mcp/stop_all_command.py +11 -8
- code_puppy/command_line/mcp/stop_command.py +11 -10
- code_puppy/command_line/mcp/test_command.py +2 -2
- code_puppy/command_line/mcp/utils.py +1 -1
- code_puppy/command_line/mcp/wizard_utils.py +22 -18
- code_puppy/command_line/mcp_completion.py +174 -0
- code_puppy/command_line/model_picker_completion.py +89 -30
- code_puppy/command_line/model_settings_menu.py +884 -0
- code_puppy/command_line/motd.py +14 -8
- code_puppy/command_line/onboarding_slides.py +179 -0
- code_puppy/command_line/onboarding_wizard.py +340 -0
- code_puppy/command_line/pin_command_completion.py +329 -0
- code_puppy/command_line/prompt_toolkit_completion.py +626 -75
- code_puppy/command_line/session_commands.py +296 -0
- code_puppy/command_line/utils.py +54 -0
- code_puppy/config.py +1181 -51
- code_puppy/error_logging.py +118 -0
- code_puppy/gemini_code_assist.py +385 -0
- code_puppy/gemini_model.py +602 -0
- code_puppy/http_utils.py +220 -104
- code_puppy/keymap.py +128 -0
- code_puppy/main.py +5 -594
- code_puppy/{mcp → mcp_}/__init__.py +17 -0
- code_puppy/{mcp → mcp_}/async_lifecycle.py +35 -4
- code_puppy/{mcp → mcp_}/blocking_startup.py +70 -43
- code_puppy/{mcp → mcp_}/captured_stdio_server.py +2 -2
- code_puppy/{mcp → mcp_}/config_wizard.py +5 -5
- code_puppy/{mcp → mcp_}/dashboard.py +15 -6
- code_puppy/{mcp → mcp_}/examples/retry_example.py +4 -1
- code_puppy/{mcp → mcp_}/managed_server.py +66 -39
- code_puppy/{mcp → mcp_}/manager.py +146 -52
- code_puppy/mcp_/mcp_logs.py +224 -0
- code_puppy/{mcp → mcp_}/registry.py +6 -6
- code_puppy/{mcp → mcp_}/server_registry_catalog.py +25 -8
- code_puppy/messaging/__init__.py +199 -2
- code_puppy/messaging/bus.py +610 -0
- code_puppy/messaging/commands.py +167 -0
- code_puppy/messaging/markdown_patches.py +57 -0
- code_puppy/messaging/message_queue.py +17 -48
- code_puppy/messaging/messages.py +500 -0
- code_puppy/messaging/queue_console.py +1 -24
- code_puppy/messaging/renderers.py +43 -146
- code_puppy/messaging/rich_renderer.py +1027 -0
- code_puppy/messaging/spinner/__init__.py +33 -5
- code_puppy/messaging/spinner/console_spinner.py +92 -52
- code_puppy/messaging/spinner/spinner_base.py +29 -0
- code_puppy/messaging/subagent_console.py +461 -0
- code_puppy/model_factory.py +686 -80
- code_puppy/model_utils.py +167 -0
- code_puppy/models.json +86 -104
- code_puppy/models_dev_api.json +1 -0
- code_puppy/models_dev_parser.py +592 -0
- code_puppy/plugins/__init__.py +164 -10
- code_puppy/plugins/antigravity_oauth/__init__.py +10 -0
- code_puppy/plugins/antigravity_oauth/accounts.py +406 -0
- code_puppy/plugins/antigravity_oauth/antigravity_model.py +704 -0
- code_puppy/plugins/antigravity_oauth/config.py +42 -0
- code_puppy/plugins/antigravity_oauth/constants.py +136 -0
- code_puppy/plugins/antigravity_oauth/oauth.py +478 -0
- code_puppy/plugins/antigravity_oauth/register_callbacks.py +406 -0
- code_puppy/plugins/antigravity_oauth/storage.py +271 -0
- code_puppy/plugins/antigravity_oauth/test_plugin.py +319 -0
- code_puppy/plugins/antigravity_oauth/token.py +167 -0
- code_puppy/plugins/antigravity_oauth/transport.py +767 -0
- code_puppy/plugins/antigravity_oauth/utils.py +169 -0
- code_puppy/plugins/chatgpt_oauth/__init__.py +8 -0
- code_puppy/plugins/chatgpt_oauth/config.py +52 -0
- code_puppy/plugins/chatgpt_oauth/oauth_flow.py +328 -0
- code_puppy/plugins/chatgpt_oauth/register_callbacks.py +94 -0
- code_puppy/plugins/chatgpt_oauth/test_plugin.py +293 -0
- code_puppy/plugins/chatgpt_oauth/utils.py +489 -0
- code_puppy/plugins/claude_code_oauth/README.md +167 -0
- code_puppy/plugins/claude_code_oauth/SETUP.md +93 -0
- code_puppy/plugins/claude_code_oauth/__init__.py +6 -0
- code_puppy/plugins/claude_code_oauth/config.py +50 -0
- code_puppy/plugins/claude_code_oauth/register_callbacks.py +308 -0
- code_puppy/plugins/claude_code_oauth/test_plugin.py +283 -0
- code_puppy/plugins/claude_code_oauth/utils.py +518 -0
- code_puppy/plugins/customizable_commands/__init__.py +0 -0
- code_puppy/plugins/customizable_commands/register_callbacks.py +169 -0
- code_puppy/plugins/example_custom_command/README.md +280 -0
- code_puppy/plugins/example_custom_command/register_callbacks.py +51 -0
- code_puppy/plugins/file_permission_handler/__init__.py +4 -0
- code_puppy/plugins/file_permission_handler/register_callbacks.py +523 -0
- code_puppy/plugins/frontend_emitter/__init__.py +25 -0
- code_puppy/plugins/frontend_emitter/emitter.py +121 -0
- code_puppy/plugins/frontend_emitter/register_callbacks.py +261 -0
- code_puppy/plugins/oauth_puppy_html.py +228 -0
- code_puppy/plugins/shell_safety/__init__.py +6 -0
- code_puppy/plugins/shell_safety/agent_shell_safety.py +69 -0
- code_puppy/plugins/shell_safety/command_cache.py +156 -0
- code_puppy/plugins/shell_safety/register_callbacks.py +202 -0
- code_puppy/prompts/antigravity_system_prompt.md +1 -0
- code_puppy/prompts/codex_system_prompt.md +310 -0
- code_puppy/pydantic_patches.py +131 -0
- code_puppy/reopenable_async_client.py +8 -8
- code_puppy/round_robin_model.py +10 -15
- code_puppy/session_storage.py +294 -0
- code_puppy/status_display.py +21 -4
- code_puppy/summarization_agent.py +52 -14
- code_puppy/terminal_utils.py +418 -0
- code_puppy/tools/__init__.py +139 -6
- code_puppy/tools/agent_tools.py +548 -49
- code_puppy/tools/browser/__init__.py +37 -0
- code_puppy/tools/browser/browser_control.py +289 -0
- code_puppy/tools/browser/browser_interactions.py +545 -0
- code_puppy/tools/browser/browser_locators.py +640 -0
- code_puppy/tools/browser/browser_manager.py +316 -0
- code_puppy/tools/browser/browser_navigation.py +251 -0
- code_puppy/tools/browser/browser_screenshot.py +179 -0
- code_puppy/tools/browser/browser_scripts.py +462 -0
- code_puppy/tools/browser/browser_workflows.py +221 -0
- code_puppy/tools/browser/chromium_terminal_manager.py +259 -0
- code_puppy/tools/browser/terminal_command_tools.py +521 -0
- code_puppy/tools/browser/terminal_screenshot_tools.py +556 -0
- code_puppy/tools/browser/terminal_tools.py +525 -0
- code_puppy/tools/command_runner.py +941 -153
- code_puppy/tools/common.py +1146 -6
- code_puppy/tools/display.py +84 -0
- code_puppy/tools/file_modifications.py +288 -89
- code_puppy/tools/file_operations.py +352 -266
- code_puppy/tools/subagent_context.py +158 -0
- code_puppy/uvx_detection.py +242 -0
- code_puppy/version_checker.py +30 -11
- code_puppy-0.0.366.data/data/code_puppy/models.json +110 -0
- code_puppy-0.0.366.data/data/code_puppy/models_dev_api.json +1 -0
- {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/METADATA +184 -67
- code_puppy-0.0.366.dist-info/RECORD +217 -0
- {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/WHEEL +1 -1
- {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/entry_points.txt +1 -0
- code_puppy/agent.py +0 -231
- code_puppy/agents/agent_orchestrator.json +0 -26
- code_puppy/agents/runtime_manager.py +0 -272
- code_puppy/command_line/mcp/add_command.py +0 -183
- code_puppy/command_line/meta_command_handler.py +0 -153
- code_puppy/message_history_processor.py +0 -490
- code_puppy/messaging/spinner/textual_spinner.py +0 -101
- code_puppy/state_management.py +0 -200
- code_puppy/tui/__init__.py +0 -10
- code_puppy/tui/app.py +0 -986
- code_puppy/tui/components/__init__.py +0 -21
- code_puppy/tui/components/chat_view.py +0 -550
- code_puppy/tui/components/command_history_modal.py +0 -218
- code_puppy/tui/components/copy_button.py +0 -139
- code_puppy/tui/components/custom_widgets.py +0 -63
- code_puppy/tui/components/human_input_modal.py +0 -175
- code_puppy/tui/components/input_area.py +0 -167
- code_puppy/tui/components/sidebar.py +0 -309
- code_puppy/tui/components/status_bar.py +0 -182
- code_puppy/tui/messages.py +0 -27
- code_puppy/tui/models/__init__.py +0 -8
- code_puppy/tui/models/chat_message.py +0 -25
- code_puppy/tui/models/command_history.py +0 -89
- code_puppy/tui/models/enums.py +0 -24
- code_puppy/tui/screens/__init__.py +0 -15
- code_puppy/tui/screens/help.py +0 -130
- code_puppy/tui/screens/mcp_install_wizard.py +0 -803
- code_puppy/tui/screens/settings.py +0 -290
- code_puppy/tui/screens/tools.py +0 -74
- code_puppy-0.0.169.data/data/code_puppy/models.json +0 -128
- code_puppy-0.0.169.dist-info/RECORD +0 -112
- /code_puppy/{mcp → mcp_}/circuit_breaker.py +0 -0
- /code_puppy/{mcp → mcp_}/error_isolation.py +0 -0
- /code_puppy/{mcp → mcp_}/health_monitor.py +0 -0
- /code_puppy/{mcp → mcp_}/retry_manager.py +0 -0
- /code_puppy/{mcp → mcp_}/status_tracker.py +0 -0
- /code_puppy/{mcp → mcp_}/system_tools.py +0 -0
- {code_puppy-0.0.169.dist-info → code_puppy-0.0.366.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
"""Interactive TUI for configuring banner colors.
|
|
2
|
+
|
|
3
|
+
Similar to diff_menu.py but for customizing the banner background colors
|
|
4
|
+
for different tool outputs (THINKING, SHELL COMMAND, READ FILE, etc.).
|
|
5
|
+
|
|
6
|
+
Use /colors to launch the TUI and customize your banners!
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import io
|
|
10
|
+
import sys
|
|
11
|
+
import time
|
|
12
|
+
from typing import Callable, Optional
|
|
13
|
+
|
|
14
|
+
from prompt_toolkit import Application
|
|
15
|
+
from prompt_toolkit.formatted_text import ANSI, FormattedText
|
|
16
|
+
from prompt_toolkit.key_binding import KeyBindings
|
|
17
|
+
from prompt_toolkit.layout import Layout, VSplit, Window
|
|
18
|
+
from prompt_toolkit.layout.controls import FormattedTextControl
|
|
19
|
+
from prompt_toolkit.widgets import Frame
|
|
20
|
+
from rich.console import Console
|
|
21
|
+
|
|
22
|
+
# Banner display names with icons
|
|
23
|
+
BANNER_DISPLAY_INFO = {
|
|
24
|
+
"thinking": ("THINKING", "⚡"),
|
|
25
|
+
"agent_response": ("AGENT RESPONSE", ""),
|
|
26
|
+
"shell_command": ("SHELL COMMAND", "🚀"),
|
|
27
|
+
"read_file": ("READ FILE", "📂"),
|
|
28
|
+
"edit_file": ("EDIT FILE", "✏️"),
|
|
29
|
+
"grep": ("GREP", "📂"),
|
|
30
|
+
"directory_listing": ("DIRECTORY LISTING", "📂"),
|
|
31
|
+
"agent_reasoning": ("AGENT REASONING", ""),
|
|
32
|
+
"invoke_agent": ("🤖 INVOKE AGENT", ""),
|
|
33
|
+
"subagent_response": ("✓ AGENT RESPONSE", ""),
|
|
34
|
+
"list_agents": ("LIST AGENTS", ""),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Sample content to show after each banner
|
|
38
|
+
BANNER_SAMPLE_CONTENT = {
|
|
39
|
+
"thinking": "Let me analyze this code structure and figure out the best approach...",
|
|
40
|
+
"agent_response": "I've implemented the feature you requested. The changes include...",
|
|
41
|
+
"shell_command": "$ npm run test -- --silent\n⏱ Timeout: 60s",
|
|
42
|
+
"read_file": "/path/to/file.py (lines 1-50)",
|
|
43
|
+
"edit_file": "MODIFY /path/to/file.py\n--- a/file.py\n+++ b/file.py",
|
|
44
|
+
"grep": "/src for 'handleClick'\n📄 Button.tsx (3 matches)",
|
|
45
|
+
"directory_listing": "/src (recursive=True)\n📁 components/\n └── Button.tsx",
|
|
46
|
+
"agent_reasoning": "Current reasoning:\nI need to refactor this function...",
|
|
47
|
+
"invoke_agent": "code-reviewer (New session)\nSession: review-auth-abc123",
|
|
48
|
+
"subagent_response": "code-reviewer\nThe code looks good overall...",
|
|
49
|
+
"list_agents": "- code-puppy: Code Puppy 🐶\n- planning-agent: Planning Agent",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Available background colors grouped by theme
|
|
53
|
+
BANNER_COLORS = {
|
|
54
|
+
# Cool colors
|
|
55
|
+
"blue": "blue",
|
|
56
|
+
"dark blue": "dark_blue",
|
|
57
|
+
"navy blue": "navy_blue",
|
|
58
|
+
"deep sky blue": "deep_sky_blue4",
|
|
59
|
+
"steel blue": "steel_blue",
|
|
60
|
+
"dodger blue": "dodger_blue3",
|
|
61
|
+
# Cyans & Teals
|
|
62
|
+
"dark cyan": "dark_cyan",
|
|
63
|
+
"cyan": "cyan4",
|
|
64
|
+
"teal": "dark_turquoise",
|
|
65
|
+
"aquamarine": "aquamarine1",
|
|
66
|
+
# Greens
|
|
67
|
+
"green": "green4",
|
|
68
|
+
"dark green": "dark_green",
|
|
69
|
+
"sea green": "dark_sea_green4",
|
|
70
|
+
"spring green": "spring_green4",
|
|
71
|
+
"chartreuse": "chartreuse4",
|
|
72
|
+
# Purples & Magentas
|
|
73
|
+
"purple": "purple",
|
|
74
|
+
"dark magenta": "dark_magenta",
|
|
75
|
+
"medium purple": "medium_purple4",
|
|
76
|
+
"dark violet": "dark_violet",
|
|
77
|
+
"plum": "plum4",
|
|
78
|
+
"orchid": "dark_orchid",
|
|
79
|
+
# Reds & Oranges
|
|
80
|
+
"red": "red3",
|
|
81
|
+
"dark red": "dark_red",
|
|
82
|
+
"indian red": "indian_red",
|
|
83
|
+
"orange red": "orange_red1",
|
|
84
|
+
"orange": "dark_orange3",
|
|
85
|
+
# Yellows & Golds
|
|
86
|
+
"gold": "gold3",
|
|
87
|
+
"dark goldenrod": "dark_goldenrod",
|
|
88
|
+
"olive": "dark_olive_green3",
|
|
89
|
+
# Grays
|
|
90
|
+
"grey30": "grey30",
|
|
91
|
+
"grey37": "grey37",
|
|
92
|
+
"grey42": "grey42",
|
|
93
|
+
"grey50": "grey50",
|
|
94
|
+
"grey58": "grey58",
|
|
95
|
+
"dark slate gray": "dark_slate_gray3",
|
|
96
|
+
# Pink tones
|
|
97
|
+
"hot pink": "hot_pink3",
|
|
98
|
+
"deep pink": "deep_pink4",
|
|
99
|
+
"pale violet red": "pale_violet_red1",
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class ColorConfiguration:
|
|
104
|
+
"""Holds the current banner color configuration state."""
|
|
105
|
+
|
|
106
|
+
def __init__(self):
|
|
107
|
+
"""Initialize configuration from current settings."""
|
|
108
|
+
from code_puppy.config import get_all_banner_colors
|
|
109
|
+
|
|
110
|
+
self.current_colors = get_all_banner_colors()
|
|
111
|
+
self.original_colors = self.current_colors.copy()
|
|
112
|
+
self.selected_banner_index = 0
|
|
113
|
+
self.banner_keys = list(BANNER_DISPLAY_INFO.keys())
|
|
114
|
+
|
|
115
|
+
def has_changes(self) -> bool:
|
|
116
|
+
"""Check if any changes have been made."""
|
|
117
|
+
return self.current_colors != self.original_colors
|
|
118
|
+
|
|
119
|
+
def get_current_banner_key(self) -> str:
|
|
120
|
+
"""Get the currently selected banner key."""
|
|
121
|
+
return self.banner_keys[self.selected_banner_index]
|
|
122
|
+
|
|
123
|
+
def get_current_banner_color(self) -> str:
|
|
124
|
+
"""Get the color of the currently selected banner."""
|
|
125
|
+
return self.current_colors[self.get_current_banner_key()]
|
|
126
|
+
|
|
127
|
+
def set_current_banner_color(self, color: str):
|
|
128
|
+
"""Set the color of the currently selected banner."""
|
|
129
|
+
self.current_colors[self.get_current_banner_key()] = color
|
|
130
|
+
|
|
131
|
+
def next_banner(self):
|
|
132
|
+
"""Cycle to the next banner."""
|
|
133
|
+
self.selected_banner_index = (self.selected_banner_index + 1) % len(
|
|
134
|
+
self.banner_keys
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
def prev_banner(self):
|
|
138
|
+
"""Cycle to the previous banner."""
|
|
139
|
+
self.selected_banner_index = (self.selected_banner_index - 1) % len(
|
|
140
|
+
self.banner_keys
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
async def interactive_colors_picker() -> Optional[dict]:
|
|
145
|
+
"""Show an interactive full-screen terminal UI to configure banner colors.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
A dict with changes or None if cancelled
|
|
149
|
+
"""
|
|
150
|
+
from code_puppy.tools.command_runner import set_awaiting_user_input
|
|
151
|
+
|
|
152
|
+
config = ColorConfiguration()
|
|
153
|
+
|
|
154
|
+
set_awaiting_user_input(True)
|
|
155
|
+
|
|
156
|
+
# Enter alternate screen buffer once for entire session
|
|
157
|
+
sys.stdout.write("\033[?1049h") # Enter alternate buffer
|
|
158
|
+
sys.stdout.write("\033[2J\033[H") # Clear and home
|
|
159
|
+
sys.stdout.flush()
|
|
160
|
+
time.sleep(0.1) # Minimal delay for state sync
|
|
161
|
+
|
|
162
|
+
try:
|
|
163
|
+
# Main menu loop
|
|
164
|
+
while True:
|
|
165
|
+
choices = []
|
|
166
|
+
for key in config.banner_keys:
|
|
167
|
+
display_name, icon = BANNER_DISPLAY_INFO[key]
|
|
168
|
+
current_color = config.current_colors[key]
|
|
169
|
+
choices.append(f"{display_name} [{current_color}]")
|
|
170
|
+
|
|
171
|
+
# Add action items
|
|
172
|
+
if config.has_changes():
|
|
173
|
+
choices.append("─── Actions ───")
|
|
174
|
+
choices.append("💾 Save & Exit")
|
|
175
|
+
choices.append("🔄 Reset All to Defaults")
|
|
176
|
+
choices.append("❌ Discard & Exit")
|
|
177
|
+
else:
|
|
178
|
+
choices.append("─── Actions ───")
|
|
179
|
+
choices.append("🔄 Reset All to Defaults")
|
|
180
|
+
choices.append("❌ Exit")
|
|
181
|
+
|
|
182
|
+
def dummy_update(choice: str):
|
|
183
|
+
pass
|
|
184
|
+
|
|
185
|
+
def get_main_preview():
|
|
186
|
+
return _get_preview_text_for_prompt_toolkit(config)
|
|
187
|
+
|
|
188
|
+
try:
|
|
189
|
+
selected = await _split_panel_selector(
|
|
190
|
+
"Banner Color Configuration",
|
|
191
|
+
choices,
|
|
192
|
+
dummy_update,
|
|
193
|
+
get_preview=get_main_preview,
|
|
194
|
+
config=config,
|
|
195
|
+
)
|
|
196
|
+
except KeyboardInterrupt:
|
|
197
|
+
break
|
|
198
|
+
|
|
199
|
+
# Handle selection
|
|
200
|
+
if selected is None:
|
|
201
|
+
break
|
|
202
|
+
elif "Save & Exit" in selected:
|
|
203
|
+
break
|
|
204
|
+
elif "Reset All" in selected:
|
|
205
|
+
from code_puppy.config import DEFAULT_BANNER_COLORS
|
|
206
|
+
|
|
207
|
+
config.current_colors = DEFAULT_BANNER_COLORS.copy()
|
|
208
|
+
elif "Discard" in selected or selected == "❌ Exit":
|
|
209
|
+
config.current_colors = config.original_colors.copy()
|
|
210
|
+
break
|
|
211
|
+
elif "───" in selected:
|
|
212
|
+
# Separator - do nothing
|
|
213
|
+
pass
|
|
214
|
+
else:
|
|
215
|
+
# A banner was selected - show color picker
|
|
216
|
+
# Find which banner was selected
|
|
217
|
+
for i, key in enumerate(config.banner_keys):
|
|
218
|
+
display_name, _ = BANNER_DISPLAY_INFO[key]
|
|
219
|
+
if selected.startswith(display_name):
|
|
220
|
+
config.selected_banner_index = i
|
|
221
|
+
await _handle_color_menu(config)
|
|
222
|
+
break
|
|
223
|
+
|
|
224
|
+
except Exception:
|
|
225
|
+
# Silent error - just exit cleanly
|
|
226
|
+
return None
|
|
227
|
+
finally:
|
|
228
|
+
set_awaiting_user_input(False)
|
|
229
|
+
# Exit alternate screen buffer once at end
|
|
230
|
+
sys.stdout.write("\033[?1049l") # Exit alternate buffer
|
|
231
|
+
sys.stdout.flush()
|
|
232
|
+
|
|
233
|
+
# Clear exit message
|
|
234
|
+
from code_puppy.messaging import emit_info
|
|
235
|
+
|
|
236
|
+
emit_info("✓ Exited banner color configuration")
|
|
237
|
+
|
|
238
|
+
# Return changes if any
|
|
239
|
+
if config.has_changes():
|
|
240
|
+
return config.current_colors
|
|
241
|
+
|
|
242
|
+
return None
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
async def _split_panel_selector(
|
|
246
|
+
title: str,
|
|
247
|
+
choices: list[str],
|
|
248
|
+
on_change: Callable[[str], None],
|
|
249
|
+
get_preview: Callable[[], ANSI],
|
|
250
|
+
config: Optional[ColorConfiguration] = None,
|
|
251
|
+
) -> Optional[str]:
|
|
252
|
+
"""Split-panel selector with menu on left and live preview on right."""
|
|
253
|
+
selected_index = [0]
|
|
254
|
+
result = [None]
|
|
255
|
+
|
|
256
|
+
def get_left_panel_text():
|
|
257
|
+
"""Generate the selector menu text."""
|
|
258
|
+
try:
|
|
259
|
+
lines = []
|
|
260
|
+
lines.append(("bold cyan", title))
|
|
261
|
+
lines.append(("", "\n\n"))
|
|
262
|
+
|
|
263
|
+
if not choices:
|
|
264
|
+
lines.append(("fg:ansiyellow", "No choices available"))
|
|
265
|
+
lines.append(("", "\n"))
|
|
266
|
+
else:
|
|
267
|
+
for i, choice in enumerate(choices):
|
|
268
|
+
# Skip separator lines for selection highlighting
|
|
269
|
+
if "───" in choice:
|
|
270
|
+
lines.append(("fg:ansigray", f" {choice}"))
|
|
271
|
+
lines.append(("", "\n"))
|
|
272
|
+
elif i == selected_index[0]:
|
|
273
|
+
lines.append(("fg:ansigreen", "▶ "))
|
|
274
|
+
lines.append(("fg:ansigreen bold", choice))
|
|
275
|
+
lines.append(("", "\n"))
|
|
276
|
+
else:
|
|
277
|
+
lines.append(("", " "))
|
|
278
|
+
lines.append(("", choice))
|
|
279
|
+
lines.append(("", "\n"))
|
|
280
|
+
|
|
281
|
+
lines.append(("", "\n"))
|
|
282
|
+
lines.append(
|
|
283
|
+
("fg:ansicyan", "↑↓ Navigate │ Enter Select │ Ctrl-C Cancel")
|
|
284
|
+
)
|
|
285
|
+
return FormattedText(lines)
|
|
286
|
+
except Exception as e:
|
|
287
|
+
return FormattedText([("fg:ansired", f"Error: {e}")])
|
|
288
|
+
|
|
289
|
+
def get_right_panel_text():
|
|
290
|
+
"""Generate the preview panel text."""
|
|
291
|
+
try:
|
|
292
|
+
preview = get_preview()
|
|
293
|
+
return preview
|
|
294
|
+
except Exception as e:
|
|
295
|
+
return FormattedText([("fg:ansired", f"Preview error: {e}")])
|
|
296
|
+
|
|
297
|
+
kb = KeyBindings()
|
|
298
|
+
|
|
299
|
+
@kb.add("up")
|
|
300
|
+
def move_up(event):
|
|
301
|
+
if choices:
|
|
302
|
+
# Skip separator lines
|
|
303
|
+
new_idx = (selected_index[0] - 1) % len(choices)
|
|
304
|
+
while "───" in choices[new_idx]:
|
|
305
|
+
new_idx = (new_idx - 1) % len(choices)
|
|
306
|
+
selected_index[0] = new_idx
|
|
307
|
+
on_change(choices[selected_index[0]])
|
|
308
|
+
event.app.invalidate()
|
|
309
|
+
|
|
310
|
+
@kb.add("down")
|
|
311
|
+
def move_down(event):
|
|
312
|
+
if choices:
|
|
313
|
+
# Skip separator lines
|
|
314
|
+
new_idx = (selected_index[0] + 1) % len(choices)
|
|
315
|
+
while "───" in choices[new_idx]:
|
|
316
|
+
new_idx = (new_idx + 1) % len(choices)
|
|
317
|
+
selected_index[0] = new_idx
|
|
318
|
+
on_change(choices[selected_index[0]])
|
|
319
|
+
event.app.invalidate()
|
|
320
|
+
|
|
321
|
+
@kb.add("enter")
|
|
322
|
+
def accept(event):
|
|
323
|
+
if choices:
|
|
324
|
+
result[0] = choices[selected_index[0]]
|
|
325
|
+
else:
|
|
326
|
+
result[0] = None
|
|
327
|
+
event.app.exit()
|
|
328
|
+
|
|
329
|
+
@kb.add("c-c")
|
|
330
|
+
def cancel(event):
|
|
331
|
+
result[0] = None
|
|
332
|
+
event.app.exit()
|
|
333
|
+
|
|
334
|
+
# Create split layout with left (selector) and right (preview) panels
|
|
335
|
+
left_panel = Window(
|
|
336
|
+
content=FormattedTextControl(lambda: get_left_panel_text()),
|
|
337
|
+
width=45,
|
|
338
|
+
)
|
|
339
|
+
|
|
340
|
+
right_panel = Window(
|
|
341
|
+
content=FormattedTextControl(lambda: get_right_panel_text()),
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
# Create vertical split (side-by-side panels)
|
|
345
|
+
root_container = VSplit(
|
|
346
|
+
[
|
|
347
|
+
Frame(left_panel, title="Menu"),
|
|
348
|
+
Frame(right_panel, title="Preview"),
|
|
349
|
+
]
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
layout = Layout(root_container)
|
|
353
|
+
app = Application(
|
|
354
|
+
layout=layout,
|
|
355
|
+
key_bindings=kb,
|
|
356
|
+
full_screen=False,
|
|
357
|
+
mouse_support=False,
|
|
358
|
+
color_depth="DEPTH_24_BIT",
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
sys.stdout.flush()
|
|
362
|
+
|
|
363
|
+
# Trigger initial update only if choices is not empty
|
|
364
|
+
if choices:
|
|
365
|
+
on_change(choices[selected_index[0]])
|
|
366
|
+
|
|
367
|
+
# Clear the current buffer
|
|
368
|
+
sys.stdout.write("\033[2J\033[H")
|
|
369
|
+
sys.stdout.flush()
|
|
370
|
+
|
|
371
|
+
# Run application
|
|
372
|
+
await app.run_async()
|
|
373
|
+
|
|
374
|
+
if result[0] is None:
|
|
375
|
+
raise KeyboardInterrupt()
|
|
376
|
+
|
|
377
|
+
return result[0]
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _get_preview_text_for_prompt_toolkit(config: ColorConfiguration) -> ANSI:
|
|
381
|
+
"""Get preview as ANSI for embedding in selector with live colors.
|
|
382
|
+
|
|
383
|
+
Returns ANSI-formatted text that prompt_toolkit can render with full colors.
|
|
384
|
+
"""
|
|
385
|
+
# Build preview showing all banners with their current colors
|
|
386
|
+
buffer = io.StringIO()
|
|
387
|
+
console = Console(
|
|
388
|
+
file=buffer,
|
|
389
|
+
force_terminal=True,
|
|
390
|
+
width=70,
|
|
391
|
+
legacy_windows=False,
|
|
392
|
+
color_system="truecolor",
|
|
393
|
+
no_color=False,
|
|
394
|
+
force_interactive=True,
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
# Header
|
|
398
|
+
console.print("[bold]═" * 60 + "[/bold]")
|
|
399
|
+
console.print("[bold cyan] LIVE PREVIEW - Banner Colors[/bold cyan]")
|
|
400
|
+
console.print("[bold]═" * 60 + "[/bold]")
|
|
401
|
+
console.print()
|
|
402
|
+
|
|
403
|
+
# Show each banner with its current color
|
|
404
|
+
for key in config.banner_keys:
|
|
405
|
+
display_name, icon = BANNER_DISPLAY_INFO[key]
|
|
406
|
+
color = config.current_colors[key]
|
|
407
|
+
sample = BANNER_SAMPLE_CONTENT[key]
|
|
408
|
+
|
|
409
|
+
# Highlight the currently selected banner
|
|
410
|
+
is_selected = key == config.get_current_banner_key()
|
|
411
|
+
if is_selected:
|
|
412
|
+
console.print("[bold yellow]▶[/bold yellow] ", end="")
|
|
413
|
+
else:
|
|
414
|
+
console.print(" ", end="")
|
|
415
|
+
|
|
416
|
+
# Print the banner with its configured color
|
|
417
|
+
icon_str = f" {icon}" if icon else ""
|
|
418
|
+
banner_text = (
|
|
419
|
+
f"[bold white on {color}] {display_name} [/bold white on {color}]{icon_str}"
|
|
420
|
+
)
|
|
421
|
+
console.print(banner_text)
|
|
422
|
+
|
|
423
|
+
# Print sample content (dimmed)
|
|
424
|
+
sample_lines = sample.split("\n")
|
|
425
|
+
for line in sample_lines[:2]: # Only show first 2 lines
|
|
426
|
+
if is_selected:
|
|
427
|
+
console.print(f" [dim]{line}[/dim]")
|
|
428
|
+
else:
|
|
429
|
+
console.print(f" [dim]{line}[/dim]")
|
|
430
|
+
console.print()
|
|
431
|
+
|
|
432
|
+
console.print("[bold]═" * 60 + "[/bold]")
|
|
433
|
+
|
|
434
|
+
ansi_output = buffer.getvalue()
|
|
435
|
+
return ANSI(ansi_output)
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
async def _handle_color_menu(config: ColorConfiguration) -> None:
|
|
439
|
+
"""Handle color selection for the current banner."""
|
|
440
|
+
banner_key = config.get_current_banner_key()
|
|
441
|
+
display_name, _ = BANNER_DISPLAY_INFO[banner_key]
|
|
442
|
+
current_color = config.get_current_banner_color()
|
|
443
|
+
title = f"Select color for {display_name}:"
|
|
444
|
+
|
|
445
|
+
# Build choices with color names
|
|
446
|
+
choices = []
|
|
447
|
+
for name, color_value in BANNER_COLORS.items():
|
|
448
|
+
marker = " ← current" if color_value == current_color else ""
|
|
449
|
+
choices.append(f"{name}{marker}")
|
|
450
|
+
|
|
451
|
+
# Store original color for potential cancellation
|
|
452
|
+
original_color = current_color
|
|
453
|
+
|
|
454
|
+
# Callback for live preview updates
|
|
455
|
+
def update_preview(selected_choice: str):
|
|
456
|
+
color_name = selected_choice.replace(" ← current", "").strip()
|
|
457
|
+
selected_color = BANNER_COLORS.get(color_name, "blue")
|
|
458
|
+
config.set_current_banner_color(selected_color)
|
|
459
|
+
|
|
460
|
+
def get_preview_header():
|
|
461
|
+
return _get_single_banner_preview(config)
|
|
462
|
+
|
|
463
|
+
try:
|
|
464
|
+
await _split_panel_selector(
|
|
465
|
+
title,
|
|
466
|
+
choices,
|
|
467
|
+
update_preview,
|
|
468
|
+
get_preview=get_preview_header,
|
|
469
|
+
config=config,
|
|
470
|
+
)
|
|
471
|
+
except KeyboardInterrupt:
|
|
472
|
+
# Restore original color on cancel
|
|
473
|
+
config.set_current_banner_color(original_color)
|
|
474
|
+
except Exception:
|
|
475
|
+
pass # Silent error handling
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def _get_single_banner_preview(config: ColorConfiguration) -> ANSI:
|
|
479
|
+
"""Get preview for a single banner being edited."""
|
|
480
|
+
buffer = io.StringIO()
|
|
481
|
+
console = Console(
|
|
482
|
+
file=buffer,
|
|
483
|
+
force_terminal=True,
|
|
484
|
+
width=70,
|
|
485
|
+
legacy_windows=False,
|
|
486
|
+
color_system="truecolor",
|
|
487
|
+
no_color=False,
|
|
488
|
+
force_interactive=True,
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
banner_key = config.get_current_banner_key()
|
|
492
|
+
display_name, icon = BANNER_DISPLAY_INFO[banner_key]
|
|
493
|
+
color = config.get_current_banner_color()
|
|
494
|
+
sample = BANNER_SAMPLE_CONTENT[banner_key]
|
|
495
|
+
|
|
496
|
+
# Header
|
|
497
|
+
console.print("[bold]═" * 60 + "[/bold]")
|
|
498
|
+
console.print(f"[bold cyan] Editing: {display_name}[/bold cyan]")
|
|
499
|
+
console.print(f" Current Color: [bold]{color}[/bold]")
|
|
500
|
+
console.print("[bold]═" * 60 + "[/bold]")
|
|
501
|
+
console.print()
|
|
502
|
+
|
|
503
|
+
# Show the banner large
|
|
504
|
+
icon_str = f" {icon}" if icon else ""
|
|
505
|
+
banner_text = (
|
|
506
|
+
f"[bold white on {color}] {display_name} [/bold white on {color}]{icon_str}"
|
|
507
|
+
)
|
|
508
|
+
console.print(banner_text)
|
|
509
|
+
console.print()
|
|
510
|
+
|
|
511
|
+
# Show sample content
|
|
512
|
+
console.print("[dim]Sample output:[/dim]")
|
|
513
|
+
for line in sample.split("\n"):
|
|
514
|
+
console.print(f"[dim]{line}[/dim]")
|
|
515
|
+
|
|
516
|
+
console.print()
|
|
517
|
+
console.print("[bold]═" * 60 + "[/bold]")
|
|
518
|
+
|
|
519
|
+
ansi_output = buffer.getvalue()
|
|
520
|
+
return ANSI(ansi_output)
|