mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 07:39:22 +02:00
LazBuild: Better colored output. Move unit LazTTY to LazUtils. Issue #40878, patch by Anton Kavalenka.
This commit is contained in:
parent
eab8ceff45
commit
be06ee3c92
@ -15,7 +15,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, types, math,
|
Classes, SysUtils, types, math,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazLoggerBase, LazClasses, LazFileUtils, LazStringUtils, LazUTF8;
|
LazLoggerBase, LazClasses, LazFileUtils, LazStringUtils, LazUTF8, laztty;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -536,7 +536,13 @@ begin
|
|||||||
DoOpenFile;
|
DoOpenFile;
|
||||||
if FActiveLogText = nil then exit;
|
if FActiveLogText = nil then exit;
|
||||||
|
|
||||||
WriteLn(FActiveLogText^, s);
|
|
||||||
|
//WriteLn(FActiveLogText^, s);
|
||||||
|
if TTYCheckSupported and IsATTY(FActiveLogText^) then
|
||||||
|
WriteLn(FActiveLogText^, Colorize(s))
|
||||||
|
else
|
||||||
|
WriteLn(FActiveLogText^, s);
|
||||||
|
|
||||||
|
|
||||||
if FCloseLogFileBetweenWrites then
|
if FCloseLogFileBetweenWrites then
|
||||||
DoCloseFile;
|
DoCloseFile;
|
||||||
|
@ -41,6 +41,7 @@ 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);
|
||||||
|
|
||||||
procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiString);
|
procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiString);
|
||||||
|
function Colorize(const s : AnsiString):AnsiString;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -174,29 +175,70 @@ begin
|
|||||||
Result:=IsATTYValue;
|
Result:=IsATTYValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function open_esc(color: TOutputColor):ansistring;
|
||||||
|
begin
|
||||||
|
case color of
|
||||||
|
oc_black:
|
||||||
|
Result:=#27'[1m'#27'[30m';
|
||||||
|
oc_red:
|
||||||
|
Result:=#27'[1m'#27'[31m';
|
||||||
|
oc_green:
|
||||||
|
Result:=#27'[1m'#27'[32m';
|
||||||
|
oc_orange:
|
||||||
|
Result:=#27'[1m'#27'[33m';
|
||||||
|
og_blue:
|
||||||
|
Result:=#27'[1m'#27'[34m';
|
||||||
|
oc_magenta:
|
||||||
|
Result:=#27'[1m'#27'[35m';
|
||||||
|
oc_cyan:
|
||||||
|
Result:=#27'[1m'#27'[36m';
|
||||||
|
oc_lightgray:
|
||||||
|
Result:=#27'[1m'#27'[37m';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
type tkeyword=record
|
||||||
|
t:pchar;
|
||||||
|
c:TOutputColor;
|
||||||
|
end;
|
||||||
|
|
||||||
|
const terms:array[0..6] of tkeyword =
|
||||||
|
(
|
||||||
|
(t:'Note:';c:oc_orange),
|
||||||
|
(t:'Hint:';c:oc_lightgray),
|
||||||
|
(t:'Warning:';c:oc_magenta),
|
||||||
|
(t:'Error:';c:oc_red),
|
||||||
|
(t:'(lazbuild)';c:oc_lightgray),
|
||||||
|
(t:'(lazarus)';c:oc_cyan),
|
||||||
|
(t:'gtk2';c:oc_green)
|
||||||
|
);
|
||||||
|
|
||||||
|
function Colorize(const s : AnsiString):AnsiString;
|
||||||
|
var
|
||||||
|
i,p,ll:integer;
|
||||||
|
color:ToutputColor;
|
||||||
|
p1,p2,p3:ansistring;
|
||||||
|
begin
|
||||||
|
for i:=0 to high(terms) do
|
||||||
|
begin
|
||||||
|
p:=pos(terms[i].t,s);
|
||||||
|
if p<=0 then continue;
|
||||||
|
ll:=length(terms[i].t);
|
||||||
|
p1:=copy(s,1,p-1);
|
||||||
|
p2:=copy(s,p,ll);
|
||||||
|
p3:=copy(s,p+ll,length(s));
|
||||||
|
Result:=p1+
|
||||||
|
open_esc(terms[i].c)+p2+#27'[0m'+
|
||||||
|
p3;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result:=s;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiString);
|
procedure WriteColoredOutput(var t: Text;color: TOutputColor;const s : AnsiString);
|
||||||
begin
|
begin
|
||||||
if TTYCheckSupported and IsATTY(t) then
|
if TTYCheckSupported and IsATTY(t) then
|
||||||
begin
|
write(t,open_esc(color));
|
||||||
case color of
|
|
||||||
oc_black:
|
|
||||||
write(t,#27'[1m'#27'[30m');
|
|
||||||
oc_red:
|
|
||||||
write(t,#27'[1m'#27'[31m');
|
|
||||||
oc_green:
|
|
||||||
write(t,#27'[1m'#27'[32m');
|
|
||||||
oc_orange:
|
|
||||||
write(t,#27'[1m'#27'[33m');
|
|
||||||
og_blue:
|
|
||||||
write(t,#27'[1m'#27'[34m');
|
|
||||||
oc_magenta:
|
|
||||||
write(t,#27'[1m'#27'[35m');
|
|
||||||
oc_cyan:
|
|
||||||
write(t,#27'[1m'#27'[36m');
|
|
||||||
oc_lightgray:
|
|
||||||
write(t,#27'[1m'#27'[37m');
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
write(t,s);
|
write(t,s);
|
||||||
if TTYCheckSupported and IsATTY(t) then
|
if TTYCheckSupported and IsATTY(t) then
|
||||||
write(t,#27'[0m');
|
write(t,#27'[0m');
|
Loading…
Reference in New Issue
Block a user