forked from RenjiYuusei/CursorFocus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
427 lines (360 loc) · 14.4 KB
/
ui.py
File metadata and controls
427 lines (360 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/env python3
import os
import sys
import time
import shutil
from colorama import init, Fore, Back, Style
from rich.console import Console
from rich.panel import Panel
from rich.text import Text
from rich.table import Table
from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TimeElapsedColumn, TaskProgressColumn
from rich.prompt import Prompt, Confirm
from rich.layout import Layout
from rich.live import Live
from rich.markdown import Markdown
from rich.style import Style as RichStyle
from rich.align import Align
from rich.columns import Columns
from rich import box
import keyboard
# Initialize colorama
init(autoreset=True)
# Rich console for improved output
console = Console()
# Define theme colors for consistent UI
class Theme:
"""Modern theme colors and styles for the application."""
PRIMARY = "blue"
SECONDARY = "cyan"
SUCCESS = "green"
WARNING = "yellow"
ERROR = "red"
INFO = "bright_blue"
MUTED = "dim"
ACCENT = "magenta"
PROMPT = "green"
# Compound styles
TITLE = f"bold {PRIMARY}"
SUBTITLE = f"bold {SECONDARY}"
HEADER = f"bold {PRIMARY}"
HIGHLIGHT = f"bold {ACCENT}"
# Panel styles
PANEL_BORDER = PRIMARY
PANEL_TITLE = f"white on {PRIMARY}"
# Table styles
TABLE_HEADER = f"bold {SECONDARY}"
TABLE_BORDER = SECONDARY
# Component styles
BUTTON = f"bold {PRIMARY}"
LINK = f"underline {INFO}"
ICON_SUCCESS = "✓"
ICON_ERROR = "✗"
ICON_WARNING = "⚠"
ICON_INFO = "ℹ"
ICON_ARROW = "→"
ICON_BULLET = "•"
ICON_GEAR = "⚙"
ICON_STAR = "★"
ICON_FOLDER = "📁"
ICON_FILE = "📄"
ICON_CLOCK = "🕒"
ICON_SEARCH = "🔍"
ICON_KEY = "🔑"
ICON_NET = "🌐"
ICON_MONITOR = "📡"
ICON_LOCK = "🔒"
# Legacy colors for backward compatibility
class Colors:
"""Color and style definitions for the classic terminal interface."""
TITLE = Fore.CYAN + Style.BRIGHT
SUBTITLE = Fore.WHITE + Style.BRIGHT
PROMPT = Fore.GREEN + Style.BRIGHT
INFO = Fore.BLUE
SUCCESS = Fore.GREEN
WARNING = Fore.YELLOW
ERROR = Fore.RED
INPUT = Fore.WHITE + Style.BRIGHT
MENU_NUM = Fore.CYAN + Style.BRIGHT
MENU_TEXT = Fore.WHITE
PATH = Fore.MAGENTA
HEADER_BG = Back.BLUE + Fore.WHITE + Style.BRIGHT
ACCENT = Fore.YELLOW + Style.BRIGHT
KEY = Fore.CYAN
VALUE = Fore.WHITE
RESET = Style.RESET_ALL
def clear_screen():
"""Clear the console screen."""
os.system('cls' if os.name == 'nt' else 'clear')
def get_terminal_size():
"""Get terminal dimensions."""
return shutil.get_terminal_size((80, 20))
# ========== Modern UI Functions (using Rich) ==========
def create_title_panel(title, subtitle=None):
"""Create a stylish title panel with modern design."""
if subtitle:
content = f"[{Theme.TITLE}]{title}[/]\n[white]{subtitle}[/]"
else:
content = f"[{Theme.TITLE}]{title}[/]"
return Panel(
content,
border_style=Theme.PANEL_BORDER,
title=f"[{Theme.PANEL_TITLE}] CursorFocus [/]",
title_align="center",
subtitle=f"[{Theme.MUTED}]AI-Powered Context Generator for Cursor IDE[/]",
subtitle_align="center",
padding=(1, 2),
box=box.ROUNDED
)
def display_menu(title, options, status=None):
"""Display a beautiful menu with options and status information."""
clear_screen()
console.print(create_title_panel(title))
if status:
status_items = []
for key, value in status.items():
if isinstance(value, tuple):
text, style = value
status_items.append(f"[bold {Theme.SECONDARY}]{key}:[/] [{style}]{text}[/]")
else:
status_items.append(f"[bold {Theme.SECONDARY}]{key}:[/] {value}")
status_text = Align.center(" | ".join(status_items))
console.print(Panel(status_text, border_style=Theme.MUTED, padding=(1, 2), box=box.ROUNDED))
table = Table(show_header=False, box=None, padding=(0, 2))
table.add_column("Number", style=Theme.SECONDARY)
table.add_column("Option", style="white")
table.add_column("Description", style=Theme.MUTED)
for option in options:
if isinstance(option, str) and option.startswith("---"):
# This is a category header
category = option.replace("---", "").strip()
table.add_row("", f"[bold {Theme.ACCENT}]{category}[/]", "")
else:
number, text, description = option
table.add_row(f"[bold]{number}[/]", text, f"{Theme.ICON_ARROW} {description}")
console.print(table)
return Prompt.ask(f"[bold {Theme.SUCCESS}]Enter your choice[/]")
def display_custom_progress(description="Processing", iterations=100, delay=0.01):
"""Display a modern progress bar with spinner and detailed statistics."""
with Progress(
SpinnerColumn(),
TextColumn(f"[bold {Theme.PRIMARY}]{{task.description}}"),
BarColumn(bar_width=40, complete_style=Theme.SUCCESS, finished_style=Theme.SUCCESS),
TaskProgressColumn(),
TimeElapsedColumn(),
) as progress:
task = progress.add_task(f"[{Theme.SECONDARY}]{description}", total=iterations)
for _ in range(iterations):
time.sleep(delay)
progress.update(task, advance=1)
def input_with_default(prompt, default=""):
"""Display a rich input prompt with a default value."""
# Handle Windows backslashes in paths properly
if isinstance(default, str) and "\\" in default:
default = default.replace("\\", "\\\\")
response = console.input(f"[{Theme.PROMPT}]{prompt}[/]" +
(f" ([{Theme.ACCENT}]{default}[/])" if default else "") +
": ")
return response.strip() or default
def confirm_action(question):
"""Confirm an action with yes/no prompt."""
return Confirm.ask(f"[bold {Theme.WARNING}]{question}[/]")
def success_message(message):
"""Display a success message."""
if "\n" in message:
for line in message.split("\n"):
console.print(f"[bold {Theme.SUCCESS}]{Theme.ICON_SUCCESS} {line.strip()}[/]")
else:
console.print(f"[bold {Theme.SUCCESS}]{Theme.ICON_SUCCESS} {message}[/]")
def error_message(message):
"""Display an error message with icon."""
console.print(f"[bold {Theme.ERROR}]{Theme.ICON_ERROR} {message}[/]")
def warning_message(message):
"""Display a warning message with icon."""
console.print(f"[bold {Theme.WARNING}]{Theme.ICON_WARNING} {message}[/]")
def info_message(message):
"""Display an information message with icon."""
console.print(f"[{Theme.INFO}]{Theme.ICON_INFO} {message}[/]")
def wait_for_key():
"""Wait for user to press any key to continue."""
console.print(f"\n[bold {Theme.SUCCESS}]Press Enter to continue...[/]")
input()
def get_input(prompt_text):
"""Get user input with styled prompt."""
return input_with_default(prompt_text)
def display_project_list(projects, title="Project List"):
"""Display a list of projects in a modern table format."""
console.print(create_title_panel(title))
if not projects:
warning_message("No projects configured")
return
table = Table(
title=f"{Theme.ICON_FOLDER} Configured Projects",
show_lines=True,
box=box.ROUNDED,
title_style=f"bold {Theme.SECONDARY}",
border_style=Theme.SECONDARY
)
table.add_column("#", style=Theme.SECONDARY, justify="right")
table.add_column("Name", style="bold white")
table.add_column("Path", style=Theme.ACCENT)
table.add_column("Status", style=Theme.SUCCESS)
table.add_column("Update Interval", style=Theme.INFO)
table.add_column("Max Depth", style=Theme.INFO)
for i, project in enumerate(projects, 1):
path_exists = os.path.exists(project['project_path'])
status = f"[{Theme.SUCCESS}]Active[/]" if path_exists else f"[{Theme.ERROR}]Path not found[/]"
table.add_row(
str(i),
project['name'],
project['project_path'],
status,
f"{project['update_interval']}s",
str(project['max_depth'])
)
console.print(table)
console.print(f"\n[{Theme.INFO}]Total:[/] [bold]{len(projects)}[/] projects configured")
def display_monitoring_screen(project_count):
"""Display a live monitoring screen with modern layout."""
layout = Layout()
layout.split(
Layout(name="header", size=3),
Layout(name="body"),
Layout(name="footer", size=3)
)
# Create header
layout["header"].update(Panel(
f"[bold {Theme.PRIMARY}]{Theme.ICON_MONITOR} CursorFocus Monitoring[/]",
border_style=Theme.PANEL_BORDER,
box=box.ROUNDED,
padding=(1, 2)
))
# Create footer with instructions
layout["footer"].update(Panel(
f"[bold {Theme.SUCCESS}]Press Ctrl+C to stop monitoring[/]",
border_style=Theme.SUCCESS,
box=box.ROUNDED,
padding=(1, 0)
))
project_table = Table(
title=f"{Theme.ICON_MONITOR} Monitoring {project_count} Projects",
show_lines=True,
box=box.ROUNDED,
title_style=f"bold {Theme.PRIMARY}",
border_style=Theme.SECONDARY
)
project_table.add_column("Project", style="bold white")
project_table.add_column("Status", style=Theme.SUCCESS)
project_table.add_column("Last Update", style=Theme.INFO)
project_table.add_column("Next Update", style=Theme.SECONDARY)
# Add sample projects row
project_table.add_row(
"Sample Project",
f"[{Theme.SUCCESS}]Active[/]",
"Just now",
"In 60s"
)
layout["body"].update(project_table)
# Return the layout for use in a Live context
return layout
def display_scanning_results(found_projects):
"""Display the results of scanning for projects with modern styling."""
if not found_projects:
error_message("No projects found")
return
console.print(f"\n[bold {Theme.SUCCESS}]{Theme.ICON_SEARCH} Found {len(found_projects)} projects:[/]")
table = Table(
title=f"{Theme.ICON_FOLDER} Detected Projects",
show_lines=True,
box=box.ROUNDED,
title_style=f"bold {Theme.PRIMARY}",
border_style=Theme.SECONDARY
)
table.add_column("#", style=Theme.SECONDARY, justify="right")
table.add_column("Name", style="bold white")
table.add_column("Type", style=Theme.INFO)
table.add_column("Path", style=Theme.ACCENT)
table.add_column("Language", style=Theme.SUCCESS)
table.add_column("Framework", style=Theme.WARNING)
for i, project in enumerate(found_projects, 1):
table.add_row(
str(i),
str(project['name']),
str(project.get('type', '')),
str(project['path']),
str(project.get('language', '')),
str(project.get('framework', ''))
)
console.print(table)
def display_update_info(update_info):
"""
Display information about an available update with modern styling.
Args:
update_info (dict): Update information dictionary or None
Returns:
bool: True if user wants to update, False otherwise
"""
if not update_info:
success_message("You are using the latest version")
return False
# Display header information
console.print(Panel(
f"[bold {Theme.SUCCESS}]{Theme.ICON_STAR} New update available![/]\n\n"
f"[{Theme.SECONDARY}]Version:[/] {update_info['version']}\n"
f"[{Theme.SECONDARY}]Date:[/] {update_info['date']}\n"
f"[{Theme.SECONDARY}]Author:[/] {update_info['author']}\n"
f"[{Theme.SECONDARY}]Asset:[/] {update_info['asset_name']}",
title="Update Available",
border_style=Theme.SUCCESS,
box=box.ROUNDED,
padding=(1, 2)
))
# Ask about backup
if confirm_action("Update now?"):
keep_backup = confirm_action("Keep backup after update? (recommended for first update)")
if keep_backup:
from core import CursorFocusCore
CursorFocusCore.configure_updater(keep_backups=True)
info_message("Backup will be kept after update")
else:
# Warn about potential backup cleanup issues
import platform
if platform.system().lower() == 'windows':
warning_message("Note: On Windows, backup cleanup may show warnings about .git directories")
info_message("These warnings are normal and won't affect functionality")
# Display additional information about the update process
info_message("Starting update process - this may take a moment...")
info_message("The update will download and validate the package before applying it")
# For Windows, show different message based on update type
import platform
if platform.system().lower() == 'windows':
if update_info['asset_name'].lower().endswith('.exe'):
info_message("Detected .exe update file - will install executable directly")
else:
info_message("Note: On Windows, updating may skip .git directories to avoid permission issues")
return True
return False
# Legacy UI functions for compatibility
def print_centered(text, color=None):
"""Print text centered in the terminal."""
terminal_width = get_terminal_size().columns
if color:
print(color + text.center(terminal_width) + Colors.RESET)
else:
print(text.center(terminal_width))
def print_header():
"""Print the classic application header."""
clear_screen()
terminal_width = get_terminal_size().columns
print(Colors.HEADER_BG + "=" * terminal_width + Colors.RESET)
print_centered("CURSOR FOCUS CLI", Colors.TITLE)
print(Colors.HEADER_BG + "=" * terminal_width + Colors.RESET)
print_centered("Automatically analyze and create context for Cursor AI IDE", Colors.SUBTITLE)
print(Colors.INFO + "-" * terminal_width + Colors.RESET)
def print_key_value(key, value, indent=0):
"""Print a key-value pair with formatting."""
indentation = " " * indent
print(f"{indentation}{Colors.KEY}{key}:{Colors.RESET} {Colors.VALUE}{value}{Colors.RESET}")
def processing_message(message):
"""Display a processing message (legacy)."""
print(f"{Colors.INFO}⏳ {message}{Colors.RESET}")