4141from CB import __version__
4242from CB .Core import Core
4343from CB .Wago import WagoUpdater
44- from CB .Compat import pause , timeout , clear , set_terminal_title , set_terminal_size , KBHit
44+ from CB .Compat import clear , set_terminal_title , set_terminal_size , KBHit
4545from CB .Resources import LOGO , HEADLESS_TERMINAL_THEME
4646
4747if platform .system () == 'Windows' :
@@ -145,9 +145,8 @@ def start(self): # sourcery skip: low-code-quality
145145 logo = Pixels .from_image (image , resize = (40 , 40 ))
146146 self .console .print (Panel (Align .center (logo ), border_style = 'yellow' ))
147147 self .console .print ('' )
148- with Live (Text ('Automatic update of all addons will start in 5 seconds.\n Press any button to enter inte'
149- 'ractive mode.' ), console = self .console , refresh_per_second = 2 ) as countdown :
150- keypress = self .handle_keypress (5 , countdown )
148+ keypress = self .handle_keypress ('Automatic update of all addons will start in {} seconds.\n Press any bu'
149+ 'tton to enter interactive mode.' , 5 , True )
151150 else :
152151 keypress = False
153152 if not keypress :
@@ -174,9 +173,8 @@ def start(self): # sourcery skip: low-code-quality
174173 sys .exit (0 )
175174 else :
176175 self .print_author_reminder ()
177- self .console .print ('Press [bold]I[/bold] to enter interactive mode or any other button to close'
178- ' the application.' )
179- keypress = self .handle_keypress (0 )
176+ keypress = self .handle_keypress ('Press [bold]I[/bold] to enter interactive mode or any other button'
177+ ' to close the application.' , 0 , False )
180178 if not keypress or keypress .lower () not in [b'i' , 'i' ]:
181179 self .core .http .close ()
182180 sys .exit (0 )
@@ -224,7 +222,7 @@ def start(self): # sourcery skip: low-code-quality
224222 def _auto_update_cleanup (self ):
225223 self .print_log ()
226224 self .core .http .close ()
227- pause ( self .headless )
225+ self .handle_keypress ( 'Press any button to continue...' , 0 , False )
228226
229227 def _auto_update_install (self , url , changelog ):
230228 self .console .print ('[green]Updating CurseBreaker...[/green]' )
@@ -284,7 +282,7 @@ def motd_parser(self):
284282 else :
285283 payload = self .core .http .get ('https://cursebreaker.acidweb.dev/motd' )
286284 if payload .status_code == 200 :
287- self .console .print (Panel (payload .content .decode ('UTF-8' ), title = ':warning : MOTD :warning :' ,
285+ self .console .print (Panel (payload .content .decode ('UTF-8' ), title = ':megaphone : MOTD :megaphone :' ,
288286 border_style = 'red' ))
289287 self .console .print ('' )
290288
@@ -304,35 +302,41 @@ def handle_exception(self, e, table=True):
304302 self .console .print (Traceback .from_exception (exc_type = e .__class__ , exc_value = e ,
305303 traceback = e .__traceback__ , width = width ))
306304
307- def handle_countdown (self , n ):
308- msg = (f'Automatic update of all addons will start in { math .ceil (n )} seconds.\n '
309- f'Press any button to enter interactive mode.' )
310- return Text (msg )
311-
312- def handle_keypress (self , wait , countdown = None ):
305+ def _handle_keypress_console (self , count , msg , countdown = None ):
313306 kb = KBHit ()
314307 starttime = time .time ()
315- keypress = None
308+ keypress = False
316309 while True :
317310 if kb .kbhit ():
318311 keypress = kb .getch ()
319312 break
320- elif wait and time .time () - starttime > wait :
313+ elif count and time .time () - starttime > count :
321314 break
322315 if countdown :
323- countdown .update (self . handle_countdown ( wait - (time .time () - starttime )))
316+ countdown .update (Text ( msg . format ( math . ceil ( count - (time .time () - starttime )) )))
324317 time .sleep (0.01 )
325318 kb .set_normal_term ()
326319 return keypress
327320
321+ def handle_keypress (self , msg , count , live ):
322+ if self .headless :
323+ return False
324+ if live :
325+ with Live (Text (msg .format (count )), console = self .console , refresh_per_second = 2 ) as countdown :
326+ keypress = self ._handle_keypress_console (count , msg , countdown )
327+ else :
328+ self .console .print (msg )
329+ keypress = self ._handle_keypress_console (count , msg )
330+ return keypress
331+
328332 def handle_shutdown (self , message = '' ):
329333 self .core .http .close ()
330334 if not message :
331- timeout ( self .headless )
335+ self .handle_keypress ( ' \n Waiting for {} seconds, press any button to continue...' , 5 , True )
332336 sys .exit (0 )
333337 else :
334338 self .console .print (message )
335- pause ( self .headless )
339+ self .handle_keypress ( ' \n Press any button to continue...' , 0 , False )
336340 sys .exit (1 )
337341
338342 def print_header (self ):
0 commit comments