View Issue Details

IDProjectCategoryView StatusLast Update
0038025FPCCompilerpublic2020-11-06 17:39
ReporterAnton Kavalenka Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038025: compiler: Implement colored terminal output for Win10
DescriptionFollow-up of 0037331
Implemented isatty() for Win10
TagsNo tags attached.
Fixed in Revision47285
FPCOldBugId
FPCTarget-
Attached Files

Activities

Anton Kavalenka

2020-11-02 15:23

reporter  

comphook.diff (1,909 bytes)   
Index: compiler/comphook.pas
===================================================================
--- compiler/comphook.pas	(revision 47282)
+++ compiler/comphook.pas	(working copy)
@@ -173,6 +173,9 @@
 {$ifdef linux}
    ,termio
 {$endif linux}
+{$ifdef mswindows}
+   ,windows
+{$endif mswindows}
    ;
 
 {****************************************************************************
@@ -211,11 +214,12 @@
 type
   TOutputColor = (oc_black,oc_red,oc_green,oc_orange,og_blue,oc_magenta,oc_cyan,oc_lightgray);
 
-{$ifdef linux}
+{$if defined(linux) or defined(MSWINDOWS)}
 const
   CachedIsATTY : Boolean = false;
   IsATTYValue : Boolean = false;
 
+{$ifdef linux}
 function IsATTY(var t : text) : Boolean;
   begin
     if not(CachedIsATTY) then
@@ -227,10 +231,34 @@
   end;
 {$endif linux}
 
+{$ifdef MSWINDOWS}
+const ENABLE_VIRTUAL_TERMINAL_PROCESSING = $0004;
 
+function IsATTY(var t : text) : Boolean;
+  const dwMode: dword = 0;
+  begin
+    if not(CachedIsATTY) then
+      begin
+        IsATTYValue := false;
+        if GetConsoleMode(TextRec(t).handle, dwMode) then
+        begin
+          dwMode := dwMode or ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+          if SetConsoleMode(TextRec(t).handle, dwMode) then
+            IsATTYValue := true;   
+        end; 
+        CachedIsATTY:=true;
+      end;
+    Result:=IsATTYValue;
+  end;
+{$endif MSWINDOWS}
+
+
+{$endif linux or mswindows}
+
+
 procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiString);
   begin
-{$ifdef linux}
+{$if defined(linux) or defined(mswindows)}
      if IsATTY(t) then
        begin
          case color of
@@ -252,9 +280,9 @@
              write(t,#27'[1m'#27'[37m');
          end;
        end;
-{$endif linux}
+{$endif linux or mswindows}
     write(t,s);
-{$ifdef linux}
+{$if defined(linux) or defined(mswindows)}
     if IsATTY(t) then
       write(t,#27'[0m');
 {$endif linux}
comphook.diff (1,909 bytes)   

Anton Kavalenka

2020-11-02 15:28

reporter   ~0126697

Last edited: 2020-11-02 16:48

View 3 revisions

Looks like all working

Florian

2020-11-02 22:38

administrator   ~0126700

Thanks, applied.

CudaText man

2020-11-02 23:41

reporter   ~0126702

Suggestion.
Instead of n places like
{$if defined(linux) or defined(mswindows)}

make additional define, and use it:
{$ifdef color_term}

Issue History

Date Modified Username Field Change
2020-11-02 15:23 Anton Kavalenka New Issue
2020-11-02 15:23 Anton Kavalenka File Added: comphook.diff
2020-11-02 15:23 Anton Kavalenka File Added: Здымак экрана, 2020-11-02 17-22-38.png
2020-11-02 15:28 Anton Kavalenka Note Added: 0126697
2020-11-02 15:55 Anton Kavalenka Note Edited: 0126697 View Revisions
2020-11-02 16:48 Anton Kavalenka Note Edited: 0126697 View Revisions
2020-11-02 22:38 Florian Assigned To => Florian
2020-11-02 22:38 Florian Status new => resolved
2020-11-02 22:38 Florian Resolution open => fixed
2020-11-02 22:38 Florian Fixed in Version => 3.3.1
2020-11-02 22:38 Florian Fixed in Revision => 47285
2020-11-02 22:38 Florian FPCTarget => -
2020-11-02 22:38 Florian Note Added: 0126700
2020-11-02 23:41 CudaText man Note Added: 0126702
2020-11-06 17:39 Anton Kavalenka Status resolved => closed