Skip to content

Commit d5acbd4

Browse files
committed
refactor(tui): 🔨 enhance clear_screen with optional header display
The `clear_screen()` function in both launcher_tui.py and settings_tool.py has been enhanced to accept an optional subtitle parameter that displays a consistent header panel when provided. - Add `subtitle` parameter to `clear_screen()` function - Display formatted header panel with subtitle when provided - Update function calls to use new subtitle feature in settings tool (e.g., "Save Changes", "Exit Without Saving") - Remove redundant clear_screen call in launcher after startup message - Improve code reuse and consistency across TUI interfaces
1 parent ef8f78e commit d5acbd4

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/proxy_app/launcher_tui.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,26 @@ def _get_env_file() -> Path:
3030
return Path.cwd() / ".env"
3131

3232

33-
def clear_screen():
33+
def clear_screen(subtitle: str = ""):
3434
"""
35-
Cross-platform terminal clear that works robustly on both
36-
classic Windows conhost and modern terminals (Windows Terminal, Linux, Mac).
35+
Cross-platform terminal clear with optional header.
3736
3837
Uses native OS commands instead of ANSI escape sequences:
3938
- Windows (conhost & Windows Terminal): cls
4039
- Unix-like systems (Linux, Mac): clear
40+
41+
Args:
42+
subtitle: If provided, displays a header panel with this subtitle.
43+
If empty/None, just clears the screen.
4144
"""
4245
os.system("cls" if os.name == "nt" else "clear")
46+
if subtitle:
47+
console.print(
48+
Panel(
49+
f"[bold cyan]{subtitle}[/bold cyan]",
50+
title="--- API Key Proxy ---",
51+
)
52+
)
4353

4454

4555
class LauncherConfig:
@@ -967,11 +977,10 @@ def run_proxy(self):
967977
f"\n[bold green]🚀 Starting proxy on {self.config.config['host']}:{self.config.config['port']}...[/bold green]\n"
968978
)
969979

970-
# Clear console again to remove the starting message before main.py shows loading details
980+
# Brief pause so user sees the message before main.py takes over
971981
import time
972982

973-
time.sleep(0.5) # Brief pause so user sees the message
974-
clear_screen()
983+
time.sleep(0.5)
975984

976985
# Reconstruct sys.argv for main.py
977986
sys.argv = [

src/proxy_app/settings_tool.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,26 @@
4343
IFLOW_DEFAULT_OAUTH_PORT = 11451
4444

4545

46-
def clear_screen():
46+
def clear_screen(subtitle: str = ""):
4747
"""
48-
Cross-platform terminal clear that works robustly on both
49-
classic Windows conhost and modern terminals (Windows Terminal, Linux, Mac).
48+
Cross-platform terminal clear with optional header.
5049
5150
Uses native OS commands instead of ANSI escape sequences:
5251
- Windows (conhost & Windows Terminal): cls
5352
- Unix-like systems (Linux, Mac): clear
53+
54+
Args:
55+
subtitle: If provided, displays a header panel with this subtitle.
56+
If empty/None, just clears the screen.
5457
"""
5558
os.system("cls" if os.name == "nt" else "clear")
59+
if subtitle:
60+
console.print(
61+
Panel(
62+
f"[bold cyan]{subtitle}[/bold cyan]",
63+
title="--- API Key Proxy ---",
64+
)
65+
)
5666

5767

5868
class AdvancedSettings:
@@ -1443,9 +1453,8 @@ def manage_provider_settings(self):
14431453
def _manage_single_provider_settings(self, provider: str):
14441454
"""Manage settings for a single provider"""
14451455
while True:
1446-
clear_screen()
1447-
14481456
display_name = provider.replace("_", " ").title()
1457+
clear_screen()
14491458
definitions = self.provider_settings_mgr.get_provider_settings_definitions(
14501459
provider
14511460
)
@@ -2401,7 +2410,7 @@ def _show_changes_summary(self):
24012410
def save_and_exit(self):
24022411
"""Save pending changes and exit"""
24032412
if self.settings.has_pending():
2404-
clear_screen()
2413+
clear_screen("Save Changes")
24052414
self._show_changes_summary()
24062415

24072416
if Confirm.ask("\n[bold yellow]Save all pending changes?[/bold yellow]"):
@@ -2421,7 +2430,7 @@ def save_and_exit(self):
24212430
def exit_without_saving(self):
24222431
"""Exit without saving"""
24232432
if self.settings.has_pending():
2424-
clear_screen()
2433+
clear_screen("Exit Without Saving")
24252434
self._show_changes_summary()
24262435

24272436
if Confirm.ask("\n[bold red]Discard all pending changes?[/bold red]"):

0 commit comments

Comments
 (0)