mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Unbuffering stdout
This commit is contained in:
parent
bc5c425d1b
commit
4a819762e6
3 changed files with 17 additions and 6 deletions
|
@ -90,13 +90,12 @@ namespace System
|
|||
|
||||
static function void(StringView str) OutString = => OutString_Simple;
|
||||
|
||||
public static extern void PutChar(char8 c);
|
||||
private static extern void PutChars(char8* c, int32 len);
|
||||
public static extern void ReopenHandles();
|
||||
|
||||
static void OutString_Simple(StringView str)
|
||||
{
|
||||
for (var c in str.RawChars)
|
||||
PutChar(c);
|
||||
PutChars(str.Ptr, (.)str.Length);
|
||||
}
|
||||
|
||||
static void OutString_Ex(StringView str)
|
||||
|
|
|
@ -183,8 +183,9 @@ namespace bf
|
|||
|
||||
class Console
|
||||
{
|
||||
private:
|
||||
BFRT_EXPORT static void PutChars(char* ptr, int len);
|
||||
public:
|
||||
BFRT_EXPORT static void PutChar(char c);
|
||||
BFRT_EXPORT static void ReopenHandles();
|
||||
};
|
||||
|
||||
|
|
|
@ -292,9 +292,20 @@ static void NTAPI TlsFreeFunc(void* ptr)
|
|||
gBfRtCallbacks.Thread_Exiting();
|
||||
}
|
||||
|
||||
void bf::System::Console::PutChar(char c)
|
||||
void bf::System::Console::PutChars(char* ptr, int len)
|
||||
{
|
||||
putchar(c);
|
||||
#ifdef BF_PLATFORM_WINDOWS
|
||||
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD numBytesWritten = 0;
|
||||
::WriteFile(handle, ptr, (DWORD)len, &numBytesWritten, NULL);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
putchar(ptr[i]);
|
||||
}
|
||||
|
||||
void bf::System::Console::ReopenHandles()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue