未验证 提交 5513e3a7 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2028 from taosdata/feature/td-407

TD-407: add config for binary column display width
...@@ -202,6 +202,8 @@ char tsTimezone[64] = {0}; ...@@ -202,6 +202,8 @@ char tsTimezone[64] = {0};
char tsLocale[TSDB_LOCALE_LEN] = {0}; char tsLocale[TSDB_LOCALE_LEN] = {0};
char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string
int32_t tsMaxBinaryDisplayWidth = 30;
static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT; static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT;
void taosSetAllDebugFlag() { void taosSetAllDebugFlag() {
...@@ -1227,6 +1229,16 @@ static void doInitGlobalConfig() { ...@@ -1227,6 +1229,16 @@ static void doInitGlobalConfig() {
cfg.ptrLength = 0; cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "maxBinaryDisplayWidth";
cfg.ptr = &tsMaxBinaryDisplayWidth;
cfg.valType = TAOS_CFG_VTYPE_INT32;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 1;
cfg.maxValue = 0x7fffffff;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
} }
void taosInitGlobalCfg() { void taosInitGlobalCfg() {
......
...@@ -29,18 +29,6 @@ ...@@ -29,18 +29,6 @@
#define MAX_COMMAND_SIZE 65536 #define MAX_COMMAND_SIZE 65536
#define HISTORY_FILE ".taos_history" #define HISTORY_FILE ".taos_history"
#define BOOL_OUTPUT_LENGTH 6
#define TINYINT_OUTPUT_LENGTH 6
#define SMALLINT_OUTPUT_LENGTH 7
#define INT_OUTPUT_LENGTH 11
#define BIGINT_OUTPUT_LENGTH 21
#define FLOAT_OUTPUT_LENGTH 20
#define DOUBLE_OUTPUT_LENGTH 25
#define BINARY_OUTPUT_LENGTH 20
// dynamic config timestamp width according to maximum time precision
extern int32_t TIMESTAMP_OUTPUT_LENGTH;
typedef struct SShellHistory { typedef struct SShellHistory {
char* hist[MAX_HISTORY_SIZE]; char* hist[MAX_HISTORY_SIZE];
int hstart; int hstart;
...@@ -80,7 +68,7 @@ void get_history_path(char* history); ...@@ -80,7 +68,7 @@ void get_history_path(char* history);
void cleanup_handler(void* arg); void cleanup_handler(void* arg);
void exitShell(); void exitShell();
int shellDumpResult(TAOS* con, char* fname, int* error_no, bool printMode); int shellDumpResult(TAOS* con, char* fname, int* error_no, bool printMode);
void shellPrintNChar(char* str, int width, bool printMode); void shellPrintNChar(const char* str, int length, int width);
void shellGetGrantInfo(void *con); void shellGetGrantInfo(void *con);
int isCommentLine(char *line); int isCommentLine(char *line);
......
...@@ -352,37 +352,31 @@ void *shellLoopQuery(void *arg) { ...@@ -352,37 +352,31 @@ void *shellLoopQuery(void *arg) {
return NULL; return NULL;
} }
void shellPrintNChar(char *str, int width, bool printMode) { void shellPrintNChar(const char *str, int length, int width) {
int col_left = width; int pos = 0, cols = 0;
wchar_t wc; while (pos < length) {
while (col_left > 0) { wchar_t wc;
if (*str == '\0') break; pos += mbtowc(&wc, str + pos, MB_CUR_MAX);
char *tstr = str; if (pos > length) {
int byte_width = mbtowc(&wc, tstr, MB_CUR_MAX); break;
if (byte_width <= 0) break;
int col_width = wcwidth(wc);
if (col_width <= 0) {
str += byte_width;
continue;
} }
if (col_left < col_width) break;
printf("%lc", wc);
str += byte_width;
col_left -= col_width;
}
while (col_left > 0) { int w = wcwidth(wc);
printf(" "); if (w > 0) {
col_left--; if (width > 0 && cols + w > width) {
break;
}
printf("%lc", wc);
cols += w;
}
} }
if (!printMode) { for (; cols < width; cols++) {
printf("|"); putchar(' ');
} else {
printf("\n");
} }
} }
int get_old_terminal_mode(struct termios *tio) { int get_old_terminal_mode(struct termios *tio) {
/* Make sure stdin is a terminal. */ /* Make sure stdin is a terminal. */
if (!isatty(STDIN_FILENO)) { if (!isatty(STDIN_FILENO)) {
......
此差异已折叠。
...@@ -329,34 +329,27 @@ void *shellLoopQuery(void *arg) { ...@@ -329,34 +329,27 @@ void *shellLoopQuery(void *arg) {
return NULL; return NULL;
} }
void shellPrintNChar(char *str, int width, bool printMode) { void shellPrintNChar(const char *str, int length, int width) {
int col_left = width; int pos = 0, cols = 0;
wchar_t wc; while (pos < length) {
while (col_left > 0) { wchar_t wc;
if (*str == '\0') break; pos += mbtowc(&wc, str + pos, MB_CUR_MAX);
char *tstr = str; if (pos > length) {
int byte_width = mbtowc(&wc, tstr, MB_CUR_MAX); break;
if (byte_width <= 0) break;
int col_width = wcwidth(wc);
if (col_width <= 0) {
str += byte_width;
continue;
} }
if (col_left < col_width) break;
printf("%lc", wc);
str += byte_width;
col_left -= col_width;
}
while (col_left > 0) { int w = wcwidth(wc);
printf(" "); if (w > 0) {
col_left--; if (width > 0 && cols + w > width) {
break;
}
printf("%lc", wc);
cols += w;
}
} }
if (!printMode) { for (; cols < width; cols++) {
printf("|"); putchar(' ');
} else {
printf("\n");
} }
} }
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
TAOS* con; TAOS* con;
pthread_t pid; pthread_t pid;
int32_t TIMESTAMP_OUTPUT_LENGTH = 22;
// TODO: IMPLEMENT INTERRUPT HANDLER. // TODO: IMPLEMENT INTERRUPT HANDLER.
void interruptHandler(int signum) { void interruptHandler(int signum) {
......
...@@ -217,32 +217,32 @@ void *shellLoopQuery(void *arg) { ...@@ -217,32 +217,32 @@ void *shellLoopQuery(void *arg) {
return NULL; return NULL;
} }
void shellPrintNChar(char *str, int width, bool printMode) { void shellPrintNChar(const char *str, int length, int width) {
int col_left = width; int pos = 0, cols = 0;
wchar_t wc; while (pos < length) {
while (col_left > 0) { wchar_t wc;
if (*str == '\0') break; int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX);
char *tstr = str; pos += bytes;
int byte_width = mbtowc(&wc, tstr, MB_CUR_MAX); if (pos > length) {
int col_width = byte_width; break;
if (col_left < col_width) break; }
printf("%lc", wc);
str += byte_width;
col_left -= col_width;
}
while (col_left > 0) { int w = bytes;
printf(" "); if (w > 0) {
col_left--; if (width > 0 && cols + w > width) {
break;
}
printf("%lc", wc);
cols += w;
}
} }
if (!printMode) { for (; cols < width; cols++) {
printf("|"); putchar(' ');
} else {
printf("\n");
} }
} }
void get_history_path(char *history) { sprintf(history, "%s/%s", ".", HISTORY_FILE); } void get_history_path(char *history) { sprintf(history, "%s/%s", ".", HISTORY_FILE); }
void exitShell() { exit(EXIT_SUCCESS); } void exitShell() { exit(EXIT_SUCCESS); }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册