X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/0439d792c46efa328d67e098d688435bca1e2700..3a51bff0358c38162bc925ab25661e6090cf1161:/src/redis-cli.c diff --git a/src/redis-cli.c b/src/redis-cli.c index 87ebcb69..fc2238d4 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -60,6 +60,8 @@ static struct config { int monitor_mode; int pubsub_mode; int raw_output; /* output mode per command */ + int tty; /* flag for default output format */ + char mb_sep; char *auth; char *historyfile; } config; @@ -107,7 +109,7 @@ static int cliReadSingleLineReply(int fd, int quiet) { if (reply == NULL) return 1; if (!quiet) - printf("%s\n", reply); + printf("%s", reply); sdsfree(reply); return 0; } @@ -134,7 +136,7 @@ static void printStringRepr(char *s, int len) { } s++; } - printf("\"\n"); + printf("\""); } static int cliReadBulkReply(int fd) { @@ -152,7 +154,7 @@ static int cliReadBulkReply(int fd) { reply = zmalloc(bulklen); anetRead(fd,reply,bulklen); anetRead(fd,crlf,2); - if (config.raw_output || !config.interactive) { + if (config.raw_output || !config.tty) { if (bulklen && fwrite(reply,bulklen,1,stdout) == 0) { zfree(reply); return 1; @@ -181,8 +183,9 @@ static int cliReadMultiBulkReply(int fd) { printf("(empty list or set)\n"); } while(elements--) { - printf("%d. ", c); + if (config.tty) printf("%d. ", c); if (cliReadReply(fd)) return 1; + if (elements) printf("%c",config.mb_sep); c++; } return 0; @@ -197,13 +200,13 @@ static int cliReadReply(int fd) { } switch(type) { case '-': - printf("(error) "); + if (config.tty) printf("(error) "); cliReadSingleLineReply(fd,0); return 1; case '+': return cliReadSingleLineReply(fd,0); case ':': - printf("(integer) "); + if (config.tty) printf("(integer) "); return cliReadSingleLineReply(fd,0); case '$': return cliReadBulkReply(fd); @@ -273,7 +276,7 @@ static int cliSendCommand(int argc, char **argv, int repeat) { printf("Reading messages... (press Ctrl-c to quit)\n"); while (1) { cliReadReply(fd); - printf("\n"); + printf("\n\n"); } } @@ -281,6 +284,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) { if (retval) { return retval; } + if (!config.raw_output && config.tty) { + printf("\n"); + } } return 0; } @@ -490,6 +496,8 @@ int main(int argc, char **argv) { config.raw_output = 0; config.auth = NULL; config.historyfile = NULL; + config.tty = 1; + config.mb_sep = '\n'; if (getenv("HOME") != NULL) { config.historyfile = malloc(256); @@ -514,6 +522,7 @@ int main(int argc, char **argv) { repl(); } + config.tty = isatty(fileno(stdout)) || (getenv("FAKETTY") != NULL); argvcopy = convertToSds(argc+1, argv); if (config.argn_from_stdin) { sds lastarg = readArgFromStdin();