From 6cdeaad6b66b9a249ec233b9806edc092e9ef83e Mon Sep 17 00:00:00 2001 From: Pavel <68122101+red-prig@users.noreply.github.com> Date: Tue, 14 Feb 2023 19:34:22 +0300 Subject: [PATCH] Safer color change --- sys/sys_crt.pas | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sys/sys_crt.pas b/sys/sys_crt.pas index 8063b9dd..bbb005bc 100644 --- a/sys/sys_crt.pas +++ b/sys/sys_crt.pas @@ -58,16 +58,20 @@ Begin n:=0; _sig_lock(SL_NOINTRRUP); - EnterCriticalSection(StdOutLock); if Boolean(t.UserData[2]) then //IsChar begin - SetConsoleTextAttribute(t.Handle,t.UserData[1]); - WriteConsole(t.Handle, - data, - len, - @n, - nil); + EnterCriticalSection(StdOutLock); + //Text + SetConsoleTextAttribute(t.Handle,t.UserData[1]); + WriteConsole(t.Handle, + data, + len, + @n, + nil); + SetConsoleTextAttribute(t.Handle,StdOutColor); + //Text + LeaveCriticalSection(StdOutLock); end else begin WriteFile(t.Handle, @@ -77,7 +81,6 @@ Begin nil); end; - LeaveCriticalSection(StdOutLock); _sig_unlock(SL_NOINTRRUP); end;