提交 69bfdcf7 编写于 作者: P Pieter Noordhuis

Show database number in cli prompt when non-zero

上级 699465c3
...@@ -65,6 +65,7 @@ static struct config { ...@@ -65,6 +65,7 @@ static struct config {
char *historyfile; char *historyfile;
int raw_output; /* output mode per command */ int raw_output; /* output mode per command */
sds mb_delim; sds mb_delim;
char prompt[32];
} config; } config;
static void usage(); static void usage();
...@@ -85,6 +86,13 @@ static long long mstime(void) { ...@@ -85,6 +86,13 @@ static long long mstime(void) {
return mst; return mst;
} }
static void cliRefreshPrompt(void) {
if (config.dbnum == 0)
snprintf(config.prompt,sizeof(config.prompt),"redis> ");
else
snprintf(config.prompt,sizeof(config.prompt),"redis:%d> ",config.dbnum);
}
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Help functions * Help functions
*--------------------------------------------------------------------------- */ *--------------------------------------------------------------------------- */
...@@ -492,8 +500,10 @@ static int cliSendCommand(int argc, char **argv, int repeat) { ...@@ -492,8 +500,10 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
return REDIS_ERR; return REDIS_ERR;
} else { } else {
/* Store database number when SELECT was successfully executed. */ /* Store database number when SELECT was successfully executed. */
if (!strcasecmp(command,"select") && argc == 2) if (!strcasecmp(command,"select") && argc == 2) {
config.dbnum = atoi(argv[1]); config.dbnum = atoi(argv[1]);
cliRefreshPrompt();
}
} }
} }
...@@ -622,7 +632,8 @@ static void repl() { ...@@ -622,7 +632,8 @@ static void repl() {
config.interactive = 1; config.interactive = 1;
linenoiseSetCompletionCallback(completionCallback); linenoiseSetCompletionCallback(completionCallback);
while((line = linenoise(context ? "redis> " : "not connected> ")) != NULL) { cliRefreshPrompt();
while((line = linenoise(context ? config.prompt : "not connected> ")) != NULL) {
if (line[0] != '\0') { if (line[0] != '\0') {
argv = sdssplitargs(line,&argc); argv = sdssplitargs(line,&argc);
linenoiseHistoryAdd(line); linenoiseHistoryAdd(line);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册