2015-09-24 21:01:35 +02:00
|
|
|
unit UWriter;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2015-09-24 21:19:00 +02:00
|
|
|
Classes, SysUtils, UFilter, crt, fgl;
|
2015-09-24 21:01:35 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
TWriter = class
|
|
|
|
public
|
2015-09-24 21:19:00 +02:00
|
|
|
procedure WriteContent(AContent: String;
|
|
|
|
AHighlights: THighlights); virtual; abstract;
|
2015-09-24 21:01:35 +02:00
|
|
|
end;
|
|
|
|
TWriterList = specialize TFPGObjectList<TWriter>;
|
|
|
|
|
|
|
|
{ TConsoleWriter }
|
|
|
|
|
|
|
|
TConsoleWriter = class(TWriter)
|
|
|
|
public
|
2015-09-24 21:19:00 +02:00
|
|
|
procedure WriteContent(AContent: String;
|
|
|
|
AHighlights: THighlights); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ THTMLWriter }
|
|
|
|
|
|
|
|
THTMLWriter = class(TWriter)
|
|
|
|
protected
|
|
|
|
FFileStream: TFileStream;
|
|
|
|
procedure WriteLine(AContent: String);
|
|
|
|
public
|
|
|
|
constructor Create(AFileName: String);
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure WriteContent(AContent: String;
|
|
|
|
AHighlights: THighlights); override;
|
2015-09-24 21:01:35 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2015-09-24 21:19:00 +02:00
|
|
|
{ THTMLWriter }
|
|
|
|
|
|
|
|
procedure THTMLWriter.WriteLine(AContent: String);
|
|
|
|
begin
|
|
|
|
AContent := AContent + LineEnding;
|
|
|
|
FFileStream.Write(AContent[1], Length(AContent));
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor THTMLWriter.Create(AFileName: String);
|
|
|
|
begin
|
|
|
|
FFileStream := TFileStream.Create(AFileName, fmCreate);
|
|
|
|
WriteLine('<html>');
|
|
|
|
WriteLine('<body>');
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor THTMLWriter.Destroy;
|
|
|
|
begin
|
|
|
|
WriteLine('</body>');
|
|
|
|
WriteLine('</html>');
|
|
|
|
FFileStream.Free;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure THTMLWriter.WriteContent(AContent: String; AHighlights: THighlights);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2015-09-24 21:01:35 +02:00
|
|
|
{ TConsoleWriter }
|
|
|
|
|
2015-09-24 21:19:00 +02:00
|
|
|
procedure TConsoleWriter.WriteContent(AContent: String; AHighlights: THighlights
|
|
|
|
);
|
2015-09-24 21:01:35 +02:00
|
|
|
var
|
|
|
|
matchPos, offset, lastPos: Integer;
|
|
|
|
highlight: THighlight;
|
|
|
|
begin
|
|
|
|
lastPos := 1;
|
|
|
|
|
2015-09-24 21:19:00 +02:00
|
|
|
for highlight in AHighlights do
|
2015-09-24 21:01:35 +02:00
|
|
|
begin
|
|
|
|
matchPos := highlight.Start;
|
|
|
|
offset := highlight.Length;
|
|
|
|
write(Copy(AContent, lastPos, matchPos - lastPos));
|
|
|
|
if highlight.FGColor < $FF then
|
|
|
|
TextColor(highlight.FGColor);
|
|
|
|
if highlight.BGColor < $FF then
|
|
|
|
TextBackground(highlight.BGColor);
|
|
|
|
write(Copy(AContent, matchPos, offset));
|
|
|
|
NormVideo;
|
|
|
|
lastPos := matchPos + offset;
|
|
|
|
end;
|
|
|
|
|
|
|
|
writeln(Copy(AContent, lastPos, Length(AContent)));
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|