[*] Made conapi requirement under Win32 optional and completely nuke the code when building under non-win32 targets

This commit is contained in:
Reece Wilson 2024-04-14 23:11:15 +01:00
parent 528cb01679
commit 88a07714e5
5 changed files with 413 additions and 110 deletions

View File

@ -305,7 +305,22 @@ namespace Aurora
ADD_GET_PROC(Kernel32, RemoveDllDirectory)
ADD_GET_PROC(Kernel32, AddDllDirectory)
ADD_GET_PROC(Kernel32, SetProcessInformation)
ADD_GET_PROC(Kernel32, GetConsoleScreenBufferInfo)
ADD_GET_PROC(Kernel32, SetConsoleScreenBufferSize)
ADD_GET_PROC(Kernel32, SetConsoleWindowInfo)
ADD_GET_PROC(Kernel32, CreateConsoleScreenBuffer)
ADD_GET_PROC(Kernel32, SetConsoleCursorPosition)
ADD_GET_PROC(Kernel32, FillConsoleOutputCharacterW)
ADD_GET_PROC(Kernel32, FillConsoleOutputAttribute)
ADD_GET_PROC(Kernel32, SetConsoleTextAttribute)
ADD_GET_PROC(Kernel32, SetConsoleActiveScreenBuffer)
ADD_GET_PROC(Kernel32, ScrollConsoleScreenBufferW)
ADD_GET_PROC(Kernel32, WriteConsoleInputW)
ADD_GET_PROC(Kernel32, WriteConsoleW)
ADD_GET_PROC(Kernel32, ReadConsoleInputW)
ADD_GET_PROC(Kernel32, GetNumberOfConsoleInputEvents)
ADD_GET_PROC_BI2(Kernel32, PSAPILegacy, K32GetProcessMemoryInfo, GetProcessMemoryInfo)
ADD_GET_PROC(Sync, WaitOnAddress)

View File

@ -23,6 +23,9 @@ struct _SP_DEVINFO_DATA;
struct _SP_DEVICE_INTERFACE_DATA;
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W;
struct _NETRESOURCEW;
struct _CONSOLE_SCREEN_BUFFER_INFO;
struct _SMALL_RECT;
struct _CHAR_INFO;
enum _TOKEN_INFORMATION_CLASS;
enum _SE_OBJECT_TYPE;
enum _MINIDUMP_TYPE;
@ -353,6 +356,95 @@ namespace Aurora
LPVOID ProcessInformation,
DWORD ProcessInformationSize
);
inline BOOL(__stdcall *pGetConsoleScreenBufferInfo)(
HANDLE hConsoleOutput,
_CONSOLE_SCREEN_BUFFER_INFO*lpConsoleScreenBufferInfo
);
inline BOOL(__stdcall *pSetConsoleScreenBufferSize)(
HANDLE hConsoleOutput,
COORD dwSize
);
inline BOOL(__stdcall *pSetConsoleWindowInfo)(
HANDLE hConsoleOutput,
BOOL bAbsolute,
CONST _SMALL_RECT * lpConsoleWindow
);
inline HANDLE(__stdcall *pCreateConsoleScreenBuffer)(
DWORD dwDesiredAccess,
DWORD dwShareMode,
CONST _SECURITY_ATTRIBUTES *lpSecurityAttributes,
DWORD dwFlags,
LPVOID lpScreenBufferData
);
inline BOOL(__stdcall *pSetConsoleCursorPosition)(
HANDLE hConsoleOutput,
COORD dwCursorPosition
);
inline BOOL(__stdcall *pFillConsoleOutputCharacterW)(
HANDLE hConsoleOutput,
WCHAR cCharacter,
DWORD nLength,
COORD dwWriteCoord,
LPDWORD lpNumberOfCharsWritten
);
inline BOOL(__stdcall *pFillConsoleOutputAttribute)(
HANDLE hConsoleOutput,
WORD wAttribute,
DWORD nLength,
COORD dwWriteCoord,
LPDWORD lpNumberOfAttrsWritten
);
inline BOOL(__stdcall *pSetConsoleTextAttribute)(
HANDLE hConsoleOutput,
WORD wAttributes
);
inline BOOL(__stdcall *pSetConsoleActiveScreenBuffer)(
HANDLE hConsoleOutput
);
inline BOOL(__stdcall *pScrollConsoleScreenBufferW)(
HANDLE hConsoleOutput,
CONST _SMALL_RECT * lpScrollRectangle,
CONST _SMALL_RECT * lpClipRectangle,
COORD dwDestinationOrigin,
CONST _CHAR_INFO * lpFill
);
inline BOOL(__stdcall *pGetNumberOfConsoleInputEvents)(
HANDLE hConsoleInput,
LPDWORD lpNumberOfEvents
);
inline BOOL(__stdcall *pReadConsoleInputW)(
HANDLE hConsoleInput,
_INPUT_RECORD * lpBuffer,
DWORD nLength,
LPDWORD lpNumberOfEventsRead
);
inline BOOL(__stdcall *pWriteConsoleInputW)(
HANDLE hConsoleInput,
CONST _INPUT_RECORD * lpBuffer,
DWORD nLength,
LPDWORD lpNumberOfEventsWritten
);
inline BOOL(__stdcall *pWriteConsoleW)(
HANDLE hConsoleInput,
CONST wchar_t * lpBuffer,
DWORD nLength,
LPDWORD lpNumberOfEventsWritten,
void * pReserved
);
inline BOOL(__stdcall *pPrefetchVirtualMemory)(
HANDLE hProcess,

View File

@ -82,7 +82,11 @@ namespace Aurora::Console::ConsoleStd
#if defined(AURORA_IS_MODERNNT_DERIVED)
ConsoleSecondaryDataLoopSource(LSEvent *pAltHandle) : LSEvent(false, true, true)
{
handles = { /*pAltHandle->GetHandle()*/AuUInt(GetStdHandle(STD_INPUT_HANDLE)), LSEvent::GetHandle()};
#if defined(STD_INPUT_HANDLE)
handles = { /*pAltHandle->GetHandle()*/AuUInt(GetStdHandle(STD_INPUT_HANDLE)), LSEvent::GetHandle() };
#else
handles = { LSEvent::GetHandle() };
#endif
}
#else
ConsoleSecondaryDataLoopSource(int fd) : LSEvent(false, true, true)
@ -278,6 +282,7 @@ namespace Aurora::Console::ConsoleStd
void ProcessCanonical(HANDLE h)
{
#if defined(AURORA_PLATFORM_WIN32)
INPUT_RECORD records[4096];
DWORD dwRecords;
@ -296,7 +301,13 @@ namespace Aurora::Console::ConsoleStd
return;
}
if (!GetNumberOfConsoleInputEvents(h,
if (!pGetNumberOfConsoleInputEvents ||
!pReadConsoleInputW)
{
return;
}
if (!pGetNumberOfConsoleInputEvents(h,
&dwRecords))
{
return;
@ -308,10 +319,10 @@ namespace Aurora::Console::ConsoleStd
return;
}
if (!ReadConsoleInputW(h,
records,
dwRecords,
&dwRecords))
if (!pReadConsoleInputW(h,
records,
dwRecords,
&dwRecords))
{
return;
}
@ -558,6 +569,9 @@ namespace Aurora::Console::ConsoleStd
return;
}
}
#else
//
#endif
}
void NoncanonicalTick()
@ -590,6 +604,7 @@ namespace Aurora::Console::ConsoleStd
{
DWORD mode;
#if defined(AURORA_PLATFORM_WIN32)
if (!GetConsoleMode(gInputStream, &mode))
{
return false;
@ -624,14 +639,16 @@ namespace Aurora::Console::ConsoleStd
niceWorkMicrosoft[1].Event.KeyEvent.wVirtualScanCode = pMapVirtualKeyA(VK_RETURN, MAPVK_VK_TO_VSC);
DWORD idc;
WriteConsoleInputW(gInputStream, niceWorkMicrosoft, 2, &idc);
WriteConsoleInputW(gInputStream, niceWorkMicrosoft, 2, &idc);
pWriteConsoleInputW(gInputStream, niceWorkMicrosoft, 2, &idc);
pWriteConsoleInputW(gInputStream, niceWorkMicrosoft, 2, &idc);
return true;
#endif
}
void LeaveNoncanonicalMode()
{
#if defined(AURORA_PLATFORM_WIN32)
if (!AuExchange(gCanonicalEnabled, false))
{
return;
@ -639,6 +656,7 @@ namespace Aurora::Console::ConsoleStd
SetConsoleMode(gInputStream, gCanonicalBackup);
gWin32Thread = CreateThread(nullptr, 0, StdInWin32Thread, nullptr, 0, nullptr);
#endif
}
#else
@ -697,7 +715,8 @@ namespace Aurora::Console::ConsoleStd
bool IsStdOutTTY()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
#if defined(AURORA_PLATFORM_WIN32)
//#if defined(AURORA_IS_MODERNNT_DERIVED)
HANDLE hConsole;
DWORD dwType;
@ -710,7 +729,8 @@ namespace Aurora::Console::ConsoleStd
return dwType == FILE_TYPE_CHAR;
#else
return IsStdOutTTY(STDOUT_FILENO);
return false;
//return IsStdOutTTY(STDOUT_FILENO);
#endif
}
@ -876,6 +896,7 @@ namespace Aurora::Console::ConsoleStd
if (isNotPipe)
{
#if defined(AURORA_PLATFORM_WIN32)
// Get current console flags
if (GetConsoleMode(gOutputStream, &dwMode))
{
@ -915,15 +936,20 @@ namespace Aurora::Console::ConsoleStd
#endif
}
#endif
}
if (gRuntimeConfig.console.enableStdPassthrough && gRuntimeConfig.console.enableStdIn && isNotPipe)
{
#if defined(AURORA_PLATFORM_WIN32)
if (!GetConsoleMode(gInputStream, &dwMode))
{
ok = SetConsoleMode(gInputStream, dwMode & ~(ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT));
SysAssert(ok, "Couldn't maintain binary stdin stream");
}
#endif
}
//else
{

View File

@ -10,14 +10,22 @@
#include <Source/Console/ColorConvert.hpp>
#include <Source/Console/ConsoleStd/ConsoleStd.hpp>
#if !defined(WINAPI_FAMILY_PARTITION) || \
WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM)
#define ENABLE_CONTTY
#endif
namespace Aurora::Console::ConsoleTTY
{
static HANDLE gConsole {INVALID_HANDLE_VALUE};
static COORD gSavedCoord {};
static HANDLE gConsole { INVALID_HANDLE_VALUE };
static bool gIsRecording {};
static AuThreadPrimitives::Mutex gRecordLock;
static AuList<AuFunction<void()>> gRecordedActions {};
#if defined(ENABLE_CONTTY)
static COORD gSavedCoord {};
#endif
static bool gIsRecording {};
static AuMutex gRecordLock;
static AuList<AuFunction<void()>> gRecordedActions;
struct Console
{
@ -49,6 +57,14 @@ namespace Aurora::Console::ConsoleTTY
AUKN_SYM void TTYClearLine(EAnsiColor bgColor)
{
#if defined(ENABLE_CONTTY)
if (!pSetConsoleCursorPosition ||
!pGetConsoleScreenBufferInfo ||
!pFillConsoleOutputCharacterW)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYClearLine, bgColor);
HANDLE hConsole;
@ -57,34 +73,43 @@ namespace Aurora::Console::ConsoleTTY
hConsole = GetTTYHandle();
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
if (!FillConsoleOutputCharacterW(hConsole,
L' ',
csbi.dwSize.X,
COORD {0, csbi.dwCursorPosition.Y},
&cCharsWritten))
if (!pFillConsoleOutputCharacterW(hConsole,
L' ',
csbi.dwSize.X,
COORD {0, csbi.dwCursorPosition.Y},
&cCharsWritten))
{
return;
}
if (!FillConsoleOutputAttribute(hConsole,
bgColor == EAnsiColor::eEnumCount ? csbi.wAttributes : kAnsiColorBackgroundToNT[AuStaticCast<AuUInt>(bgColor)],
csbi.dwSize.X,
COORD {0, csbi.dwCursorPosition.Y},
&cCharsWritten))
if (!pFillConsoleOutputAttribute(hConsole,
bgColor == EAnsiColor::eEnumCount ? csbi.wAttributes : kAnsiColorBackgroundToNT[AuStaticCast<AuUInt>(bgColor)], // TODO: Why?
csbi.dwSize.X,
COORD {0, csbi.dwCursorPosition.Y},
&cCharsWritten))
{
return;
}
SetConsoleCursorPosition(hConsole, {0, csbi.dwCursorPosition.Y});
pSetConsoleCursorPosition(hConsole, {0, csbi.dwCursorPosition.Y});
#endif
}
AUKN_SYM void TTYClearScreen()
{
#if defined(ENABLE_CONTTY)
if (!pGetConsoleScreenBufferInfo ||
!pFillConsoleOutputCharacterW ||
!pFillConsoleOutputAttribute)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYClearScreen);
HANDLE hConsole;
@ -94,41 +119,48 @@ namespace Aurora::Console::ConsoleTTY
hConsole = GetTTYHandle();
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
if (!FillConsoleOutputCharacterW(hConsole,
L' ',
dwConSize,
COORD {0, 0},
if (!pFillConsoleOutputCharacterW(hConsole,
L' ',
dwConSize,
COORD {0, 0},
&cCharsWritten))
{
return;
}
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
if (!pFillConsoleOutputAttribute(hConsole,
csbi.wAttributes,
dwConSize,
COORD {0, 0},
&cCharsWritten))
{
return;
}
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
if (!FillConsoleOutputAttribute(hConsole,
csbi.wAttributes,
dwConSize,
COORD {0, 0},
&cCharsWritten))
{
return;
}
SetConsoleCursorPosition(hConsole, {0, 0});
pSetConsoleCursorPosition(hConsole, {0, 0});
#endif
}
AUKN_SYM void TTYFill(char character, EAnsiColor fgColor, EAnsiColor bgColor)
{
#if defined(ENABLE_CONTTY)
if (!pGetConsoleScreenBufferInfo)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYFill, character, fgColor, bgColor);
DWORD attrib {0}, cCharsWritten {};
@ -137,7 +169,7 @@ namespace Aurora::Console::ConsoleTTY
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
@ -156,26 +188,27 @@ namespace Aurora::Console::ConsoleTTY
attrib |= kAnsiColorBackgroundToNT[AuStaticCast<AuUInt>(bgColor)];
}
if (!FillConsoleOutputCharacterW(hConsole,
L' ',
csbi.dwSize.X * csbi.dwSize.Y,
COORD {0, 0},
&cCharsWritten))
if (!pFillConsoleOutputCharacterW(hConsole,
L' ',
csbi.dwSize.X * csbi.dwSize.Y,
COORD {0, 0},
&cCharsWritten))
{
return;
}
if (attrib)
{
if (!FillConsoleOutputAttribute(hConsole,
attrib,
csbi.dwSize.X * csbi.dwSize.Y,
COORD {0, 0},
&cCharsWritten))
if (!pFillConsoleOutputAttribute(hConsole,
attrib,
csbi.dwSize.X * csbi.dwSize.Y,
COORD {0, 0},
&cCharsWritten))
{
//return;
}
}
#endif
}
AUKN_SYM AuUInt32 TTYWrite(const void *buffer, AuUInt32 length)
@ -186,6 +219,13 @@ namespace Aurora::Console::ConsoleTTY
AUKN_SYM void TTYWrite(const char *string, EAnsiColor fgColor, EAnsiColor bgColor)
{
#if defined(ENABLE_CONTTY)
if (!pSetConsoleTextAttribute)
{
ConsoleStd::WriteStdOutBlocking2(string, strlen(string));
return;
}
TTY_RECORD_FOR_FLIP((void(*)(const char *, EAnsiColor, EAnsiColor))(TTYWrite), string, fgColor, bgColor);
DWORD attrib {};
@ -210,7 +250,7 @@ namespace Aurora::Console::ConsoleTTY
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
@ -218,57 +258,96 @@ namespace Aurora::Console::ConsoleTTY
attrib |= csbi.wAttributes & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
}
SetConsoleTextAttribute(hConsole, attrib);
pSetConsoleTextAttribute(hConsole, attrib);
TTYWrite(string, AuUInt32(strlen(string)));
SetConsoleTextAttribute(hConsole, FOREGROUND_WHITE);
pSetConsoleTextAttribute(hConsole, FOREGROUND_WHITE);
#else
ConsoleStd::WriteStdOutBlocking2(string, strlen(string));
#endif
}
AUKN_SYM void TTYReturnHome()
{
#if defined(ENABLE_CONTTY)
if (!pSetConsoleCursorPosition)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYReturnHome);
SetConsoleCursorPosition(GetTTYHandle(), {0, 0});
pSetConsoleCursorPosition(GetTTYHandle(), {0, 0});
#endif
}
AUKN_SYM AuPair<AuUInt32, AuUInt32> TTYScreenSize()
{
#if defined(ENABLE_CONTTY)
if (!pGetConsoleScreenBufferInfo)
{
return {};
}
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hConsole;
hConsole = GetTTYHandle();
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return {};
}
return AuMakePair(AuStaticCast<AuUInt32>(csbi.srWindow.Right - csbi.srWindow.Left + 1),
AuStaticCast<AuUInt32>(csbi.srWindow.Bottom - csbi.srWindow.Top + 1));
#else
return {};
#endif
}
AUKN_SYM void TTYStorePos()
{
#if defined(ENABLE_CONTTY)
if (!pGetConsoleScreenBufferInfo)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYStorePos);
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(GetTTYHandle(), &csbi))
if (!pGetConsoleScreenBufferInfo(GetTTYHandle(), &csbi))
{
return;
}
gSavedCoord = csbi.dwCursorPosition;
#endif
}
AUKN_SYM void TTYRestorePos()
{
#if defined(ENABLE_CONTTY)
if (!pSetConsoleCursorPosition)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYRestorePos);
SetConsoleCursorPosition(GetTTYHandle(), gSavedCoord);
pSetConsoleCursorPosition(GetTTYHandle(), gSavedCoord);
#endif
}
AUKN_SYM void TTYMoveY(AuInt16 lines)
{
#if defined(ENABLE_CONTTY)
if (!pGetConsoleScreenBufferInfo ||
!pSetConsoleCursorPosition)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYMoveY, lines);
CONSOLE_SCREEN_BUFFER_INFO csbi;
@ -276,17 +355,25 @@ namespace Aurora::Console::ConsoleTTY
hConsole = GetTTYHandle();
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
csbi.dwCursorPosition.Y += lines;
SetConsoleCursorPosition(hConsole, gSavedCoord);
pSetConsoleCursorPosition(hConsole, gSavedCoord);
#endif
}
AUKN_SYM void TTYMoveX(AuInt16 lines)
{
#if defined(ENABLE_CONTTY)
if (!pGetConsoleScreenBufferInfo ||
!pSetConsoleCursorPosition)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYMoveX, lines);
CONSOLE_SCREEN_BUFFER_INFO csbi;
@ -294,17 +381,25 @@ namespace Aurora::Console::ConsoleTTY
hConsole = GetTTYHandle();
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
csbi.dwCursorPosition.X += lines;
SetConsoleCursorPosition(hConsole, gSavedCoord);
pSetConsoleCursorPosition(hConsole, gSavedCoord);
#endif
}
AUKN_SYM void TTYSetY(AuUInt16 Y)
{
#if defined(ENABLE_CONTTY)
if (!pGetConsoleScreenBufferInfo ||
!pSetConsoleCursorPosition)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYSetY, Y);
CONSOLE_SCREEN_BUFFER_INFO csbi;
@ -312,17 +407,25 @@ namespace Aurora::Console::ConsoleTTY
hConsole = GetTTYHandle();
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
csbi.dwCursorPosition.Y = Y;
SetConsoleCursorPosition(hConsole, gSavedCoord);
pSetConsoleCursorPosition(hConsole, gSavedCoord);
#endif
}
AUKN_SYM void TTYSetX(AuUInt16 X)
{
#if defined(ENABLE_CONTTY)
if (!pGetConsoleScreenBufferInfo ||
!pSetConsoleCursorPosition)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYSetX, X);
CONSOLE_SCREEN_BUFFER_INFO csbi;
@ -330,24 +433,38 @@ namespace Aurora::Console::ConsoleTTY
hConsole = GetTTYHandle();
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
csbi.dwCursorPosition.X = X;
SetConsoleCursorPosition(hConsole, gSavedCoord);
pSetConsoleCursorPosition(hConsole, gSavedCoord);
#endif
}
AUKN_SYM void TTYSetPos(AuPair<AuUInt32, AuUInt32> position)
{
#if defined(ENABLE_CONTTY)
if (!pSetConsoleCursorPosition)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYSetPos, position);
SetConsoleCursorPosition(GetTTYHandle(), COORD {AuStaticCast<short>(position.first), AuStaticCast<short>(position.second)});
pSetConsoleCursorPosition(GetTTYHandle(), COORD {AuStaticCast<short>(position.first), AuStaticCast<short>(position.second)});
#endif
}
AUKN_SYM void TTYScrollBuffer(int Y)
{
#if defined(ENABLE_CONTTY)
if (!pScrollConsoleScreenBufferW)
{
return;
}
TTY_RECORD_FOR_FLIP(TTYScrollBuffer, Y);
CONSOLE_SCREEN_BUFFER_INFO csbi;
@ -357,7 +474,7 @@ namespace Aurora::Console::ConsoleTTY
hConsole = GetTTYHandle();
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
if (!pGetConsoleScreenBufferInfo(hConsole, &csbi))
{
return;
}
@ -379,31 +496,41 @@ namespace Aurora::Console::ConsoleTTY
chiFill.Attributes = BACKGROUND_BLACK | FOREGROUND_WHITE;
chiFill.Char.UnicodeChar = ' ';
ScrollConsoleScreenBufferW(
hConsole,
&srctScrollRect,
&srctClipRect,
coordDest,
&chiFill);
pScrollConsoleScreenBufferW(hConsole,
&srctScrollRect,
&srctClipRect,
coordDest,
&chiFill);
#endif
}
HANDLE GetTTYHandle()
{
#if defined(ENABLE_CONTTY)
if (gConsole != INVALID_HANDLE_VALUE)
{
return gConsole;
}
return gConsole = GetStdHandle(STD_OUTPUT_HANDLE);
#else
return INVALID_HANDLE_VALUE;
#endif
}
static bool AU_NOINLINE HasFBChanged(CONSOLE_SCREEN_BUFFER_INFO &csbi)
{
#if defined(ENABLE_CONTTY)
auto &curConsole = gConsoles[(gConsoleIndex ) % 2];
if (!GetConsoleScreenBufferInfo(gConsoleHandle, &csbi))
if (!pGetConsoleScreenBufferInfo)
{
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
return false;
}
if (!pGetConsoleScreenBufferInfo(gConsoleHandle, &csbi))
{
if (!pGetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
{
}
@ -422,11 +549,11 @@ namespace Aurora::Console::ConsoleTTY
SMALL_RECT screen = {0, 0, AuInt16(res.first - 1), AuInt16(res.second - 1)};
SetConsoleScreenBufferSize(gConsoles[0].h, COORD {(AuInt16)res.first, (AuInt16)res.second});
SetConsoleScreenBufferSize(gConsoles[1].h, COORD {(AuInt16)res.first, (AuInt16)res.second});
pSetConsoleScreenBufferSize(gConsoles[0].h, COORD {(AuInt16)res.first, (AuInt16)res.second});
pSetConsoleScreenBufferSize(gConsoles[1].h, COORD {(AuInt16)res.first, (AuInt16)res.second});
SetConsoleWindowInfo(gConsoles[0].h, true, &screen);
SetConsoleWindowInfo(gConsoles[1].h, true, &screen);
pSetConsoleWindowInfo(gConsoles[0].h, true, &screen);
pSetConsoleWindowInfo(gConsoles[1].h, true, &screen);
return true;
}
@ -438,12 +565,22 @@ namespace Aurora::Console::ConsoleTTY
}
return true;
#else
return false;
#endif
}
bool AU_NOINLINE InitConsoles()
{
#if defined(ENABLE_CONTTY)
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!pSetConsoleScreenBufferSize ||
!pSetConsoleWindowInfo)
{
return false;
}
if (!HasFBChanged(csbi))
{
return {};
@ -454,8 +591,8 @@ namespace Aurora::Console::ConsoleTTY
if (gConsoles[0].h == INVALID_HANDLE_VALUE)
{
auto a = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CONSOLE_TEXTMODE_BUFFER, nullptr);
auto b = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CONSOLE_TEXTMODE_BUFFER, nullptr);
auto a = pCreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CONSOLE_TEXTMODE_BUFFER, nullptr);
auto b = pCreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CONSOLE_TEXTMODE_BUFFER, nullptr);
gConsoles[0].h = a;
gConsoles[1].h = b;
@ -463,32 +600,48 @@ namespace Aurora::Console::ConsoleTTY
SMALL_RECT screen = {0, 0, AuInt16(res.first - 1), AuInt16(res.second - 1)};
SetConsoleScreenBufferSize(gConsoles[0].h, COORD {(AuInt16)res.first, (AuInt16)res.second});
SetConsoleScreenBufferSize(gConsoles[1].h, COORD {(AuInt16)res.first, (AuInt16)res.second});
pSetConsoleScreenBufferSize(gConsoles[0].h, COORD {(AuInt16)res.first, (AuInt16)res.second});
pSetConsoleScreenBufferSize(gConsoles[1].h, COORD {(AuInt16)res.first, (AuInt16)res.second});
SetConsoleWindowInfo(gConsoles[0].h, true, &screen);
SetConsoleWindowInfo(gConsoles[1].h, true, &screen);
pSetConsoleWindowInfo(gConsoles[0].h, true, &screen);
pSetConsoleWindowInfo(gConsoles[1].h, true, &screen);
gConsoles[0].width = gConsoles[1].width = res.first;
gConsoles[0].height = gConsoles[1].height = res.second;
return true;
#else
return false;
#endif
}
bool WarmBuffering()
{
#if defined(ENABLE_CONTTY)
return InitConsoles();
#else
return false;
#endif
}
void BeginBuffering()
{
#if defined(ENABLE_CONTTY)
if (!pSetConsoleActiveScreenBuffer)
{
return;
}
InitConsoles();
gConsoleIndex++;
gIsRecording = true;
SetConsoleActiveScreenBuffer(gConsoleHandle = gConsoles[(gConsoleIndex + 1) % 2].h);
pSetConsoleActiveScreenBuffer(gConsoleHandle = gConsoles[(gConsoleIndex + 1) % 2].h);
gConsole = gConsoles[gConsoleIndex % 2].h;
#else
#endif
}
void RecordFunction(const AuFunction<void()> &func)
@ -512,6 +665,7 @@ namespace Aurora::Console::ConsoleTTY
static bool IdkMan()
{
#if defined(ENABLE_CONTTY)
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (HasFBChanged(csbi))
@ -521,20 +675,30 @@ namespace Aurora::Console::ConsoleTTY
}
return true;
#else
return false;
#endif
}
bool EndBuffering()
{
#if defined(ENABLE_CONTTY)
if (!pSetConsoleActiveScreenBuffer)
{
return false;
}
if (!IdkMan())
{
gIsRecording = false;
return false;
}
SetConsoleActiveScreenBuffer(gConsoleHandle = gConsoles[(gConsoleIndex) % 2].h);
pSetConsoleActiveScreenBuffer(gConsoleHandle = gConsoles[(gConsoleIndex) % 2].h);
gConsole = gConsoles[(gConsoleIndex + 1) % 2].h;
gIsRecording = false;
RepeatRecord();
#endif
return true;
}

View File

@ -340,7 +340,8 @@ namespace Aurora::Console::ConsoleTTY
gTTYConsoleEnabled = true;
#if defined(AURORA_IS_MODERNNT_DERIVED)
//#if defined(AURORA_IS_MODERNNT_DERIVED)
#if defined(AURORA_PLATFORM_WIN32)
this->oldCP = GetConsoleOutputCP();
SetConsoleOutputCP(CP_UTF8);
#endif
@ -371,8 +372,12 @@ namespace Aurora::Console::ConsoleTTY
void TTYConsole::End()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
SetConsoleActiveScreenBuffer(GetStdHandle(STD_OUTPUT_HANDLE));
//#if defined(AURORA_IS_MODERNNT_DERIVED)
#if defined(AURORA_PLATFORM_WIN32)
if (pSetConsoleActiveScreenBuffer)
{
pSetConsoleActiveScreenBuffer(GetStdHandle(STD_OUTPUT_HANDLE));
}
#endif
if (!AuExchange(gTTYConsoleEnabled, false))
@ -399,8 +404,9 @@ namespace Aurora::Console::ConsoleTTY
#if defined(AURORA_IS_POSIX_DERIVED)
TTYWrite("\033[?1049l");
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED)
//#if defined(AURORA_IS_MODERNNT_DERIVED)
#if defined(AURORA_PLATFORM_WIN32)
SetConsoleOutputCP(this->oldCP);
#endif
@ -1445,8 +1451,8 @@ namespace Aurora::Console::ConsoleTTY
#if defined(AURORA_IS_MODERNNT_DERIVED)
DWORD idc;
auto line2 = AuLocale::ConvertFromUTF8(in);
SetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(XOffset), AuStaticCast<short>(Y) });
WriteConsoleW(GetTTYHandle(), line2.data(), AuUInt32(line2.size()), &idc, NULL);
pSetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(XOffset), AuStaticCast<short>(Y) });
pWriteConsoleW(GetTTYHandle(), line2.data(), AuUInt32(line2.size()), &idc, NULL);
#else
TTYSetPos({XOffset, Y});
ConsoleStd::WriteStdOutBlocking2(in.data(), in.size());
@ -1491,8 +1497,8 @@ namespace Aurora::Console::ConsoleTTY
#if defined(AURORA_IS_MODERNNT_DERIVED)
DWORD idc;
auto line2 = AuLocale::ConvertFromUTF8(in);
SetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(pos.first), AuStaticCast<short>(pos.second) });
WriteConsoleW(GetTTYHandle(), line2.data(), AuUInt32(line2.size()), &idc, NULL);
pSetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(pos.first), AuStaticCast<short>(pos.second) });
pWriteConsoleW(GetTTYHandle(), line2.data(), AuUInt32(line2.size()), &idc, NULL);
#else
TTYSetPos(pos);
@ -1530,10 +1536,10 @@ namespace Aurora::Console::ConsoleTTY
}
auto line2 = AuLocale::ConvertFromUTF8(in);
SetConsoleTextAttribute(hConsole, attrib);
SetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(pos.first), AuStaticCast<short>(pos.second) });
WriteConsoleW(hConsole, line2.data(), AuUInt32(line2.size()), &idc, NULL);
SetConsoleTextAttribute(hConsole, FOREGROUND_WHITE);
pSetConsoleTextAttribute(hConsole, attrib);
pSetConsoleCursorPosition(GetTTYHandle(), COORD { AuStaticCast<short>(pos.first), AuStaticCast<short>(pos.second) });
pWriteConsoleW(hConsole, line2.data(), AuUInt32(line2.size()), &idc, NULL);
pSetConsoleTextAttribute(hConsole, FOREGROUND_WHITE);
}
//WriteConsoleA(GetTTYHandle(), in.data(), AuUInt32(in.size()), &idc, NULL);