diff --git a/UApp.pas b/UApp.pas index 2c41d9b..90a8ff3 100644 --- a/UApp.pas +++ b/UApp.pas @@ -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);