From 17c0291e86d90a27181304b8adb1d51d79c5b618 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 25 Oct 2020 19:07:44 +0000 Subject: [PATCH] * cache IsATTY value git-svn-id: trunk@47201 - --- compiler/comphook.pas | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/compiler/comphook.pas b/compiler/comphook.pas index 7d9e89f6d4..10c02607d0 100644 --- a/compiler/comphook.pas +++ b/compiler/comphook.pas @@ -211,10 +211,27 @@ end; type TOutputColor = (oc_black,oc_red,oc_green,oc_orange,og_blue,oc_magenta,oc_cyan,oc_lightgray); +{$ifdef linux} +const + CachedIsATTY : Boolean = false; + IsATTYValue : Boolean = false; + +function IsATTY(var t : text) : Boolean; + begin + if not(CachedIsATTY) then + begin + IsATTYValue:=termio.IsATTY(t)=1; + CachedIsATTY:=true; + end; + Result:=IsATTYValue; + end; +{$endif linux} + + procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiString); begin {$ifdef linux} - if IsATTY(t)=1 then + if IsATTY(t) then begin case color of oc_black: @@ -238,7 +255,7 @@ procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiStrin {$endif linux} write(t,s); {$ifdef linux} - if IsATTY(t)=1 then + if IsATTY(t) then write(t,#27'[0m'); {$endif linux} end;