summaryrefslogtreecommitdiff
path: root/deps
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2010-12-01 11:18:59 +0100
committerantirez <antirez@gmail.com>2010-12-01 11:18:59 +0100
commitbbac56c2f823a6ab2170e1b00b93a620188b76da (patch)
tree4c91945574f3b35d3f3ed44ce71cbbb1b9d991c9 /deps
parentce260f736e483d40967d3e551f04534154c12aba (diff)
downloadredis-bbac56c2f823a6ab2170e1b00b93a620188b76da.tar.gz
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.
Diffstat (limited to 'deps')
-rw-r--r--deps/linenoise/linenoise.c20
-rw-r--r--deps/linenoise/linenoise.h3
2 files changed, 23 insertions, 0 deletions
diff --git a/deps/linenoise/linenoise.c b/deps/linenoise/linenoise.c
index b6f4d4f9b..dd4341366 100644
--- a/deps/linenoise/linenoise.c
+++ b/deps/linenoise/linenoise.c
@@ -9,6 +9,8 @@
* the 2010 UNIX computers around.
*
* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
+ * Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
+ *
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -66,6 +68,17 @@
* CUF (CUrsor Forward)
* Sequence: ESC [ n C
* 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
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) {
size_t plen = strlen(prompt);
size_t pos = 0;
@@ -432,6 +449,9 @@ up_down_arrow:
pos = len;
refreshLine(fd,prompt,buf,len,pos,cols);
break;
+ case 12: /* ctrl+l, clear screen */
+ linenoiseClearScreen();
+ refreshLine(fd,prompt,buf,len,pos,cols);
}
}
return len;
diff --git a/deps/linenoise/linenoise.h b/deps/linenoise/linenoise.h
index c44bc3ade..76a703c28 100644
--- a/deps/linenoise/linenoise.h
+++ b/deps/linenoise/linenoise.h
@@ -4,6 +4,8 @@
* See linenoise.c for more information.
*
* Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
+ * Copyright (c) 2010, Pieter Noordhuis <pcnoordhuis at gmail dot com>
+ *
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,5 +50,6 @@ int linenoiseHistoryAdd(const char *line);
int linenoiseHistorySetMaxLen(int len);
int linenoiseHistorySave(char *filename);
int linenoiseHistoryLoad(char *filename);
+void linenoiseClearScreen(void);
#endif /* __LINENOISE_H */