未验证 提交 9c07d24a 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #8452 from taosdata/fix/TS-441

[TS-441]<fix>: add windows unicode support
......@@ -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)
......
......@@ -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);
......
......@@ -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]);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册