redis-cli: Aligned RESP3 maps with multiline value in TTY (#10170)
Before: ``` 127.0.0.1:6379> command info get 1) 1) "get" 2) (integer) 2 3) 1~ readonly 2~ fast 4) (integer) 1 5) (integer) 1 6) (integer) 1 7) 1~ @read 2~ @string 3~ @fast 8) (empty set) 9) 1~ 1# "flags" => 1~ RO 2~ access 2# "begin_search" => 1# "type" => "index" 2# "spec" => 1# "index" => (integer) 1 3# "find_keys" => 1# "type" => "range" 2# "spec" => 1# "lastkey" => (integer) 0 2# "keystep" => (integer) 1 3# "limit" => (integer) 0 10) (empty set) ``` After: ``` 127.0.0.1:6379> command info get 1) 1) "get" 2) (integer) 2 3) 1~ readonly 2~ fast 4) (integer) 1 5) (integer) 1 6) (integer) 1 7) 1~ @read 2~ @string 3~ @fast 8) (empty set) 9) 1~ 1# "flags" => 1~ RO 2~ access 2# "begin_search" => 1# "type" => "index" 2# "spec" => 1# "index" => (integer) 1 3# "find_keys" => 1# "type" => "range" 2# "spec" => 1# "lastkey" => (integer) 0 2# "keystep" => (integer) 1 3# "limit" => (integer) 0 10) (empty set) ```
This commit is contained in:
parent
5a38ccc253
commit
4491ee1805
@ -878,6 +878,24 @@ static sds cliFormatInvalidateTTY(redisReply *r) {
|
||||
return sdscatlen(out, "\n", 1);
|
||||
}
|
||||
|
||||
/* Returns non-zero if cliFormatReplyTTY renders the reply in multiple lines. */
|
||||
static int cliIsMultilineValueTTY(redisReply *r) {
|
||||
switch (r->type) {
|
||||
case REDIS_REPLY_ARRAY:
|
||||
case REDIS_REPLY_SET:
|
||||
case REDIS_REPLY_PUSH:
|
||||
if (r->elements == 0) return 0;
|
||||
if (r->elements > 1) return 1;
|
||||
return cliIsMultilineValueTTY(r->element[0]);
|
||||
case REDIS_REPLY_MAP:
|
||||
if (r->elements == 0) return 0;
|
||||
if (r->elements > 2) return 1;
|
||||
return cliIsMultilineValueTTY(r->element[1]);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static sds cliFormatReplyTTY(redisReply *r, char *prefix) {
|
||||
sds out = sdsempty();
|
||||
switch (r->type) {
|
||||
@ -974,6 +992,11 @@ static sds cliFormatReplyTTY(redisReply *r, char *prefix) {
|
||||
i++;
|
||||
sdsrange(out,0,-2);
|
||||
out = sdscat(out," => ");
|
||||
if (cliIsMultilineValueTTY(r->element[i])) {
|
||||
/* linebreak before multiline value to fix alignment */
|
||||
out = sdscat(out, "\n");
|
||||
out = sdscat(out, _prefix);
|
||||
}
|
||||
tmp = cliFormatReplyTTY(r->element[i],_prefix);
|
||||
out = sdscatlen(out,tmp,sdslen(tmp));
|
||||
sdsfree(tmp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user