@@ -143,111 +143,92 @@ def _handle_key(self, key: str) -> None:
143143
144144 def _prompt_irradiance (self ) -> None :
145145 """Prompt for irradiance value."""
146+ if self .display :
147+ self .display .pause ()
146148 try :
147- if self .display and self .display .console :
148- self .display .console .print (f"\n [cyan]Solar Irradiance[/cyan] (current: { self .simulator .solar_irradiance :.0f} W/m²)" )
149- self .display .console .print ("[white]Enter new value (0-1000): [/white]" , end = '' )
150- else :
151- print (f"\n Solar Irradiance (current: { self .simulator .solar_irradiance :.0f} W/m²)" )
152- print ("Enter new value (0-1000): " , end = '' , flush = True )
149+ print (f"\n Solar Irradiance (current: { self .simulator .solar_irradiance :.0f} W/m²)" )
150+ print ("Enter new value (0-1000): " , end = '' , flush = True )
153151
154152 value = float (input ())
155153 self .simulator .set_irradiance (value )
156-
157- if self .display and self .display .console :
158- self .display .console .print (f"[green]✓ Irradiance set to { self .simulator .solar_irradiance :.0f} W/m²[/green]" )
159- else :
160- print (f"✓ Irradiance set to { self .simulator .solar_irradiance :.0f} W/m²" )
154+ print (f"✓ Irradiance set to { self .simulator .solar_irradiance :.0f} W/m²" )
155+ time .sleep (1 )
161156
162157 except (ValueError , EOFError , KeyboardInterrupt ):
163- if self .display and self .display .console :
164- self .display .console .print ("[red]✗ Invalid input[/red]" )
165- else :
166- print ("✗ Invalid input" )
158+ print ("✗ Invalid input" )
159+ time .sleep (1 )
160+ finally :
161+ if self .display :
162+ self .display .resume ()
167163
168164 def _prompt_clouds (self ) -> None :
169165 """Prompt for cloud cover."""
166+ if self .display :
167+ self .display .pause ()
170168 try :
171- if self .display and self .display .console :
172- self .display .console .print (f"\n [cyan]Cloud Cover[/cyan] (current: { self .simulator .cloud_cover * 100 :.0f} %)" )
173- self .display .console .print ("[white]Enter new value (0-100): [/white]" , end = '' )
174- else :
175- print (f"\n Cloud Cover (current: { self .simulator .cloud_cover * 100 :.0f} %)" )
176- print ("Enter new value (0-100): " , end = '' , flush = True )
169+ print (f"\n Cloud Cover (current: { self .simulator .cloud_cover * 100 :.0f} %)" )
170+ print ("Enter new value (0-100): " , end = '' , flush = True )
177171
178172 value = float (input ()) / 100.0
179173 self .simulator .set_cloud_cover (value )
180-
181- if self .display and self .display .console :
182- self .display .console .print (f"[green]✓ Cloud cover set to { self .simulator .cloud_cover * 100 :.0f} %[/green]" )
183- else :
184- print (f"✓ Cloud cover set to { self .simulator .cloud_cover * 100 :.0f} %" )
174+ print (f"✓ Cloud cover set to { self .simulator .cloud_cover * 100 :.0f} %" )
175+ time .sleep (1 )
185176
186177 except (ValueError , EOFError , KeyboardInterrupt ):
187- if self .display and self .display .console :
188- self .display .console .print ("[red]✗ Invalid input[/red]" )
189- else :
190- print ("✗ Invalid input" )
178+ print ("✗ Invalid input" )
179+ time .sleep (1 )
180+ finally :
181+ if self .display :
182+ self .display .resume ()
191183
192184 def _prompt_load (self ) -> None :
193185 """Prompt for house load."""
186+ if self .display :
187+ self .display .pause ()
194188 try :
195- if self .display and self .display .console :
196- self .display .console .print (f"\n [cyan]House Load[/cyan] (current: { self .simulator .house_load :.0f} W)" )
197- self .display .console .print ("[white]Enter new value (W): [/white]" , end = '' )
198- else :
199- print (f"\n House Load (current: { self .simulator .house_load :.0f} W)" )
200- print ("Enter new value (W): " , end = '' , flush = True )
189+ print (f"\n House Load (current: { self .simulator .house_load :.0f} W)" )
190+ print ("Enter new value (W): " , end = '' , flush = True )
201191
202192 value = float (input ())
203193 self .simulator .set_house_load (value )
204-
205- if self .display and self .display .console :
206- self .display .console .print (f"[green]✓ House load set to { self .simulator .house_load :.0f} W[/green]" )
207- else :
208- print (f"✓ House load set to { self .simulator .house_load :.0f} W" )
194+ print (f"✓ House load set to { self .simulator .house_load :.0f} W" )
195+ time .sleep (1 )
209196
210197 except (ValueError , EOFError , KeyboardInterrupt ):
211- if self .display and self .display .console :
212- self .display .console .print ("[red]✗ Invalid input[/red]" )
213- else :
214- print ("✗ Invalid input" )
198+ print ("✗ Invalid input" )
199+ time .sleep (1 )
200+ finally :
201+ if self .display :
202+ self .display .resume ()
215203
216204 def _prompt_time_speed (self ) -> None :
217205 """Prompt for time multiplier."""
206+ if self .display :
207+ self .display .pause ()
218208 try :
219- if self .display and self .display .console :
220- self .display .console .print (f"\n [cyan]Time Speed[/cyan] (current: { self .simulator .time_multiplier } x)" )
221- self .display .console .print ("[white]Enter new multiplier (0.1-100): [/white]" , end = '' )
222- else :
223- print (f"\n Time Speed (current: { self .simulator .time_multiplier } x)" )
224- print ("Enter new multiplier (0.1-100): " , end = '' , flush = True )
209+ print (f"\n Time Speed (current: { self .simulator .time_multiplier } x)" )
210+ print ("Enter new multiplier (0.1-100): " , end = '' , flush = True )
225211
226212 value = float (input ())
227213 self .simulator .set_time_multiplier (value )
228-
229- if self .display and self .display .console :
230- self .display .console .print (f"[green]✓ Time speed set to { self .simulator .time_multiplier } x[/green]" )
231- else :
232- print (f"✓ Time speed set to { self .simulator .time_multiplier } x" )
214+ print (f"✓ Time speed set to { self .simulator .time_multiplier } x" )
215+ time .sleep (1 )
233216
234217 except (ValueError , EOFError , KeyboardInterrupt ):
235- if self .display and self .display .console :
236- self .display .console .print ("[red]✗ Invalid input[/red]" )
237- else :
238- print ("✗ Invalid input" )
218+ print ("✗ Invalid input" )
219+ time .sleep (1 )
220+ finally :
221+ if self .display :
222+ self .display .resume ()
239223
240224 def _prompt_battery (self ) -> None :
241225 """Prompt for battery control."""
226+ if self .display :
227+ self .display .pause ()
242228 try :
243- if self .display and self .display .console :
244- self .display .console .print ("\n [cyan]Battery Control[/cyan]" )
245- self .display .console .print ("[white]1. Auto 2. Charge 3. Discharge 4. Idle[/white]" )
246- self .display .console .print ("[white]Enter choice (1-4): [/white]" , end = '' )
247- else :
248- print ("\n Battery Control" )
249- print ("1. Auto 2. Charge 3. Discharge 4. Idle" )
250- print ("Enter choice (1-4): " , end = '' , flush = True )
229+ print ("\n Battery Control" )
230+ print ("1. Auto 2. Charge 3. Discharge 4. Idle" )
231+ print ("Enter choice (1-4): " , end = '' , flush = True )
251232
252233 choice = input ().strip ()
253234
@@ -256,19 +237,13 @@ def _prompt_battery(self) -> None:
256237 msg = "✓ Battery set to AUTO mode"
257238
258239 elif choice == '2' :
259- if self .display and self .display .console :
260- self .display .console .print ("[white]Enter charge power (W): [/white]" , end = '' )
261- else :
262- print ("Enter charge power (W): " , end = '' , flush = True )
240+ print ("Enter charge power (W): " , end = '' , flush = True )
263241 power = float (input ())
264242 self .simulator .set_battery_override (abs (power ))
265243 msg = f"✓ Battery charging at { abs (power ):.0f} W"
266244
267245 elif choice == '3' :
268- if self .display and self .display .console :
269- self .display .console .print ("[white]Enter discharge power (W): [/white]" , end = '' )
270- else :
271- print ("Enter discharge power (W): " , end = '' , flush = True )
246+ print ("Enter discharge power (W): " , end = '' , flush = True )
272247 power = float (input ())
273248 self .simulator .set_battery_override (- abs (power ))
274249 msg = f"✓ Battery discharging at { abs (power ):.0f} W"
@@ -279,13 +254,12 @@ def _prompt_battery(self) -> None:
279254 else :
280255 msg = "✗ Invalid choice"
281256
282- if self .display and self .display .console :
283- self .display .console .print (f"[green]{ msg } [/green]" )
284- else :
285- print (msg )
257+ print (msg )
258+ time .sleep (1 )
286259
287260 except (ValueError , EOFError , KeyboardInterrupt ):
288- if self .display and self .display .console :
289- self .display .console .print ("[red]✗ Invalid input[/red]" )
290- else :
291- print ("✗ Invalid input" )
261+ print ("✗ Invalid input" )
262+ time .sleep (1 )
263+ finally :
264+ if self .display :
265+ self .display .resume ()
0 commit comments