From c7c735dcff9bdb67435cc82a4bcf36fe2ddea1d6 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Fri, 21 Oct 2022 10:49:27 +0800 Subject: [PATCH] fix(shell): supported input with chinese --- src/kit/shell/src/shellAuto.c | 12 ++++++------ src/kit/shell/src/shellCommand.c | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/kit/shell/src/shellAuto.c b/src/kit/shell/src/shellAuto.c index 970bf65ca2..a96aa3f581 100644 --- a/src/kit/shell/src/shellAuto.c +++ b/src/kit/shell/src/shellAuto.c @@ -31,7 +31,7 @@ // extern function -void insertChar(Command *cmd, char *c, int size); +void insertStr(Command *cmd, char *str, int size); typedef struct SAutoPtr { @@ -1077,7 +1077,7 @@ void printScreen(TAOS * con, Command * cmd, SWords * match) { } // insert new - insertChar(cmd, (char *)str, strLen); + insertStr(cmd, (char *)str, strLen); } @@ -1192,7 +1192,7 @@ bool fillWithType(TAOS * con, Command * cmd, char* pre, int type) { // show int count = strlen(part); - insertChar(cmd, part, count); + insertStr(cmd, part, count); cntDel = count; // next press tab delete current append count free(str); @@ -1220,7 +1220,7 @@ bool fillTableName(TAOS * con, Command * cmd, char* pre) { // show int count = strlen(part); - insertChar(cmd, part, count); + insertStr(cmd, part, count); cntDel = count; // next press tab delete current append count free(str); @@ -1344,7 +1344,7 @@ bool appendAfterSelect(TAOS * con, Command * cmd, char* sql, int32_t len) { bool fieldEnd = fieldsInputEnd(p); // cheeck fields input end then insert from keyword if (fieldEnd && p[len-1] == ' ') { - insertChar(cmd, "from", 4); + insertStr(cmd, "from", 4); free(p); return true; } @@ -1527,7 +1527,7 @@ bool matchOther(TAOS * con, Command * cmd) { if (p[len - 1] == '\\') { // append '\G' char a[] = "G;"; - insertChar(cmd, a, 2); + insertStr(cmd, a, 2); return true; } diff --git a/src/kit/shell/src/shellCommand.c b/src/kit/shell/src/shellCommand.c index 2fe09691e3..a14eeb5e94 100644 --- a/src/kit/shell/src/shellCommand.c +++ b/src/kit/shell/src/shellCommand.c @@ -79,11 +79,22 @@ void insertChar(Command *cmd, char *c, int size) { /* update the values */ cmd->commandSize += size; cmd->cursorOffset += size; - for (int i = 0; i < size; i++) { - mbtowc(&wc, c + i, size); - cmd->screenOffset += wcwidth(wc); - cmd->endOffset += wcwidth(wc); - } + cmd->screenOffset += wcwidth(wc); + cmd->endOffset += wcwidth(wc); + showOnScreen(cmd); +} + +void insertStr(Command *cmd, char *str, int size) { + clearScreen(cmd->endOffset + prompt_size, cmd->screenOffset + prompt_size); + /* update the buffer */ + memmove(cmd->command + cmd->cursorOffset + size, cmd->command + cmd->cursorOffset, + cmd->commandSize - cmd->cursorOffset); + memcpy(cmd->command + cmd->cursorOffset, str, size); + /* update the values */ + cmd->commandSize += size; + cmd->cursorOffset += size; + cmd->screenOffset += size; + cmd->endOffset += size; showOnScreen(cmd); } -- GitLab