提交 c7c735dc 编写于 作者: A Alex Duan

fix(shell): supported input with chinese

上级 d28de946
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
// extern function // extern function
void insertChar(Command *cmd, char *c, int size); void insertStr(Command *cmd, char *str, int size);
typedef struct SAutoPtr { typedef struct SAutoPtr {
...@@ -1077,7 +1077,7 @@ void printScreen(TAOS * con, Command * cmd, SWords * match) { ...@@ -1077,7 +1077,7 @@ void printScreen(TAOS * con, Command * cmd, SWords * match) {
} }
// insert new // 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) { ...@@ -1192,7 +1192,7 @@ bool fillWithType(TAOS * con, Command * cmd, char* pre, int type) {
// show // show
int count = strlen(part); int count = strlen(part);
insertChar(cmd, part, count); insertStr(cmd, part, count);
cntDel = count; // next press tab delete current append count cntDel = count; // next press tab delete current append count
free(str); free(str);
...@@ -1220,7 +1220,7 @@ bool fillTableName(TAOS * con, Command * cmd, char* pre) { ...@@ -1220,7 +1220,7 @@ bool fillTableName(TAOS * con, Command * cmd, char* pre) {
// show // show
int count = strlen(part); int count = strlen(part);
insertChar(cmd, part, count); insertStr(cmd, part, count);
cntDel = count; // next press tab delete current append count cntDel = count; // next press tab delete current append count
free(str); free(str);
...@@ -1344,7 +1344,7 @@ bool appendAfterSelect(TAOS * con, Command * cmd, char* sql, int32_t len) { ...@@ -1344,7 +1344,7 @@ bool appendAfterSelect(TAOS * con, Command * cmd, char* sql, int32_t len) {
bool fieldEnd = fieldsInputEnd(p); bool fieldEnd = fieldsInputEnd(p);
// cheeck fields input end then insert from keyword // cheeck fields input end then insert from keyword
if (fieldEnd && p[len-1] == ' ') { if (fieldEnd && p[len-1] == ' ') {
insertChar(cmd, "from", 4); insertStr(cmd, "from", 4);
free(p); free(p);
return true; return true;
} }
...@@ -1527,7 +1527,7 @@ bool matchOther(TAOS * con, Command * cmd) { ...@@ -1527,7 +1527,7 @@ bool matchOther(TAOS * con, Command * cmd) {
if (p[len - 1] == '\\') { if (p[len - 1] == '\\') {
// append '\G' // append '\G'
char a[] = "G;"; char a[] = "G;";
insertChar(cmd, a, 2); insertStr(cmd, a, 2);
return true; return true;
} }
......
...@@ -79,11 +79,22 @@ void insertChar(Command *cmd, char *c, int size) { ...@@ -79,11 +79,22 @@ void insertChar(Command *cmd, char *c, int size) {
/* update the values */ /* update the values */
cmd->commandSize += size; cmd->commandSize += size;
cmd->cursorOffset += size; cmd->cursorOffset += size;
for (int i = 0; i < size; i++) {
mbtowc(&wc, c + i, size);
cmd->screenOffset += wcwidth(wc); cmd->screenOffset += wcwidth(wc);
cmd->endOffset += 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); showOnScreen(cmd);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册