-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.Help.pas
136 lines (117 loc) · 4.31 KB
/
Main.Help.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{*******************************************************}
{ YAGE: Yet Another Global Encoder }
{ Unit: Main.Help }
{ Copyright(c) 2021 Alexey Anisimov }
{ Contact email: softlight@ya.ru }
{*******************************************************}
unit Main.Help;
{$MODE delphiunicode}
interface
type
TLogMsgType = (ok, info, warn, error, time);
procedure WriteAppTitle(const AppName: string; const AppDescription: string; const AppVer: string;
const Copyright: string);
procedure WriteAppTitleShort(const AppName: string; const AppVer: string);
procedure WriteAppHelp(const AppName: string; const UsageString: string);
procedure WriteAppLog(const LogMsgType: TLogMsgType; const Msg: string);
procedure WriteAppStartTime(const StartTime: TDateTime);
procedure WriteAppStopTime(const StartTime: TDateTime;
const StopTime: TDateTime; const ElapsedTime: Int64);
resourcestring
rs_StartMsg = '%s/%s: %s / v.%s';
rs_StartMsgShort = '%s v.%s';
rs_LogMsgOk = ' ok ';
rs_LogMsgInfo = 'info';
rs_LogMsgWarn = 'warn';
rs_LogMsgErr = 'err!';
rs_LogMsgTime = 'time';
implementation
uses
Sysutils, Windows, Classes,
Helper.Console;
procedure WriteAppHelp(const AppName: string; const UsageString: string);
var
List: TStringList;
i: Integer;
begin
List := TStringList.Create;
List.Add('');
List.Add(Format(UsageString, [LowerCase(AppName)]));
List.Add('');
List.Add('Keys:');
List.Add('[/from:Encoding] - source file encoding');
List.Add(' valid values:');
List.Add(' - "oem" (default value), "utf8", "unicode"');
List.Add('[/to:Encoding] - destination file encoding');
List.Add(' valid values:');
List.Add(' - "oem", "utf8" (default value), "unicode"');
List.Add('[/file:ResultFileName] - destination file name');
List.Add('[/excel] - use COM to convert Excel');
List.Add('[/log] - show execution details');
List.Add('');
for i := 0 to List.Count - 1 do
Console.WriteLn(List.Strings[i]);
List.Free;
end;
procedure WriteAppTitle(const AppName: string; const AppDescription: string; const AppVer: string;
const Copyright: string);
begin
Console.SetColor(FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED or FOREGROUND_INTENSITY);
Console.Write(AppName);
Console.SetColor();
Console.WriteLn(Format(': %s - v.%s', [AppDescription, AppVer]));
Console.WriteLn(Copyright);
end;
procedure WriteAppTitleShort(const AppName: string; const AppVer: string);
begin
Console.SetColor(FOREGROUND_BLUE or FOREGROUND_GREEN or FOREGROUND_RED or FOREGROUND_INTENSITY);
Console.Write(AppName);
Console.SetColor();
Console.WriteLn(Format(' v.%s', [AppVer]));
end;
procedure WriteAppLog(const LogMsgType: TLogMsgType; const Msg: string);
begin
Console.SetColor();
Console.Write('[');
case LogMsgType of
ok: begin
Console.SetColor(FOREGROUND_BLUE);
Console.Write(rs_LogMsgOk);
end;
info: begin
Console.SetColor(FOREGROUND_GREEN);
Console.Write(rs_LogMsgInfo);
end;
warn: begin
Console.SetColor(FOREGROUND_RED or FOREGROUND_GREEN or FOREGROUND_INTENSITY);
Console.Write(rs_LogMsgWarn);
end;
error: begin
Console.SetColor(FOREGROUND_RED or FOREGROUND_INTENSITY);
Console.Write(rs_LogMsgErr);
end;
time: begin
Console.SetColor(FOREGROUND_GREEN or FOREGROUND_BLUE);
Console.Write(rs_LogMsgTime);
end;
end;
Console.SetColor();
Console.Write(']');
Console.SetColor();
Console.WriteLn(' ' + Msg);
end;
procedure WriteAppStartTime(const StartTime: TDateTime);
begin
WriteAppLog(time, Format('Start: %s / %s', [
FormatDateTime('dd:mm:yy', Trunc(StartTime)),
FormatDateTime('hh:nn:ss', Frac(StartTime))]));
end;
procedure WriteAppStopTime(const StartTime: TDateTime;
const StopTime: TDateTime; const ElapsedTime: Int64);
begin
WriteAppLog(time, Format('Stop: %s / %s', [
FormatDateTime('dd:mm:yy', Trunc(StopTime)),
FormatDateTime('hh:nn:ss', Frac(StopTime))]));
WriteAppLog(info, Format('Elapsed time: %s ms', [IntToStr(ElapsedTime)]));
end;
end.