diff --git a/src/kit/shell/CMakeLists.txt b/src/kit/shell/CMakeLists.txt index 794ca5e2de1820035524cc4180558b9f290c22c6..57c30d8e62f2fbcc1ddf0c4e12693c7456727f08 100644 --- a/src/kit/shell/CMakeLists.txt +++ b/src/kit/shell/CMakeLists.txt @@ -26,6 +26,8 @@ ENDIF () SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos) ELSEIF (TD_WINDOWS) + ADD_DEFINITIONS(-DUNICODE) + ADD_DEFINITIONS(-D_UNICODE) LIST(APPEND SRC ./src/shellEngine.c) LIST(APPEND SRC ./src/shellMain.c) LIST(APPEND SRC ./src/shellWindows.c) diff --git a/src/kit/shell/src/shellMain.c b/src/kit/shell/src/shellMain.c index 4c7e550760cecb7c045cb8c94fc431cb5f91812b..2cf0bbeeb125de3b5162bb480e32d56539f25ea6 100644 --- a/src/kit/shell/src/shellMain.c +++ b/src/kit/shell/src/shellMain.c @@ -89,6 +89,9 @@ SShellArguments args = { */ int main(int argc, char* argv[]) { /*setlocale(LC_ALL, "en_US.UTF-8"); */ +#ifdef WINDOWS + SetConsoleOutputCP(CP_UTF8); +#endif if (!checkVersion()) { exit(EXIT_FAILURE); diff --git a/src/kit/shell/src/shellWindows.c b/src/kit/shell/src/shellWindows.c index 87d11a3516a65e83201bf4ebe51f07e5394d5cdf..fd4032a84258596dc6db9f360457289403c1a7ff 100644 --- a/src/kit/shell/src/shellWindows.c +++ b/src/kit/shell/src/shellWindows.c @@ -232,13 +232,16 @@ int32_t shellReadCommand(TAOS *con, char command[]) { cmd.command = (char *)calloc(1, MAX_COMMAND_SIZE); // Read input. - char c; + void *console = GetStdHandle(STD_INPUT_HANDLE); + unsigned long read; + wchar_t c; + char mbStr[16]; while (1) { - c = getchar(); - + int ret = ReadConsole(console, &c, 1, &read, NULL); + int size = WideCharToMultiByte(CP_UTF8, 0, &c, read, mbStr, sizeof(mbStr), NULL, NULL); + mbStr[size] = 0; switch (c) { case '\n': - case '\r': if (isReadyGo(&cmd)) { sprintf(command, "%s%s", cmd.buffer, cmd.command); free(cmd.buffer); @@ -251,8 +254,12 @@ int32_t shellReadCommand(TAOS *con, char command[]) { updateBuffer(&cmd); } break; + case '\r': + break; default: - insertChar(&cmd, c); + for (int i = 0; i < size; ++i) { + insertChar(&cmd, mbStr[i]); + } } }