enable VT sequence on Windows (#136)

This commit is contained in:
Cyano Hao 2023-09-20 10:02:50 +08:00 committed by GitHub
parent ec3527e5d6
commit 660cd63532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -27,6 +27,9 @@ using std::string;
#ifndef WINBOOL #ifndef WINBOOL
#define WINBOOL BOOL #define WINBOOL BOOL
#endif #endif
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif
#define MAX_COMMAND_LENGTH 32768 #define MAX_COMMAND_LENGTH 32768
#define MAX_ERROR_LENGTH 2048 #define MAX_ERROR_LENGTH 2048
@ -163,6 +166,17 @@ DWORD ExecuteCommand(string& command,bool reInp, LONGLONG &peakMemory, LONGLONG
return result; return result;
} }
void EnableVtSequence() {
DWORD mode;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (GetConsoleMode(hConsole, &mode))
SetConsoleMode(hConsole, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
hConsole = GetStdHandle(STD_ERROR_HANDLE);
if (GetConsoleMode(hConsole, &mode))
SetConsoleMode(hConsole, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
int main(int argc, char** argv) { int main(int argc, char** argv) {
const char *sharedMemoryId; const char *sharedMemoryId;
@ -220,6 +234,7 @@ int main(int argc, char** argv) {
} else { } else {
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)); FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
} }
EnableVtSequence();
HANDLE hSharedMemory=INVALID_HANDLE_VALUE; HANDLE hSharedMemory=INVALID_HANDLE_VALUE;
int BUF_SIZE=1024; int BUF_SIZE=1024;