mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-11 10:49:30 +02:00
* cache IsATTY value
git-svn-id: trunk@47201 -
This commit is contained in:
parent
ff6a58ff89
commit
17c0291e86
@ -211,10 +211,27 @@ end;
|
|||||||
type
|
type
|
||||||
TOutputColor = (oc_black,oc_red,oc_green,oc_orange,og_blue,oc_magenta,oc_cyan,oc_lightgray);
|
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);
|
procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiString);
|
||||||
begin
|
begin
|
||||||
{$ifdef linux}
|
{$ifdef linux}
|
||||||
if IsATTY(t)=1 then
|
if IsATTY(t) then
|
||||||
begin
|
begin
|
||||||
case color of
|
case color of
|
||||||
oc_black:
|
oc_black:
|
||||||
@ -238,7 +255,7 @@ procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiStrin
|
|||||||
{$endif linux}
|
{$endif linux}
|
||||||
write(t,s);
|
write(t,s);
|
||||||
{$ifdef linux}
|
{$ifdef linux}
|
||||||
if IsATTY(t)=1 then
|
if IsATTY(t) then
|
||||||
write(t,#27'[0m');
|
write(t,#27'[0m');
|
||||||
{$endif linux}
|
{$endif linux}
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user