Added Ctrl+C support (*cough*)

This commit is contained in:
Andreas Schneider 2015-09-25 15:03:10 +02:00
parent c3c26681e1
commit 80142da589
1 changed files with 22 additions and 3 deletions

View File

@ -26,7 +26,7 @@ interface
uses
Classes, SysUtils, CustApp, RegExpr, Math,
UFilter, UWriter;
UFilter, UWriter, Crt;
type
@ -48,6 +48,8 @@ type
//Logfile handling
procedure DumpFile(AFileName: String);
procedure PollFile(AFileName: String);
//Key Handling
function CheckQuit: Boolean;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
@ -236,10 +238,13 @@ begin
Reset(logFile);
// Filter log
while not EOF(logFile) do
while (not Terminated) and (not EOF(logFile)) do
begin
Readln(logFile, line);
FilterLine(line);
if CheckQuit then
Terminate;
end;
CloseFile(logFile);
@ -263,7 +268,7 @@ begin
bufPos := 0;
bufMax := 0;
lastSize := 0;
while true do
while not Terminated do
begin
currentSize := FileSize(f);
if currentSize > lastSize then
@ -333,10 +338,24 @@ begin
lastSize := currentSize;
end;
Sleep(100);
if CheckQuit then
Terminate;
end;
end;
// This is necessary since we use CRT, which captures all keys.
// Therefore Ctrl+C will by default no longer send SIGINT.
function TLogFilterApplication.CheckQuit: Boolean;
begin
Result := False;
if KeyPressed then
if ReadKey = ^C then
Result := True;
end;
constructor TLogFilterApplication.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);