2022-05-03 04:31:49 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
Date: 2022-5-2
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
2022-05-17 16:54:14 +00:00
|
|
|
#include <Source/Console/Console.hpp>
|
2022-05-03 04:31:49 +00:00
|
|
|
#include "ConsoleTTY.NT.hpp"
|
2022-05-17 16:54:14 +00:00
|
|
|
#include <Source/Console/ColorConvert.hpp>
|
2022-05-03 04:31:49 +00:00
|
|
|
#include <Source/Console/ConsoleStd/ConsoleStd.hpp>
|
|
|
|
|
2022-05-17 16:54:14 +00:00
|
|
|
namespace Aurora::Console::ConsoleTTY
|
2022-05-03 04:31:49 +00:00
|
|
|
{
|
2022-05-04 15:34:02 +00:00
|
|
|
static HANDLE gConsole {INVALID_HANDLE_VALUE};
|
2022-05-03 04:31:49 +00:00
|
|
|
static COORD gSavedCoord {};
|
|
|
|
|
2022-05-17 16:54:14 +00:00
|
|
|
static bool gIsRecording {};
|
|
|
|
static AuThreadPrimitives::SpinLock gRecordLock;
|
|
|
|
static AuList<AuFunction<void()>> gRecordedActions {};
|
2022-05-04 15:34:02 +00:00
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
struct Console
|
|
|
|
{
|
|
|
|
HANDLE h {INVALID_HANDLE_VALUE};
|
|
|
|
int width, height;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Console gConsoles[2];
|
|
|
|
static AuUInt32 gConsoleIndex {0};
|
|
|
|
static HANDLE gConsoleHandle {INVALID_HANDLE_VALUE};
|
|
|
|
|
2022-05-17 16:54:14 +00:00
|
|
|
#define TTY_RECORD_FOR_FLIP(func, ...) \
|
|
|
|
if (gIsRecording) \
|
|
|
|
{ \
|
|
|
|
AU_LOCK_GUARD(gRecordLock); \
|
|
|
|
gRecordedActions.push_back(std::bind(func, ## __VA_ARGS__)); \
|
2022-05-04 15:34:02 +00:00
|
|
|
}
|
2022-09-09 20:12:20 +00:00
|
|
|
|
|
|
|
void GetConsoleHandles(HANDLE(&handles)[2])
|
|
|
|
{
|
|
|
|
handles[0] = gConsoles[0].h;
|
|
|
|
handles[1] = gConsoles[1].h;
|
|
|
|
}
|
2022-05-04 15:34:02 +00:00
|
|
|
|
|
|
|
AUKN_SYM void SuperSecretTTYReplacer(HANDLE console)
|
|
|
|
{
|
|
|
|
gConsole = console;
|
|
|
|
}
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
AUKN_SYM void TTYClearLine(EAnsiColor bgColor)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYClearLine, bgColor);
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
HANDLE hConsole;
|
|
|
|
DWORD cCharsWritten;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
hConsole = GetTTYHandle();
|
2022-05-03 04:31:49 +00:00
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FillConsoleOutputCharacterW(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))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetConsoleCursorPosition(hConsole, {0, csbi.dwCursorPosition.Y});
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYClearScreen()
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYClearScreen);
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
HANDLE hConsole;
|
|
|
|
DWORD cCharsWritten;
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
DWORD dwConSize;
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
hConsole = GetTTYHandle();
|
2022-05-03 04:31:49 +00:00
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
|
|
|
|
|
|
|
|
if (!FillConsoleOutputCharacterW(hConsole,
|
|
|
|
L' ',
|
|
|
|
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});
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYFill(char character, EAnsiColor fgColor, EAnsiColor bgColor)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYFill, character, fgColor, bgColor);
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
DWORD attrib {0}, cCharsWritten {};
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
HANDLE hConsole;
|
|
|
|
|
|
|
|
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fgColor != EAnsiColor::eEnumCount)
|
|
|
|
{
|
|
|
|
attrib |= kAnsiColorForegroundToNT[AuStaticCast<AuUInt>(fgColor)];
|
|
|
|
}
|
|
|
|
else if (bgColor != EAnsiColor::eEnumCount)
|
|
|
|
{
|
|
|
|
attrib = FOREGROUND_WHITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bgColor != EAnsiColor::eEnumCount)
|
|
|
|
{
|
|
|
|
attrib |= kAnsiColorBackgroundToNT[AuStaticCast<AuUInt>(bgColor)];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FillConsoleOutputCharacterW(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))
|
|
|
|
{
|
|
|
|
//return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuUInt32 TTYWrite(const void *buffer, AuUInt32 length)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
// no record required
|
2022-05-03 04:31:49 +00:00
|
|
|
return ConsoleStd::WriteStdOutBlocking2(buffer, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYWrite(const char *string, EAnsiColor fgColor, EAnsiColor bgColor)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP((void(*)(const char *, EAnsiColor, EAnsiColor))(TTYWrite), string, fgColor, bgColor);
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
DWORD attrib {};
|
|
|
|
HANDLE hConsole;
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
hConsole = GetTTYHandle();
|
2022-05-03 04:31:49 +00:00
|
|
|
|
|
|
|
if (fgColor != EAnsiColor::eEnumCount)
|
|
|
|
{
|
|
|
|
attrib |= kAnsiColorForegroundToNT[AuStaticCast<AuUInt>(fgColor)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attrib = FOREGROUND_WHITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bgColor != EAnsiColor::eEnumCount)
|
|
|
|
{
|
|
|
|
attrib |= kAnsiColorBackgroundToNT[AuStaticCast<AuUInt>(bgColor)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
attrib |= csbi.wAttributes & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetConsoleTextAttribute(hConsole, attrib);
|
2022-06-14 15:59:37 +00:00
|
|
|
TTYWrite(string, AuUInt32(strlen(string)));
|
2022-05-03 04:31:49 +00:00
|
|
|
SetConsoleTextAttribute(hConsole, FOREGROUND_WHITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYReturnHome()
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYReturnHome);
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
SetConsoleCursorPosition(GetTTYHandle(), {0, 0});
|
2022-05-03 04:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM AuPair<AuUInt32, AuUInt32> TTYScreenSize()
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2022-05-17 23:51:57 +00:00
|
|
|
HANDLE hConsole;
|
2022-05-03 04:31:49 +00:00
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
hConsole = GetTTYHandle();
|
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
2022-05-03 04:31:49 +00:00
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-05-12 07:06:08 +00:00
|
|
|
return AuMakePair(AuStaticCast<AuUInt32>(csbi.srWindow.Right - csbi.srWindow.Left + 1),
|
|
|
|
AuStaticCast<AuUInt32>(csbi.srWindow.Bottom - csbi.srWindow.Top + 1));
|
2022-05-03 04:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYStorePos()
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYStorePos);
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
if (!GetConsoleScreenBufferInfo(GetTTYHandle(), &csbi))
|
2022-05-03 04:31:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gSavedCoord = csbi.dwCursorPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYRestorePos()
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYRestorePos);
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
SetConsoleCursorPosition(GetTTYHandle(), gSavedCoord);
|
2022-05-03 04:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYMoveY(AuInt16 lines)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYMoveY, lines);
|
2022-05-03 04:31:49 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2022-05-17 16:54:14 +00:00
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
HANDLE hConsole;
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
hConsole = GetTTYHandle();
|
2022-05-03 04:31:49 +00:00
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
csbi.dwCursorPosition.Y += lines;
|
|
|
|
SetConsoleCursorPosition(hConsole, gSavedCoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYMoveX(AuInt16 lines)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYMoveX, lines);
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
HANDLE hConsole;
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
hConsole = GetTTYHandle();
|
2022-05-03 04:31:49 +00:00
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
csbi.dwCursorPosition.X += lines;
|
|
|
|
SetConsoleCursorPosition(hConsole, gSavedCoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYSetY(AuUInt16 Y)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYSetY, Y);
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
HANDLE hConsole;
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
hConsole = GetTTYHandle();
|
2022-05-03 04:31:49 +00:00
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
csbi.dwCursorPosition.Y = Y;
|
|
|
|
SetConsoleCursorPosition(hConsole, gSavedCoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYSetX(AuUInt16 X)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYSetX, X);
|
|
|
|
|
2022-05-03 04:31:49 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
HANDLE hConsole;
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
hConsole = GetTTYHandle();
|
2022-05-03 04:31:49 +00:00
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
csbi.dwCursorPosition.X = X;
|
|
|
|
SetConsoleCursorPosition(hConsole, gSavedCoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM void TTYSetPos(AuPair<AuUInt32, AuUInt32> position)
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
TTY_RECORD_FOR_FLIP(TTYSetPos, position);
|
|
|
|
|
2022-05-04 15:34:02 +00:00
|
|
|
SetConsoleCursorPosition(GetTTYHandle(), COORD {AuStaticCast<short>(position.first), AuStaticCast<short>(position.second)});
|
2022-05-03 04:31:49 +00:00
|
|
|
}
|
2022-05-17 16:54:14 +00:00
|
|
|
|
|
|
|
AUKN_SYM void TTYScrollBuffer(int Y)
|
|
|
|
{
|
|
|
|
TTY_RECORD_FOR_FLIP(TTYScrollBuffer, Y);
|
|
|
|
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
SMALL_RECT srctScrollRect, srctClipRect;
|
|
|
|
HANDLE hConsole;
|
|
|
|
COORD coordDest;
|
|
|
|
|
|
|
|
hConsole = GetTTYHandle();
|
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto res = AuMakePair(AuStaticCast<AuUInt32>(csbi.srWindow.Right - csbi.srWindow.Left + 1),
|
|
|
|
AuStaticCast<AuUInt32>(csbi.srWindow.Bottom - csbi.srWindow.Top + 1));
|
2022-05-17 23:51:57 +00:00
|
|
|
|
2022-05-17 16:54:14 +00:00
|
|
|
srctScrollRect.Top = 0;
|
|
|
|
srctScrollRect.Bottom = csbi.dwSize.Y - 1;
|
|
|
|
srctScrollRect.Left = 0;
|
|
|
|
srctScrollRect.Right = csbi.dwSize.X - 1;
|
|
|
|
|
|
|
|
coordDest.X = 0;
|
2022-05-17 16:58:29 +00:00
|
|
|
coordDest.Y = -Y;
|
2022-05-17 23:51:57 +00:00
|
|
|
|
2022-05-17 16:54:14 +00:00
|
|
|
srctClipRect = srctScrollRect;
|
|
|
|
|
|
|
|
CHAR_INFO chiFill;
|
|
|
|
chiFill.Attributes = BACKGROUND_BLACK | FOREGROUND_WHITE;
|
|
|
|
chiFill.Char.UnicodeChar = ' ';
|
|
|
|
|
|
|
|
ScrollConsoleScreenBufferW(
|
|
|
|
hConsole,
|
|
|
|
&srctScrollRect,
|
|
|
|
&srctClipRect,
|
|
|
|
coordDest,
|
|
|
|
&chiFill);
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE GetTTYHandle()
|
|
|
|
{
|
|
|
|
if (gConsole != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return gConsole;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
}
|
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
static bool AU_NOINLINE HasFBChanged(CONSOLE_SCREEN_BUFFER_INFO &csbi)
|
2022-05-17 16:54:14 +00:00
|
|
|
{
|
2022-05-17 23:51:57 +00:00
|
|
|
auto &curConsole = gConsoles[(gConsoleIndex ) % 2];
|
2022-05-17 16:54:14 +00:00
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
if (!GetConsoleScreenBufferInfo(gConsoleHandle, &csbi))
|
2022-05-17 16:54:14 +00:00
|
|
|
{
|
2022-05-17 23:51:57 +00:00
|
|
|
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2022-05-17 16:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto res = AuMakePair(AuStaticCast<AuUInt32>(csbi.srWindow.Right - csbi.srWindow.Left + 1),
|
|
|
|
AuStaticCast<AuUInt32>(csbi.srWindow.Bottom - csbi.srWindow.Top + 1));
|
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
if ((res.first != csbi.dwSize.X) || (res.second != csbi.dwSize.Y))
|
|
|
|
{
|
|
|
|
if ((res.first != curConsole.width) ||
|
|
|
|
(res.second != curConsole.height))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-14 15:59:37 +00:00
|
|
|
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});
|
2022-05-17 23:51:57 +00:00
|
|
|
|
|
|
|
SetConsoleWindowInfo(gConsoles[0].h, true, &screen);
|
|
|
|
SetConsoleWindowInfo(gConsoles[1].h, true, &screen);
|
|
|
|
|
2022-05-18 18:14:24 +00:00
|
|
|
return true;
|
2022-05-17 23:51:57 +00:00
|
|
|
}
|
2022-05-17 16:54:14 +00:00
|
|
|
|
|
|
|
if (((res.first == curConsole.width &&
|
|
|
|
res.second == curConsole.height)))
|
|
|
|
{
|
2022-05-17 23:51:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AU_NOINLINE InitConsoles()
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
if (!HasFBChanged(csbi))
|
|
|
|
{
|
|
|
|
return {};
|
2022-05-17 16:54:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
auto res = AuMakePair(AuStaticCast<AuUInt32>(csbi.srWindow.Right - csbi.srWindow.Left + 1),
|
|
|
|
AuStaticCast<AuUInt32>(csbi.srWindow.Bottom - csbi.srWindow.Top + 1));
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
gConsoles[0].h = a;
|
|
|
|
gConsoles[1].h = b;
|
|
|
|
}
|
2022-05-17 16:54:14 +00:00
|
|
|
|
|
|
|
|
2022-06-14 15:59:37 +00:00
|
|
|
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});
|
2022-05-17 16:54:14 +00:00
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
SetConsoleWindowInfo(gConsoles[0].h, true, &screen);
|
|
|
|
SetConsoleWindowInfo(gConsoles[1].h, true, &screen);
|
2022-05-17 16:54:14 +00:00
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
gConsoles[0].width = gConsoles[1].width = res.first;
|
2022-05-17 16:54:14 +00:00
|
|
|
gConsoles[0].height = gConsoles[1].height = res.second;
|
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
return true;
|
2022-05-17 16:54:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
bool WarmBuffering()
|
2022-05-17 16:54:14 +00:00
|
|
|
{
|
2022-05-17 23:51:57 +00:00
|
|
|
return InitConsoles();
|
|
|
|
}
|
2022-05-17 16:54:14 +00:00
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
void BeginBuffering()
|
|
|
|
{
|
2022-05-17 16:54:14 +00:00
|
|
|
InitConsoles();
|
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
gConsoleIndex++;
|
2022-05-17 16:54:14 +00:00
|
|
|
gIsRecording = true;
|
2022-05-17 23:51:57 +00:00
|
|
|
|
|
|
|
SetConsoleActiveScreenBuffer(gConsoleHandle = gConsoles[(gConsoleIndex + 1) % 2].h);
|
|
|
|
gConsole = gConsoles[gConsoleIndex % 2].h;
|
2022-05-17 16:54:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RecordFunction(const AuFunction<void()> &func)
|
|
|
|
{
|
|
|
|
if (gIsRecording)
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(gRecordLock);
|
|
|
|
gRecordedActions.push_back(func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RepeatRecord()
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(gRecordLock);
|
|
|
|
|
|
|
|
for (auto action : AuExchange(gRecordedActions, {}))
|
|
|
|
{
|
|
|
|
action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
static bool IdkMan()
|
2022-05-17 16:54:14 +00:00
|
|
|
{
|
2022-05-17 23:51:57 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
|
|
|
|
|
|
if (HasFBChanged(csbi))
|
|
|
|
{
|
|
|
|
gRecordedActions.clear();
|
|
|
|
return {};
|
|
|
|
}
|
2022-05-17 16:54:14 +00:00
|
|
|
|
2022-05-17 23:51:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EndBuffering()
|
|
|
|
{
|
|
|
|
if (!IdkMan())
|
|
|
|
{
|
|
|
|
gIsRecording = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetConsoleActiveScreenBuffer(gConsoleHandle = gConsoles[(gConsoleIndex) % 2].h);
|
2022-05-17 16:54:14 +00:00
|
|
|
gConsole = gConsoles[(gConsoleIndex + 1) % 2].h;
|
|
|
|
gIsRecording = false;
|
|
|
|
RepeatRecord();
|
2022-05-17 23:51:57 +00:00
|
|
|
|
|
|
|
return true;
|
2022-05-17 16:54:14 +00:00
|
|
|
}
|
2022-08-05 18:25:01 +00:00
|
|
|
|
|
|
|
bool IsBuffering()
|
|
|
|
{
|
|
|
|
return gIsRecording;
|
|
|
|
}
|
2022-05-03 04:31:49 +00:00
|
|
|
}
|