From 4e3aa5d5d3228ffb193582f2c25a648eea704b30 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Mon, 25 May 2020 18:45:43 +0800 Subject: [PATCH] update shellPrintNChar it padding the output to be exactly `width` columns now. --- src/kit/shell/inc/shell.h | 2 +- src/kit/shell/src/shellDarwin.c | 6 ++++-- src/kit/shell/src/shellEngine.c | 4 +--- src/kit/shell/src/shellLinux.c | 6 ++++-- src/kit/shell/src/shellWindows.c | 6 ++++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/kit/shell/inc/shell.h b/src/kit/shell/inc/shell.h index 51bd1c1102..5400d9c5ba 100644 --- a/src/kit/shell/inc/shell.h +++ b/src/kit/shell/inc/shell.h @@ -68,7 +68,7 @@ void get_history_path(char* history); void cleanup_handler(void* arg); void exitShell(); int shellDumpResult(TAOS* con, char* fname, int* error_no, bool printMode); -int shellPrintNChar(const char* str, int length, int width); +void shellPrintNChar(const char* str, int length, int width); void shellGetGrantInfo(void *con); int isCommentLine(char *line); diff --git a/src/kit/shell/src/shellDarwin.c b/src/kit/shell/src/shellDarwin.c index 2f5d1f421d..e4ef06c403 100644 --- a/src/kit/shell/src/shellDarwin.c +++ b/src/kit/shell/src/shellDarwin.c @@ -352,7 +352,7 @@ void *shellLoopQuery(void *arg) { return NULL; } -int shellPrintNChar(const char *str, int length, int width) { +void shellPrintNChar(const char *str, int length, int width) { int pos = 0, cols = 0; while (pos < length) { wchar_t wc; @@ -371,7 +371,9 @@ int shellPrintNChar(const char *str, int length, int width) { } } - return cols; + for (; cols < width; cols++) { + putchar(' '); + } } diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index b4103ab331..ba5909923b 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -484,9 +484,7 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: - for (int w = shellPrintNChar(val, length, width); w < width; w++) { - putchar(' '); - } + shellPrintNChar(val, length, width); break; case TSDB_DATA_TYPE_TIMESTAMP: formatTimestamp(buf, *(int64_t*)val, precision); diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index 37c08d7ae9..856e011a78 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -329,7 +329,7 @@ void *shellLoopQuery(void *arg) { return NULL; } -int shellPrintNChar(const char *str, int length, int width) { +void shellPrintNChar(const char *str, int length, int width) { int pos = 0, cols = 0; while (pos < length) { wchar_t wc; @@ -348,7 +348,9 @@ int shellPrintNChar(const char *str, int length, int width) { } } - return cols; + for (; cols < width; cols++) { + putchar(' '); + } } int get_old_terminal_mode(struct termios *tio) { diff --git a/src/kit/shell/src/shellWindows.c b/src/kit/shell/src/shellWindows.c index 8c7f24ef52..c446677276 100644 --- a/src/kit/shell/src/shellWindows.c +++ b/src/kit/shell/src/shellWindows.c @@ -217,7 +217,7 @@ void *shellLoopQuery(void *arg) { return NULL; } -int shellPrintNChar(const char *str, int length, int width) { +void shellPrintNChar(const char *str, int length, int width) { int pos = 0, cols = 0; while (pos < length) { wchar_t wc; @@ -237,7 +237,9 @@ int shellPrintNChar(const char *str, int length, int width) { } } - return cols; + for (; cols < width; cols++) { + putchar(' '); + } } -- GitLab