[+] Win32 clipboard update check under the ConsoleStd pump to automatically switch between quick edit and gib us the raw input modes

This commit is contained in:
Reece Wilson 2022-08-07 23:35:13 +01:00
parent a92467ceb6
commit da70053aab
3 changed files with 90 additions and 20 deletions

View File

@ -110,7 +110,13 @@ namespace Aurora::Console::ConsoleStd
static bool gCanonicalUnixOn {};
#if defined(AURORA_IS_MODERNNT_DERIVED)
}
#include "../ConsoleTTY/ConsoleTTY.hpp"
#include "../ConsoleTTY/ConsoleTTY.NT.hpp"
namespace Aurora::Console::ConsoleStd
{
static DWORD WINAPI StdInWin32Thread(void*)
{
HANDLE a[2] = {gInputStream, gTerminateConsole};
@ -130,6 +136,41 @@ namespace Aurora::Console::ConsoleStd
return 1;
}
static void PumpClipboardCheck()
{
static AuUInt64 gLastHash {};
AuString str;
if (!::OpenClipboard(nullptr))
{
return;
}
auto hClipboardData = ::GetClipboardData(CF_UNICODETEXT);
if (hClipboardData == nullptr)
{
::CloseClipboard();
return;
}
auto pLpwStr = (LPWSTR)GlobalLock(hClipboardData);
if (pLpwStr != nullptr)
{
str = AuLocale::ConvertFromWChar(pLpwStr);
::GlobalUnlock(hClipboardData);
}
auto newHash = AuFnv1a64Runtime(str.data(), str.length());
if (newHash != gLastHash)
{
gLastHash = newHash;
ConsoleTTY::EnterScrollMode();
}
::CloseClipboard();
}
void ProcessCanonical(HANDLE h)
{
INPUT_RECORD records[4096];
@ -138,6 +179,8 @@ namespace Aurora::Console::ConsoleStd
void *data = &gLineEncodedBuffer[gEncodedIndex];
auto length = kLineBufferMax - gEncodedIndex;
PumpClipboardCheck();
if (!IS_STREAM_HANDLE_VALID(h))
{
h = gInputStream;
@ -194,7 +237,7 @@ namespace Aurora::Console::ConsoleStd
switch (record.EventType)
{
case KEY_EVENT:
{
if (!record.Event.KeyEvent.bKeyDown)
{
dBreak = true;
@ -203,7 +246,7 @@ namespace Aurora::Console::ConsoleStd
// TODO: numpad
if (record.Event.KeyEvent.wVirtualKeyCode <= VK_HELP &&
record.Event.KeyEvent.wVirtualKeyCode != VK_SPACE &&
record.Event.KeyEvent.wVirtualKeyCode != VK_SPACE &&
(record.Event.KeyEvent.wVirtualKeyCode < VK_NUMPAD0 || record.Event.KeyEvent.wVirtualKeyCode > VK_NUMPAD9))
{
switch (record.Event.KeyEvent.wVirtualKeyCode)
@ -264,8 +307,10 @@ namespace Aurora::Console::ConsoleStd
}
break;
}
case MOUSE_EVENT:
{
dBreak = true;
if (record.Event.MouseEvent.dwEventFlags == MOUSE_WHEELED)
{
canInput.type = ENoncanonicalInput::eScroll;
@ -275,21 +320,30 @@ namespace Aurora::Console::ConsoleStd
canInput.scrollDeltaY = 1;
else if (canInput.scrollDeltaY < -1)
canInput.scrollDeltaY = -1;
dBreak = false;
}
else if ((record.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED) != 0)
{
ConsoleTTY::LeaveScrollMode();
}
else
{
dBreak = true;
// NOOP
}
break;
}
default:
{
dBreak = true;
break;
}
};
if (dBreak) continue;
if (dBreak)
{
continue;
}
if (!AuTryInsert(gCanonicalBuffer, canInput))
{

View File

@ -333,6 +333,27 @@ namespace Aurora::Console::ConsoleTTY
}
void EnterScrollMode()
{
DWORD mode;
HANDLE stream = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(stream, &mode);
mode &= ~(ENABLE_QUICK_EDIT_MODE);
SetConsoleMode(stream, mode);
AuStaticCast<TTYConsole>(GetTTYConsole())->uxModeFlipped = true;
}
void LeaveScrollMode()
{
DWORD mode;
HANDLE stream = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(stream, &mode);
mode |= ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(stream, mode);
AuStaticCast<TTYConsole>(GetTTYConsole())->uxModeFlipped = true; // TODO?
}
void TTYConsole::NoncanonicalOnEnter()
{
AU_LOCK_GUARD(this->historyLock->AsWritable());
@ -343,21 +364,11 @@ namespace Aurora::Console::ConsoleTTY
#if defined(AURORA_IS_MODERNNT_DERIVED)
if (this->inputField == "!s")
{
DWORD mode;
HANDLE stream = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(stream, &mode);
mode &= ~(ENABLE_QUICK_EDIT_MODE);
SetConsoleMode(stream, mode);
uxModeFlipped = true;
EnterScrollMode();
}
else if (this->inputField == "!c")
{
DWORD mode;
HANDLE stream = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(stream, &mode);
mode |= ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(stream, mode);
uxModeFlipped = true;
LeaveScrollMode();
}
else
#endif

View File

@ -11,6 +11,9 @@ namespace Aurora::Console::ConsoleTTY
{
inline bool gTTYConsoleEnabled {};
void EnterScrollMode();
void LeaveScrollMode();
struct TTYConsole : ITTYConsole
{
void BufferMessage(const AuConsole::ConsoleMessage &msg) override;
@ -25,6 +28,8 @@ namespace Aurora::Console::ConsoleTTY
bool Start() override;
void End() override;
bool uxModeFlipped {};
private:
bool UTF8();
@ -158,6 +163,7 @@ namespace Aurora::Console::ConsoleTTY
void BlankBordersLine(int Y);
bool PermitDoubleBuffering();
private:
void DebugLogArea();
@ -226,7 +232,6 @@ namespace Aurora::Console::ConsoleTTY
bool IsWin32UxMode();
void UXModeFlip();
void UXModeStart();
bool uxModeFlipped {};
AuString inputField {};