Skip to content
Permalink
Browse files

let ConsoleWaitForEnterKey call Synchronize on Linux

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Jul 26, 2019
1 parent 7e37f5d commit 893b7df4827130a6f5aef53723e07c3c5b822514
Showing with 32 additions and 4 deletions.
  1. +19 −3 SynCommons.pas
  2. +12 −0 SynFPCLinux.pas
  3. +1 −1 SynopseCommit.inc
/// change the Windows console text background color
procedure TextBackground(Color: TConsoleColor);

/// will wait for the ENTER key to be pressed, processing the internal
// Windows Message loop and any Synchronize() pending notification
/// will wait for the ENTER key to be pressed, processing Synchronize() pending
// notifications, and the internal Windows Message loop (on this OS)

// - to be used e.g. for proper work of console applications with interface-based
// service implemented as optExecInMainThread
procedure ConsoleWaitForEnterKey;
end;

procedure ConsoleWaitForEnterKey;
var c: AnsiChar;
begin
Readln;
{$ifdef FPC}
if IsMultiThread and (GetCurrentThreadID=MainThreadID) then
repeat
CheckSynchronize(100);
if UnixKeyPending then
repeat
c := #0;
if FpRead(StdInputHandle,c,1)<>1 then
break;
if c in [#10,#13] then
exit;
until false;
until false else
{$endif FPC}
ReadLn;
end;

{$endif MSWINDOWS}
@@ -194,6 +194,9 @@ function GetTickCount: cardinal; inline;
// you can force SleepHiRes0Yield=true to change this behavior)
procedure SleepHiRes(ms: cardinal); inline;

/// check if any char is pending from StdInputHandle file descriptor
function UnixKeyPending: boolean;


implementation

@@ -223,6 +226,15 @@ procedure DeleteCriticalSection(var cs : TRTLCriticalSection);
DoneCriticalSection(cs);
end;

function UnixKeyPending: boolean;
var
fdsin: tfdSet;
begin
fpFD_ZERO(fdsin);
fpFD_SET(StdInputHandle,fdsin);
result := fpSelect(StdInputHandle+1,@fdsin,nil,nil,0)>0;
end;

{$ifdef LINUX}

const // Date Translation - see http://en.wikipedia.org/wiki/Julian_day
@@ -1 +1 @@
'1.18.5291'
'1.18.5292'

0 comments on commit 893b7df

Please sign in to comment.
You can’t perform that action at this time.