-
Notifications
You must be signed in to change notification settings - Fork 90
/
Grijjy.Console.pas
59 lines (47 loc) · 933 Bytes
/
Grijjy.Console.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
unit Grijjy.Console;
{$INCLUDE 'Grijjy.inc'}
interface
uses
{$IFDEF LINUX}
Posix.Signal,
{$ENDIF}
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF}
SysUtils;
procedure WaitForCtrlC;
implementation
var
Control_C: Boolean = False;
{$IFDEF MSWINDOWS}
function ConsoleCtrlHandler(dwCtrlType: DWORD): BOOL; stdcall;
begin
if (dwCtrlType = CTRL_C_EVENT) then
Control_C := True;
Result := True;
end;
{$ENDIF}
{$IFDEF LINUX}
var
sigIntHandler: sigaction_t;
procedure SigHandler(SigNum: Integer); cdecl;
begin
Control_C := True;
end;
{$ENDIF}
procedure WaitForCtrlC;
begin
while not Control_C do
Sleep(25);
end;
initialization
{$IFDEF MSWINDOWS}
Windows.SetConsoleCtrlHandler(@ConsoleCtrlHandler, True);
{$ENDIF}
{$IFDEF LINUX}
sigIntHandler._u.sa_handler := @SigHandler;
sigemptyset(sigIntHandler.sa_mask);
sigIntHandler.sa_flags := 0;
sigaction(SIGINT, @sigIntHandler, nil);
{$ENDIF}
end.