From 08224d5367f74942dffa487332222c02c842d0fe Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 4 Dec 2018 00:54:18 +0100 Subject: [PATCH] error/warning colors --- compiler/src/prog8/CompilerMain.kt | 6 ++++++ compiler/src/prog8/ast/AstChecker.kt | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index d569f5079..8554d3de4 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -136,14 +136,20 @@ fun main(args: Array) { println("\nTotal compilation+assemble time: ${(endTime-startTime)/1000.0} sec.") } catch (px: ParsingFailedError) { + System.err.print("\u001b[91m") // bright red System.err.println(px.message) + System.err.print("\u001b[0m") // reset exitProcess(1) } catch (x: Exception) { + print("\u001b[91m") // bright red println("\n* internal error *") + print("\u001b[0m") // reset System.out.flush() throw x } catch (x: NotImplementedError) { + print("\u001b[91m") // bright red println("\n* internal error: missing feature/code *") + print("\u001b[0m") // reset System.out.flush() throw x } diff --git a/compiler/src/prog8/ast/AstChecker.kt b/compiler/src/prog8/ast/AstChecker.kt index 0436fb35b..f6b328f6e 100644 --- a/compiler/src/prog8/ast/AstChecker.kt +++ b/compiler/src/prog8/ast/AstChecker.kt @@ -20,6 +20,7 @@ fun Module.checkValid(globalNamespace: INameScope, compilerOptions: CompilationO fun printErrors(errors: List, moduleName: String) { val reportedMessages = mutableSetOf() + print("\u001b[91m") // bright red errors.forEach { val msg = it.toString() if(msg !in reportedMessages) { @@ -27,17 +28,20 @@ fun printErrors(errors: List, moduleName: String) { reportedMessages.add(msg) } } + print("\u001b[0m") // reset color if(reportedMessages.isNotEmpty()) throw ParsingFailedError("There are ${reportedMessages.size} errors in module '$moduleName'.") } fun printWarning(msg: String, position: Position, detailInfo: String?=null) { + print("\u001b[93m") // bright yellow print("$position Warning: $msg") if(detailInfo==null) print("\n") else println(": $detailInfo") + print("\u001b[0m") // bright yellow }