mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-25 19:18:01 +02:00
Properly handle console mode ENABLE_LINE_INPUT
This commit is contained in:
parent
035335bf7b
commit
015bf14156
2 changed files with 48 additions and 26 deletions
|
@ -265,7 +265,21 @@ namespace System
|
|||
|
||||
public static Result<char8> Read() => In.Read();
|
||||
|
||||
public static Result<void> ReadLine(String strBuffer) => In.ReadLine(strBuffer);
|
||||
public static Result<void> ReadLine(String strBuffer)
|
||||
{
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
var fs = In.BaseStream as FileStream;
|
||||
GetConsoleMode((.)fs.Handle, var consoleMode);
|
||||
consoleMode |= ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
|
||||
SetConsoleMode((.)fs.Handle, consoleMode);
|
||||
#endif
|
||||
var result = In.ReadLine(strBuffer);
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
SetConsoleMode((.)fs.Handle, consoleMode);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Task<String> ReadLineAsync() => In.ReadLineAsync();
|
||||
|
||||
|
|
|
@ -3047,41 +3047,49 @@ BFP_EXPORT intptr BFP_CALLTYPE BfpFile_Read(BfpFile* file, void* buffer, intptr
|
|||
|
||||
if ((file->mIsStd) && (file->mHandle == GetStdHandle(STD_INPUT_HANDLE)))
|
||||
{
|
||||
INPUT_RECORD record;
|
||||
DWORD numRead;
|
||||
while (true)
|
||||
DWORD consoleMode = 0;
|
||||
GetConsoleMode(file->mHandle, &consoleMode);
|
||||
if ((consoleMode & ENABLE_LINE_INPUT) != 0)
|
||||
{
|
||||
if (timeoutMS != -1)
|
||||
forceNormalRead = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
INPUT_RECORD record;
|
||||
DWORD numRead;
|
||||
while (true)
|
||||
{
|
||||
if (!GetNumberOfConsoleInputEvents(file->mHandle, &numRead))
|
||||
if (timeoutMS != -1)
|
||||
{
|
||||
if (!GetNumberOfConsoleInputEvents(file->mHandle, &numRead))
|
||||
{
|
||||
forceNormalRead = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (numRead == 0)
|
||||
{
|
||||
OUTRESULT(BfpFileResult_Timeout);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ReadConsoleInput(file->mHandle, &record, 1, &numRead))
|
||||
{
|
||||
forceNormalRead = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (numRead == 0)
|
||||
if (numRead > 0)
|
||||
{
|
||||
OUTRESULT(BfpFileResult_Timeout);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ReadConsoleInput(file->mHandle, &record, 1, &numRead))
|
||||
{
|
||||
forceNormalRead = true;
|
||||
break;
|
||||
}
|
||||
if (numRead > 0)
|
||||
{
|
||||
if ((record.Event.KeyEvent.bKeyDown) && (record.Event.KeyEvent.uChar.AsciiChar != 0))
|
||||
{
|
||||
memset(buffer, record.Event.KeyEvent.uChar.AsciiChar, 1);
|
||||
OUTRESULT(BfpFileResult_Ok);
|
||||
return 1;
|
||||
if ((record.Event.KeyEvent.bKeyDown) && (record.Event.KeyEvent.uChar.AsciiChar != 0))
|
||||
{
|
||||
memset(buffer, record.Event.KeyEvent.uChar.AsciiChar, 1);
|
||||
OUTRESULT(BfpFileResult_Ok);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ((timeoutMS != -1) && (!forceNormalRead))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue