44from .config import *
55from .utils import get_terminal_size , draw_bar , format_bytes
66
7+ # Startup splash messages
8+ STARTUP_MESSAGES = [
9+ "Initializing terminal magic..." ,
10+ "Poking the system kernel..." ,
11+ "Interrogating your CPU..." ,
12+ "Snooping on your storage..." ,
13+ "Waking up the GPU..." ,
14+ "Collecting process breadcrumbs..." ,
15+ "Priming the performance counters..." ,
16+ "Polishing the UI..." ,
17+ "Reordering electrons..." ,
18+ "Compiling bitstreams..." ,
19+ "Calibrating flux capacitor..." ,
20+ "Reticulating splines..." ,
21+ ]
22+
23+ def render_startup (step : int , total_steps : int , message : str = None ):
24+ """Render a startup splash screen with progress.
25+
26+ Args:
27+ step: Current step number (0-indexed)
28+ total_steps: Total number of steps
29+ message: Optional custom message, otherwise uses STARTUP_MESSAGES
30+ """
31+ cols , rows , _ = get_terminal_size ()
32+
33+ # Calculate progress
34+ progress = min (100 , int ((step / max (1 , total_steps )) * 100 ))
35+
36+ # Get message
37+ if message is None :
38+ msg_idx = min (step , len (STARTUP_MESSAGES ) - 1 )
39+ message = STARTUP_MESSAGES [msg_idx ]
40+
41+ # ASCII art logo
42+ # cant we use literals so this doesnt look like shit?
43+ logo = [
44+ " __ __ _____ ___ ___ " ,
45+ " / / /\\ \\ \\ /\\ /\\ /__ \\ /___\\ / _ \\ " ,
46+ " \\ \\ / \\ / / /_/ / / /\\ // // /_)/" ,
47+ " \\ /\\ / __ / / / / \\ _// ___/ " ,
48+ " \\ / \\ /\\ / /_/ \\ / \\ ___/\\ / " ,
49+ ]
50+
51+ # We built this buffer on line by line (Heyo!)
52+ lines = []
53+
54+ # Vertical centering
55+ content_height = len (logo ) + 6
56+ start_row = max (0 , (rows - content_height ) // 2 )
57+
58+ # Fill top padding
59+ for _ in range (start_row ):
60+ lines .append ("\033 [K" ) # Empty line
61+
62+ # Draw Logo
63+ for line in logo :
64+ padding = max (0 , (cols - len (line )) // 2 )
65+ lines .append (f"{ ' ' * padding } { C_CYAN } { C_BOLD } { line } { C_RESET } \033 [K" )
66+
67+ lines .append ("\033 [K" )
68+ lines .append ("\033 [K" )
69+
70+ # Draw Progress Bar
71+ bar_width = min (50 , cols - 20 )
72+ filled = int ((progress / 100 ) * bar_width )
73+ empty = bar_width - filled
74+
75+ bar_str = f"{ C_GREEN } { '█' * filled } { C_DIM } { '░' * empty } { C_RESET } "
76+ progress_text = f" [{ bar_str } ] { C_BOLD } { progress :3d} %{ C_RESET } "
77+
78+ # Center progress bar
79+ # Text length approx bar_width + 12 chars invisible chars don't count for padding calculation but needed for total len
80+ # We visually center based on visible width ~ bar_width + 8
81+ pad_len = max (0 , (cols - (bar_width + 8 )) // 2 )
82+ lines .append (f"{ ' ' * pad_len } { progress_text } \033 [K" )
83+
84+ lines .append ("\033 [K" )
85+
86+ # Draw Message
87+ msg_len = len (message )
88+ msg_pad = max (0 , (cols - msg_len ) // 2 )
89+ lines .append (f"{ ' ' * msg_pad } { C_YELLOW } { message } { C_RESET } \033 [K" )
90+
91+ # Fill rest of screen
92+ sys .stdout .write ("\033 [H" ) # Home
93+
94+ # Output limited to rows to avoid scroll
95+ # We need to construct string carefully
96+ final_output = "\n " .join (lines )
97+ sys .stdout .write (final_output )
98+
99+ # Clear rest of screen below content
100+ sys .stdout .write ("\033 [J" )
101+ sys .stdout .flush ()
102+
7103def render ():
8104 """Render the entire UI."""
9- cols , rows = get_terminal_size ()
105+ cols , rows , toosmall = get_terminal_size ()
10106
11107 # Detect terminal resize
12108 if (cols , rows ) != state .prev_term_size :
13109 sys .stdout .write ("\033 [2J" )
14110 state .prev_term_size = (cols , rows )
15111
16- # Validation for extremely small windows to prevent crash
17- if cols < 79 or rows < 18 :
18- return
19-
20112 # We build the buffer line by line.
21113 lines = []
22114
23- # --- Helper to add a line with safe ANSI handling ---
115+ # Detect if the terminal is too small and write to status message
116+ if toosmall :
117+ state .status_message = "Window too small!"
118+
119+ # Helper to add a line with safe ANSI handling
24120 def add_line (text , bg_color = None ):
25121 if bg_color :
26122 lines .append (f"{ bg_color } { text } { C_RESET } \033 [K" )
27123 else :
28124 lines .append (f"{ text } { C_RESET } \033 [K" )
29125
30- # --- Header: Hardware Info ---
126+ # Header: Hardware Info
31127 gpu_name_short = state .sys_stats ['gpu_name' ][:25 ] if state .sys_stats ['gpu_available' ] else "No GPU"
32128 cpu_name_short = state .sys_stats ['cpu_name' ][:35 ]
33129
34130 header_content = f" CPU: { cpu_name_short } | GPU: { gpu_name_short } "
35131 padding_len = max (0 , cols - len (header_content )) # approx check
36132 lines .append (f"{ C_BG_HEADER } { C_BOLD } { header_content } { ' ' * padding_len } { C_RESET } " )
37133
38- # --- Command Bar ---
134+ # Command Bar
39135 speed_indicator = f"[{ state .current_refresh_rate } ]"
40136 cmd_display = f" > { state .input_buffer } "
41137 vis_len = len (cmd_display ) + len (speed_indicator ) + 1
@@ -45,7 +141,7 @@ def add_line(text, bg_color=None):
45141
46142 lines .append (f"{ C_DIM } { '─' * cols } { C_RESET } \033 [K" )
47143
48- # --- System Monitor ---
144+ # System Monitor
49145 # Reserve header(3), footer(header+status+sep=3), min_proc(1) -> 7 lines reserved.
50146 max_sys_mon_lines = max (1 , rows - 7 )
51147 sys_mon_lines = []
0 commit comments