Merge pull request #4515 from taosdata/feature/td-1680
[TD-1680]<feature>: print ellipsis when binary/nchar is too long
This commit is contained in:
commit
394024e62f
|
@ -509,7 +509,9 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
|
||||||
|
|
||||||
|
|
||||||
static void shellPrintNChar(const char *str, int length, int width) {
|
static void shellPrintNChar(const char *str, int length, int width) {
|
||||||
int pos = 0, cols = 0;
|
wchar_t tail[3];
|
||||||
|
int pos = 0, cols = 0, totalCols = 0, tailLen = 0;
|
||||||
|
|
||||||
while (pos < length) {
|
while (pos < length) {
|
||||||
wchar_t wc;
|
wchar_t wc;
|
||||||
int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX);
|
int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX);
|
||||||
|
@ -526,15 +528,44 @@ static void shellPrintNChar(const char *str, int length, int width) {
|
||||||
#else
|
#else
|
||||||
int w = wcwidth(wc);
|
int w = wcwidth(wc);
|
||||||
#endif
|
#endif
|
||||||
if (w > 0) {
|
if (w <= 0) {
|
||||||
if (width > 0 && cols + w > width) {
|
continue;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
if (width <= 0) {
|
||||||
|
printf("%lc", wc);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalCols += w;
|
||||||
|
if (totalCols > width) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (totalCols <= (width - 3)) {
|
||||||
printf("%lc", wc);
|
printf("%lc", wc);
|
||||||
cols += w;
|
cols += w;
|
||||||
|
} else {
|
||||||
|
tail[tailLen] = wc;
|
||||||
|
tailLen++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (totalCols > width) {
|
||||||
|
// width could be 1 or 2, so printf("...") cannot be used
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (cols >= width) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
putchar('.');
|
||||||
|
++cols;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < tailLen; i++) {
|
||||||
|
printf("%lc", tail[i]);
|
||||||
|
}
|
||||||
|
cols = totalCols;
|
||||||
|
}
|
||||||
|
|
||||||
for (; cols < width; cols++) {
|
for (; cols < width; cols++) {
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
}
|
}
|
||||||
|
@ -656,13 +687,21 @@ static int calcColWidth(TAOS_FIELD* field, int precision) {
|
||||||
return MAX(25, width);
|
return MAX(25, width);
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_BINARY:
|
case TSDB_DATA_TYPE_BINARY:
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
|
||||||
if (field->bytes > tsMaxBinaryDisplayWidth) {
|
if (field->bytes > tsMaxBinaryDisplayWidth) {
|
||||||
return MAX(tsMaxBinaryDisplayWidth, width);
|
return MAX(tsMaxBinaryDisplayWidth, width);
|
||||||
} else {
|
} else {
|
||||||
return MAX(field->bytes, width);
|
return MAX(field->bytes, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_NCHAR: {
|
||||||
|
int16_t bytes = field->bytes * TSDB_NCHAR_SIZE;
|
||||||
|
if (bytes > tsMaxBinaryDisplayWidth) {
|
||||||
|
return MAX(tsMaxBinaryDisplayWidth, width);
|
||||||
|
} else {
|
||||||
|
return MAX(bytes, width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
if (args.is_raw_time) {
|
if (args.is_raw_time) {
|
||||||
return MAX(14, width);
|
return MAX(14, width);
|
||||||
|
|
Loading…
Reference in New Issue