@@ -136,7 +136,7 @@ def deinitColors(cls):
136
136
pass
137
137
138
138
@classmethod
139
- def exit (cls , returnCode = 0 ):
139
+ def exit (cls , returnCode : int = 0 ):
140
140
"""Exit the terminal application by uninitializing color support and returning an exit code."""
141
141
cls .deinitColors ()
142
142
exit (returnCode )
@@ -174,24 +174,24 @@ def printException(cls, ex):
174
174
cls .initColors ()
175
175
176
176
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 ))
179
179
frame , sourceLine = [x for x in walk_tb (ex .__traceback__ )][- 1 ]
180
180
filename = frame .f_code .co_filename
181
181
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 (
183
183
function = funcName ,
184
184
filename = filename ,
185
185
line = sourceLine ,
186
186
** cls .Foreground
187
187
))
188
188
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 ))
191
191
print (("{RED}" + ("-" * 80 ) + "{NOCOLOR}" ).format (** cls .Foreground ))
192
192
print_tb (ex .__traceback__ )
193
193
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 ))
195
195
print (("{RED}" + ("-" * 80 ) + "{NOCOLOR}" ).format (** cls .Foreground ))
196
196
197
197
cls .exit (1 )
@@ -522,6 +522,9 @@ def __init__(self, verbose=False, debug=False, quiet=False, writeToStdOut=True):
522
522
self ._lines = []
523
523
self ._baseIndent = 0
524
524
525
+ self ._errorCounter = 0
526
+ self ._warningCounter = 0
527
+
525
528
@property
526
529
def Verbose (self ):
527
530
"""Returns true, if verbose messages are enabled."""
@@ -565,6 +568,16 @@ def BaseIndent(self, value):
565
568
Severity .Debug : "{DARK_GRAY}{message}{NOCOLOR}"
566
569
} #: Message formatting rules.
567
570
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
+
568
581
def WriteLine (self , line : Line ):
569
582
"""Print a formatted line to the underlying terminal/console offered by the operating system."""
570
583
@@ -579,13 +592,18 @@ def WriteLine(self, line : Line):
579
592
def TryWriteLine (self , line ):
580
593
return (line .Severity >= self ._WriteLevel )
581
594
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
584
600
585
601
def WriteError (self , message , indent = 0 , appendLinebreak = True ):
602
+ self ._errorCounter += 1
586
603
return self .WriteLine (Line (message , Severity .Error , self ._baseIndent + indent , appendLinebreak ))
587
604
588
605
def WriteWarning (self , message , indent = 0 , appendLinebreak = True ):
606
+ self ._warningCounter += 1
589
607
return self .WriteLine (Line (message , Severity .Warning , self ._baseIndent + indent , appendLinebreak ))
590
608
591
609
def WriteInfo (self , message , indent = 0 , appendLinebreak = True ):
0 commit comments