-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleProgressMonitor.pas
105 lines (89 loc) · 2.87 KB
/
ConsoleProgressMonitor.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{**
DelphiPI (Delphi Package Installer)
Author : ibrahim dursun (ibrahimdursun gmail)
License : GNU General Public License 2.0
**}
unit ConsoleProgressMonitor;
interface
uses PackageInfo, ProgressMonitor;
type
TConsoleOutputLevel = (colSilent, colBrief, colFull);
TConsoleProgressMonitor = class(TInterfacedObject, IProgressMonitor)
private
fOutputLevel: TConsoleOutputLevel;
fStartTime: TDateTime;
published
public
procedure CompilerOutput(const line: string);
procedure Finished;
procedure Log(const text: string);
procedure PackageProcessed(const packageInfo: TPackageInfo;
status: TPackageStatus);
procedure Started;
property OutputLevel: TConsoleOutputLevel read fOutputLevel write fOutputLevel;
end;
implementation
uses DateUtils, SysUtils, StrUtils, JclConsole;
procedure WriteLine(color: TJclScreenFontColor; text: string); overload;
begin
TJclConsole.Default.Screens[0].Writeln(text, TJclScreenTextAttribute.Create(color,bclBlack, color <> fclWhite));
end;
procedure WriteLine(text: string=''); overload;
begin
TJclConsole.Default.Screens[0].Writeln(text, TJclScreenTextAttribute.Create(fclWhite, bclBlack, false));
end;
{ TConsoleProgressMonitor }
procedure TConsoleProgressMonitor.CompilerOutput(const line: string);
begin
if length(line) > 256 then exit; //throws system error 87
if OutputLevel = colSilent then exit;
if OutputLevel = TConsoleOutputLevel.colFull then
WriteLn(line)
else if (Pos('Fatal:', line) > 0) or (Pos('Error', line) > 0) then
WriteLine(fclRed,line);
end;
procedure TConsoleProgressMonitor.Finished;
begin
if OutputLevel = TConsoleOutputLevel.colSilent then
exit;
WriteLine(fclWhite, 'Completed in ' + floattostr(MilliSecondsBetween(GetTime, fStartTime)) + ' ms');
end;
procedure TConsoleProgressMonitor.Log(const text: string);
begin
if OutputLevel = TConsoleOutputLevel.colFull then
begin
if StartsStr('-=', text) then
WriteLine(fclYellow, text)
else
WriteLine(text);
end;
end;
procedure TConsoleProgressMonitor.PackageProcessed(
const packageInfo: TPackageInfo; status: TPackageStatus);
begin
if OutputLevel = TConsoleOutputLevel.colSilent then
exit;
case status of
psNone: ;
psCompiling:
WriteLine('[Compile] ' + packageInfo.PackageName);
psInstalling:
WriteLine('[Install] ' + packageInfo.PackageName);
psSuccess: begin
WriteLine(fclGreen, '[Success] ' + packageInfo.PackageName);
WriteLine;
end;
psError: begin
WriteLine(fclRed, '[Fail ] ' + packageInfo.PackageName);
WriteLine;
end;
end;
end;
procedure TConsoleProgressMonitor.Started;
begin
if OutputLevel = TConsoleOutputLevel.colSilent then
exit;
WriteLine('Starting');
fStartTime := GetTime;
end;
end.