From 6dfa806e3a6293816b9d7adb9d8315e1905ec8ad Mon Sep 17 00:00:00 2001 From: Reece Wilson Date: Fri, 9 Dec 2022 22:59:03 +0000 Subject: [PATCH] [+] (NT only) Missing numpad and math keys input under ConsoleStd noncan APIs [*] Refactor NoncanonicalInput [*] Fix various keys resort in NUL getting added to ConsoleTTYs input field [*] Fix multichar right key input (finish TODO note) [*] Hex grammar: literals may end with 'h' now that i think about it. also added wiresharks seperator. let's continue to simply make sure we cover all forms of hex in a reasonably liberal fashion to account for user input from various human written and software form. (Nonuniform style of non-hex illegal chars are fine so long as it looks and reads like a legal array of hex characters. Comas must come directly after literals, possible [0x] prefixes are fine, whitespaces too, copy/pasted '[', ']', '{', '}', 'reasonable' new line rejection, etc) --- .../Console/ConsoleStd/NoncanonicalInput.hpp | 8 +- Source/Console/ConsoleStd/ConsoleStd.cpp | 98 +++++++++++++++---- Source/Console/ConsoleTTY/ConsoleTTY.cpp | 9 +- Source/Parse/AuHex.cpp | 18 +++- 4 files changed, 99 insertions(+), 34 deletions(-) diff --git a/Include/Aurora/Console/ConsoleStd/NoncanonicalInput.hpp b/Include/Aurora/Console/ConsoleStd/NoncanonicalInput.hpp index 0cb54a53..95f68822 100644 --- a/Include/Aurora/Console/ConsoleStd/NoncanonicalInput.hpp +++ b/Include/Aurora/Console/ConsoleStd/NoncanonicalInput.hpp @@ -13,9 +13,9 @@ namespace Aurora::Console::ConsoleStd { ENoncanonicalInput type; AuString string; - int scrollDeltaY {}; - bool isControlSequence {}; - bool isAltSequence {}; - bool isShiftSequence {}; + int iScrollDeltaY {}; + bool bIsControlSequence {}; + bool bIsAltSequence {}; + bool bIsShiftSequence {}; }; } \ No newline at end of file diff --git a/Source/Console/ConsoleStd/ConsoleStd.cpp b/Source/Console/ConsoleStd/ConsoleStd.cpp index 90a4be64..10f53ed4 100755 --- a/Source/Console/ConsoleStd/ConsoleStd.cpp +++ b/Source/Console/ConsoleStd/ConsoleStd.cpp @@ -205,6 +205,10 @@ namespace Aurora::Console::ConsoleStd NoncanonicalInput canInput {}; canInput.type = ENoncanonicalInput::eInput; canInput.string = line; + if (auto uMax = ::strnlen(line.data(), line.size())) + { + canInput.string.resize(uMax); + } SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); canInput.type = ENoncanonicalInput::eEnter; @@ -217,6 +221,10 @@ namespace Aurora::Console::ConsoleStd NoncanonicalInput canInput {}; canInput.type = ENoncanonicalInput::eInput; canInput.string = remaining; + if (auto uMax = ::strnlen(remaining.data(), remaining.size())) + { + canInput.string.resize(uMax); + } SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); } } @@ -282,7 +290,7 @@ namespace Aurora::Console::ConsoleStd bool dBreak = false; NoncanonicalInput canInput; canInput.type = ENoncanonicalInput::eEnumInvalid; - canInput.scrollDeltaY = 0; + canInput.iScrollDeltaY = 0; auto &record = records[i]; AuString key; @@ -374,13 +382,58 @@ namespace Aurora::Console::ConsoleStd case VK_F12: canInput.type = ENoncanonicalInput::eFunction12; break; + case VK_NUMPAD0: + case VK_NUMPAD1: + case VK_NUMPAD2: + case VK_NUMPAD3: + case VK_NUMPAD4: + case VK_NUMPAD5: + case VK_NUMPAD6: + case VK_NUMPAD7: + case VK_NUMPAD8: + case VK_NUMPAD9: + { + canInput.type = ENoncanonicalInput::eInput; + canInput.string = '0' + (record.Event.KeyEvent.wVirtualKeyCode - VK_NUMPAD0); + break; + } + case VK_MULTIPLY: + { + canInput.type = ENoncanonicalInput::eInput; + canInput.string = '*'; + break; + } + case VK_ADD: + { + canInput.type = ENoncanonicalInput::eInput; + canInput.string = '+'; + break; + } + case VK_SUBTRACT: + { + canInput.type = ENoncanonicalInput::eInput; + canInput.string = '-'; + break; + } + case VK_DIVIDE: + { + canInput.type = ENoncanonicalInput::eInput; + canInput.string = '/'; + break; + } + case VK_DECIMAL: + { + canInput.type = ENoncanonicalInput::eInput; + canInput.string = '.'; + break; + } default: dBreak = true; } - canInput.isControlSequence = record.Event.KeyEvent.dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED); - canInput.isAltSequence = record.Event.KeyEvent.dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED); - canInput.isShiftSequence = record.Event.KeyEvent.dwControlKeyState & (SHIFT_PRESSED); + canInput.bIsControlSequence = record.Event.KeyEvent.dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED); + canInput.bIsAltSequence = record.Event.KeyEvent.dwControlKeyState & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED); + canInput.bIsShiftSequence = record.Event.KeyEvent.dwControlKeyState & (SHIFT_PRESSED); // TODO: numpad if (!dBreak || ((record.Event.KeyEvent.wVirtualKeyCode <= VK_HELP && @@ -402,6 +455,8 @@ namespace Aurora::Console::ConsoleStd for (z = 0; z < record.Event.KeyEvent.wRepeatCount; z++) { + key.resize(::strnlen(key.data(), key.size())); + canInput.string += key; if (key.size()) @@ -419,12 +474,12 @@ namespace Aurora::Console::ConsoleStd if (record.Event.MouseEvent.dwEventFlags == MOUSE_WHEELED) { canInput.type = ENoncanonicalInput::eScroll; - canInput.scrollDeltaY = AuStaticCast(AuBitsToHigher((AuUInt32)record.Event.MouseEvent.dwButtonState)); + canInput.iScrollDeltaY = AuStaticCast(AuBitsToHigher((AuUInt32)record.Event.MouseEvent.dwButtonState)); - if (canInput.scrollDeltaY > 1) - canInput.scrollDeltaY = 1; - else if (canInput.scrollDeltaY < -1) - canInput.scrollDeltaY = -1; + if (canInput.iScrollDeltaY > 1) + canInput.iScrollDeltaY = 1; + else if (canInput.iScrollDeltaY < -1) + canInput.iScrollDeltaY = -1; dBreak = false; } else if ((record.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED) != 0) @@ -525,6 +580,7 @@ namespace Aurora::Console::ConsoleStd DWORD idc; WriteConsoleInputW(gInputStream, niceWorkMicrosoft, 2, &idc); + WriteConsoleInputW(gInputStream, niceWorkMicrosoft, 2, &idc); return true; } @@ -1100,8 +1156,8 @@ namespace Aurora::Console::ConsoleStd auto c = gLineEncodedBuffer[i]; NoncanonicalInput canInput {}; - canInput.scrollDeltaY = 0; - canInput.isControlSequence = canInput.isShiftSequence = canInput.isAltSequence = false; + canInput.iScrollDeltaY = 0; + canInput.bIsControlSequence = canInput.bIsControlSequence = canInput.bIsControlSequence = false; if (c == 127) { CanFlushLines(); @@ -1138,7 +1194,7 @@ namespace Aurora::Console::ConsoleStd CanFlushLines(); canInput.type = ENoncanonicalInput::eInput; canInput.string = 'a' + c - 1; - canInput.isControlSequence = true; + canInput.bIsControlSequence = true; SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); } @@ -1192,7 +1248,7 @@ namespace Aurora::Console::ConsoleStd if (next == nestedChar) \ { \ canInput.type = ENoncanonicalInput::op; \ - canInput.isControlSequence = true; \ + canInput.bIsControlSequence = true; \ SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); \ } \ } \ @@ -1204,8 +1260,8 @@ namespace Aurora::Console::ConsoleStd if (next == nestedChar) \ { \ canInput.type = ENoncanonicalInput::op; \ - canInput.isShiftSequence = true; \ - canInput.isControlSequence = true; \ + canInput.bIsShiftSequence = true; \ + canInput.bIsControlSequence = true; \ SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); \ } \ } \ @@ -1217,7 +1273,7 @@ namespace Aurora::Console::ConsoleStd if (next == nestedChar) \ { \ canInput.type = ENoncanonicalInput::op; \ - canInput.isShiftSequence = true; \ + canInput.bIsShiftSequence = true; \ SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); \ } \ } \ @@ -1229,9 +1285,9 @@ namespace Aurora::Console::ConsoleStd if (next == nestedChar) \ { \ canInput.type = ENoncanonicalInput::op; \ - canInput.isShiftSequence = true; \ - canInput.isControlSequence = true; \ - canInput.isAltSequence = true; \ + canInput.bIsShiftSequence = true; \ + canInput.bIsControlSequence = true; \ + canInput.bIsAltSequence = true; \ SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); \ } \ } \ @@ -1264,13 +1320,13 @@ namespace Aurora::Console::ConsoleStd if (esc == 'A') { canInput.type = ENoncanonicalInput::eScroll; - canInput.scrollDeltaY = 4; + canInput.iScrollDeltaY = 4; SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); } else if (esc == 'B') { canInput.type = ENoncanonicalInput::eScroll; - canInput.scrollDeltaY = -4; + canInput.iScrollDeltaY = -4; SysAssert(AuTryInsert(gCanonicalBuffer, canInput)); } } diff --git a/Source/Console/ConsoleTTY/ConsoleTTY.cpp b/Source/Console/ConsoleTTY/ConsoleTTY.cpp index 0137f9f4..df82eb12 100644 --- a/Source/Console/ConsoleTTY/ConsoleTTY.cpp +++ b/Source/Console/ConsoleTTY/ConsoleTTY.cpp @@ -204,12 +204,12 @@ namespace Aurora::Console::ConsoleTTY } case ConsoleStd::ENoncanonicalInput::eScroll: { - Scroll(input.scrollDeltaY); + Scroll(input.iScrollDeltaY); break; } default: { - AuLogDbg("Key Stroke: {}, {}, {}", ConsoleStd::ENoncanonicalInputToString(input.type), input.scrollDeltaY, input.string); + AuLogDbg("Key Stroke: {}, {}, {}", ConsoleStd::ENoncanonicalInputToString(input.type), input.iScrollDeltaY, input.string); } }; @@ -272,9 +272,10 @@ namespace Aurora::Console::ConsoleTTY return; } - // TODO: missing locale API + auto uAddend = AuLocale::Encoding::IterateUTF8({ &this->inputField[this->noncanonicalCursorPosInBytes], this->inputField.size() - this->noncanonicalCursorPosInBytes }); + this->noncanonicalCursorPos++; - this->noncanonicalCursorPosInBytes++; // << ILLEGAL + this->noncanonicalCursorPosInBytes += uAddend; NoncanonicalSetCursor(); } diff --git a/Source/Parse/AuHex.cpp b/Source/Parse/AuHex.cpp index b92b6826..942d1409 100644 --- a/Source/Parse/AuHex.cpp +++ b/Source/Parse/AuHex.cpp @@ -161,7 +161,7 @@ namespace Aurora::Parse // Consume array for (; i < in.size(); ) { - // Consume prefix + // Consume 0x prefix if ((i + 1) < in.size()) { if ((in[i] == '0') && @@ -186,14 +186,22 @@ namespace Aurora::Parse i += 2; } - HEX_GRAMMAR_CONSUME_ONE(','); - HEX_GRAMMAR_CONSUME_END_OF_LINE; + if (i < in.size()) + { + if ((in[i] == 'h' /*some hex dump code and people prefer FFh over 0xFF*/)) + { + i++; + } + } + + HEX_GRAMMAR_CONSUME_EITHER(':' /*wireshark and other networking tools*/, ',' /*latin splitter array*/); + HEX_GRAMMAR_CONSUME_END_OF_LINE; // all whitespace [+newline[+all whitespace]] // Consume end literal hint if (i < in.size()) { - if ((in[i] == '}') || - (in[i] == ']')) + if ((in[i] == '}' /*c-like*/) || + (in[i] == ']' /*more latin array tag*/)) { break; }