Commit bbac56c2 authored by antirez's avatar antirez
Browse files

added support for ctrl-l and clear command into redis-cli. To clear the screen...

added support for ctrl-l and clear command into redis-cli. To clear the screen is a good idea from time to time :). Also linenoise updated to the current version to support this new feature.
parent ce260f73
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
* the 2010 UNIX computers around. * the 2010 UNIX computers around.
* *
* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com> * Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -66,6 +68,17 @@ ...@@ -66,6 +68,17 @@
* CUF (CUrsor Forward) * CUF (CUrsor Forward)
* Sequence: ESC [ n C * Sequence: ESC [ n C
* Effect: moves cursor forward of n chars * Effect: moves cursor forward of n chars
*
* The following are used to clear the screen: ESC [ H ESC [ 2 J
* This is actually composed of two sequences:
*
* cursorhome
* Sequence: ESC [ H
* Effect: moves the cursor to upper left corner
*
* ED2 (Clear entire screen)
* Sequence: ESC [ 2 J
* Effect: clear the whole screen
* *
*/ */
...@@ -265,6 +278,10 @@ static int completeLine(int fd, const char *prompt, char *buf, size_t buflen, si ...@@ -265,6 +278,10 @@ static int completeLine(int fd, const char *prompt, char *buf, size_t buflen, si
return c; /* Return last read character */ return c; /* Return last read character */
} }
void linenoiseClearScreen(void) {
write(STDIN_FILENO,"\x1b[H\x1b[2J",7);
}
static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) { static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) {
size_t plen = strlen(prompt); size_t plen = strlen(prompt);
size_t pos = 0; size_t pos = 0;
...@@ -432,6 +449,9 @@ up_down_arrow: ...@@ -432,6 +449,9 @@ up_down_arrow:
pos = len; pos = len;
refreshLine(fd,prompt,buf,len,pos,cols); refreshLine(fd,prompt,buf,len,pos,cols);
break; break;
case 12: /* ctrl+l, clear screen */
linenoiseClearScreen();
refreshLine(fd,prompt,buf,len,pos,cols);
} }
} }
return len; return len;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* See linenoise.c for more information. * See linenoise.c for more information.
* *
* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com> * Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
*
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -48,5 +50,6 @@ int linenoiseHistoryAdd(const char *line); ...@@ -48,5 +50,6 @@ int linenoiseHistoryAdd(const char *line);
int linenoiseHistorySetMaxLen(int len); int linenoiseHistorySetMaxLen(int len);
int linenoiseHistorySave(char *filename); int linenoiseHistorySave(char *filename);
int linenoiseHistoryLoad(char *filename); int linenoiseHistoryLoad(char *filename);
void linenoiseClearScreen(void);
#endif /* __LINENOISE_H */ #endif /* __LINENOISE_H */
...@@ -561,6 +561,8 @@ static void repl() { ...@@ -561,6 +561,8 @@ static void repl() {
config.hostip = sdsnew(argv[1]); config.hostip = sdsnew(argv[1]);
config.hostport = atoi(argv[2]); config.hostport = atoi(argv[2]);
cliConnect(1); cliConnect(1);
} else if (argc == 1 && !strcasecmp(argv[0],"clear")) {
linenoiseClearScreen();
} else { } else {
long long start_time = mstime(), elapsed; long long start_time = mstime(), elapsed;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment