Fix console behavior on win32

This commit is contained in:
Lion Kortlepel 2020-11-08 22:15:49 +01:00
parent 7fce274915
commit 747e948339

View File

@ -119,6 +119,7 @@ void SetupConsole() {
#endif // WIN32 #endif // WIN32
} }
#ifndef WIN32
static std::vector<std::string> ConsoleHistory {}; static std::vector<std::string> ConsoleHistory {};
static size_t ConsoleHistoryReadIndex { 0 }; static size_t ConsoleHistoryReadIndex { 0 };
@ -162,12 +163,14 @@ static void ProcessCompositeInput() {
ConsoleHistoryReadIndex = ConsoleHistory.size(); ConsoleHistoryReadIndex = ConsoleHistory.size();
} }
} }
#endif // WIN32
[[noreturn]] void ReadCin() { [[noreturn]] void ReadCin() {
DebugPrintTID(); DebugPrintTID();
while (true) { while (true) {
int In = _getch(); int In = _getch();
//info(std::to_string(In)); //info(std::to_string(In));
#ifndef WIN32
if (CompositeInputExpected) { if (CompositeInputExpected) {
CompositeInput += In; CompositeInput += In;
if (CompositeInput.size() == 2) { if (CompositeInput.size() == 2) {
@ -176,10 +179,13 @@ static void ProcessCompositeInput() {
} }
continue; continue;
} }
#endif // WIN32
if (In == 13 || In == '\n') { if (In == 13 || In == '\n') {
if (!CInputBuff.empty()) { if (!CInputBuff.empty()) {
HandleInput(CInputBuff); HandleInput(CInputBuff);
#ifndef WIN32
ConsoleHistoryAdd(CInputBuff); ConsoleHistoryAdd(CInputBuff);
#endif // WIN32
CInputBuff.clear(); CInputBuff.clear();
} }
} else if (In == 8 || In == 127) { } else if (In == 8 || In == 127) {
@ -189,10 +195,12 @@ static void ProcessCompositeInput() {
CInputBuff = "exit"; CInputBuff = "exit";
HandleInput(CInputBuff); HandleInput(CInputBuff);
CInputBuff.clear(); CInputBuff.clear();
#ifndef WIN32
} else if (In == 27) { } else if (In == 27) {
// escape char, assume stuff follows // escape char, assume stuff follows
CompositeInputExpected = true; CompositeInputExpected = true;
CompositeInput.clear(); CompositeInput.clear();
#endif // WIN32
} else if (!isprint(In)) { } else if (!isprint(In)) {
// ignore // ignore
} else { } else {