@@ -136,7 +136,7 @@ def deinitColors(cls):
136136 pass
137137
138138 @classmethod
139- def exit (cls , returnCode = 0 ):
139+ def exit (cls , returnCode : int = 0 ):
140140 """Exit the terminal application by uninitializing color support and returning an exit code."""
141141 cls .deinitColors ()
142142 exit (returnCode )
@@ -174,24 +174,24 @@ def printException(cls, ex):
174174 cls .initColors ()
175175
176176 print ("{RED}FATAL: An unknown or unhandled exception reached the topmost exception handler!{NOCOLOR}" .format (** cls .Foreground ))
177- print ("{YELLOW} Exception type:{NOCOLOR} {typename}" .format (typename = ex .__class__ .__name__ , ** cls .Foreground ))
178- print ("{YELLOW} Exception message:{NOCOLOR} {message!s}" .format (message = ex , ** cls .Foreground ))
177+ print (" {YELLOW}Exception type:{NOCOLOR} {typename}" .format (typename = ex .__class__ .__name__ , ** cls .Foreground ))
178+ print (" {YELLOW}Exception message:{NOCOLOR} {message!s}" .format (message = ex , ** cls .Foreground ))
179179 frame , sourceLine = [x for x in walk_tb (ex .__traceback__ )][- 1 ]
180180 filename = frame .f_code .co_filename
181181 funcName = frame .f_code .co_name
182- print ("{YELLOW} Caused in:{NOCOLOR} {function} in file '{filename}' at line {line}" .format (
182+ print (" {YELLOW}Caused in:{NOCOLOR} {function} in file '{filename}' at line {line}" .format (
183183 function = funcName ,
184184 filename = filename ,
185185 line = sourceLine ,
186186 ** cls .Foreground
187187 ))
188188 if (ex .__cause__ is not None ):
189- print ("{DARK_YELLOW} Caused by type:{NOCOLOR} {typename}" .format (typename = ex .__cause__ .__class__ .__name__ , ** cls .Foreground ))
190- print ("{DARK_YELLOW} Caused by message:{NOCOLOR} {message!s}" .format (message = ex .__cause__ , ** cls .Foreground ))
189+ print (" {DARK_YELLOW} Caused by type:{NOCOLOR} {typename}" .format (typename = ex .__cause__ .__class__ .__name__ , ** cls .Foreground ))
190+ print (" {DARK_YELLOW} Caused by message:{NOCOLOR} {message!s}" .format (message = ex .__cause__ , ** cls .Foreground ))
191191 print (("{RED}" + ("-" * 80 ) + "{NOCOLOR}" ).format (** cls .Foreground ))
192192 print_tb (ex .__traceback__ )
193193 print (("{RED}" + ("-" * 80 ) + "{NOCOLOR}" ).format (** cls .Foreground ))
194- print (("{RED}Please report this bug at GitHub: https://github.com/VLSI-EDA/pyIPCMI /issues{NOCOLOR}" ).format (** cls .Foreground ))
194+ print (("{RED}Please report this bug at GitHub: https://github.com/Paebbels/pyTerminalUI /issues{NOCOLOR}" ).format (** cls .Foreground ))
195195 print (("{RED}" + ("-" * 80 ) + "{NOCOLOR}" ).format (** cls .Foreground ))
196196
197197 cls .exit (1 )
@@ -522,6 +522,9 @@ def __init__(self, verbose=False, debug=False, quiet=False, writeToStdOut=True):
522522 self ._lines = []
523523 self ._baseIndent = 0
524524
525+ self ._errorCounter = 0
526+ self ._warningCounter = 0
527+
525528 @property
526529 def Verbose (self ):
527530 """Returns true, if verbose messages are enabled."""
@@ -565,6 +568,16 @@ def BaseIndent(self, value):
565568 Severity .Debug : "{DARK_GRAY}{message}{NOCOLOR}"
566569 } #: Message formatting rules.
567570
571+ def ExitOnPreviousErrors (self ):
572+ if self ._errorCounter > 0 :
573+ self .WriteFatal ("Too many errors in previous steps." )
574+ self .exit ()
575+
576+ def ExitOnPreviousWarnings (self ):
577+ if self ._warningCounter > 0 :
578+ self .WriteError ("Too many warnings in previous steps." )
579+ self .exit ()
580+
568581 def WriteLine (self , line : Line ):
569582 """Print a formatted line to the underlying terminal/console offered by the operating system."""
570583
@@ -579,13 +592,18 @@ def WriteLine(self, line : Line):
579592 def TryWriteLine (self , line ):
580593 return (line .Severity >= self ._WriteLevel )
581594
582- def WriteFatal (self , message , indent = 0 , appendLinebreak = True ):
583- return self .WriteLine (Line (message , Severity .Fatal , self ._baseIndent + indent , appendLinebreak ))
595+ def WriteFatal (self , message , indent = 0 , appendLinebreak = True , immediateExit = True ):
596+ ret = self .WriteLine (Line (message , Severity .Fatal , self ._baseIndent + indent , appendLinebreak ))
597+ if immediateExit :
598+ self .exit ()
599+ return ret
584600
585601 def WriteError (self , message , indent = 0 , appendLinebreak = True ):
602+ self ._errorCounter += 1
586603 return self .WriteLine (Line (message , Severity .Error , self ._baseIndent + indent , appendLinebreak ))
587604
588605 def WriteWarning (self , message , indent = 0 , appendLinebreak = True ):
606+ self ._warningCounter += 1
589607 return self .WriteLine (Line (message , Severity .Warning , self ._baseIndent + indent , appendLinebreak ))
590608
591609 def WriteInfo (self , message , indent = 0 , appendLinebreak = True ):
0 commit comments