Browse Source

Console-mode compiler (ISCC) change: Warnings and errors are now colorized.

Martijn Laan 5 years ago
parent
commit
eb688690c0
2 changed files with 36 additions and 13 deletions
  1. 35 13
      Projects/ISCC.dpr
  2. 1 0
      whatsnew.htm

+ 35 - 13
Projects/ISCC.dpr

@@ -72,14 +72,36 @@ begin
   WriteFile(H, S[1], Length(S), BytesWritten, nil);
 end;
 
-procedure WriteStdOut(const S: String);
+procedure WriteStdOut(const S: String; const Warning: Boolean = False);
+var
+  CSBI: TConsoleScreenBufferInfo;
 begin
-  WriteToStdHandle(StdOutHandle, AnsiString(S));
+  if Warning then begin
+    GetConsoleScreenBufferInfo(StdErrHandle, CSBI);
+    SetConsoleTextAttribute(StdErrHandle, FOREGROUND_INTENSITY or FOREGROUND_RED or FOREGROUND_GREEN);
+  end;
+  try
+    WriteToStdHandle(StdOutHandle, AnsiString(S));
+  finally
+    if Warning then
+      SetConsoleTextAttribute(StdErrHandle, CSBI.wAttributes);
+  end;
 end;
 
-procedure WriteStdErr(const S: String);
+procedure WriteStdErr(const S: String; const Error: Boolean = False);
+var
+  CSBI: TConsoleScreenBufferInfo;
 begin
-  WriteToStdHandle(StdErrHandle, AnsiString(S));
+  if Error then begin
+    GetConsoleScreenBufferInfo(StdErrHandle, CSBI);
+    SetConsoleTextAttribute(StdErrHandle, FOREGROUND_INTENSITY or FOREGROUND_RED);
+  end;
+  try
+    WriteToStdHandle(StdErrHandle, AnsiString(S));
+  finally
+    if Error then
+      SetConsoleTextAttribute(StdErrHandle, CSBI.wAttributes);
+  end;
 end;
 
 function GetCursorPos: TPoint;
@@ -222,7 +244,7 @@ begin
       end;
     iscbNotifyStatus:
       if not Quiet then
-        WriteStdOut(Data.StatusMsg)
+        WriteStdOut(Data.StatusMsg, Data.Warning)
       else if ShowProgress then
         PrintProgress(Trim(Data.StatusMsg));
     iscbNotifySuccess: begin
@@ -250,7 +272,7 @@ begin
         else if ScriptFilename <> '' then
           S := S + ' in ' + ScriptFilename;
         S := S + ': ' + Data.ErrorMsg;
-        WriteStdErr(S);
+        WriteStdErr(S, True);
       end;
     iscbNotifyIdle:
       if ShowProgress and (Data.CompressProgress <> 0) then begin
@@ -411,7 +433,7 @@ begin
       else if GetParam(S, 'S') then begin
         if Pos('=', S) = 0 then begin
           ShowBanner;
-          WriteStdErr('Invalid option: ' + S);
+          WriteStdErr('Invalid option: ' + S, True);
           Halt(1);
         end;
         SignTools.Add(S);
@@ -443,7 +465,7 @@ begin
       end
       else begin
         ShowBanner;
-        WriteStdErr('Unknown option: ' + S);
+        WriteStdErr('Unknown option: ' + S, True);
         Halt(1);
       end;
     end
@@ -451,7 +473,7 @@ begin
       { Not a switch; must be the script filename }
       if ScriptFilename <> '' then begin
         ShowBanner;
-        WriteStdErr('You may not specify more than one script filename.');
+        WriteStdErr('You may not specify more than one script filename.', True);
         Halt(1);
       end;
       ScriptFilename := S;
@@ -528,7 +550,7 @@ begin
   {$ENDIF}
   if Ver.BinVersion < $05000500 then begin
     { 5.0.5 or later is required since we use TCompileScriptParamsEx }
-    WriteStdErr('Incompatible compiler engine version.');
+    WriteStdErr('Incompatible compiler engine version.', True);
     Halt(1);
   end;
 
@@ -592,12 +614,12 @@ begin
       isceNoError: ;
       isceCompileFailure: begin
           ExitCode := 2;
-          WriteStdErr('Compile aborted.');
+          WriteStdErr('Compile aborted.', True);
         end;
     else
       ExitCode := 1;
       WriteStdErr(Format('Internal error: ISDllCompileScript returned ' +
-        'unexpected result (%d).', [Res]));
+        'unexpected result (%d).', [Res]), True);
     end;
   finally
     FreeScriptLines;
@@ -619,7 +641,7 @@ begin
     except
       { Show a friendlier exception message. (By default, Delphi prints out
         the exception class and address.) }
-      WriteStdErr(GetExceptMessage);
+      WriteStdErr(GetExceptMessage, True);
       Halt(2);
     end;
   finally

+ 1 - 0
whatsnew.htm

@@ -93,6 +93,7 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
     <li><i>Fix:</i> Support function <tt>WizardSelectComponents</tt> now also updates component sizes and the current selection's required disk space.</li>
   </ul>
   </li>
+  <li>Console-mode compiler (ISCC) change: Warnings and errors are now colorized.</li>
   <li>Minor tweaks.</li>
 </ul>