From bbf364a442b463f3cf0d310ad052727de68a493a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20S=C3=B6derqvist?= Date: Sun, 19 Mar 2023 11:56:54 +0100 Subject: redis-cli: Accept commands in subscribed mode (#11873) The message "Reading messages... (press Ctrl-C to quit)" is replaced by "Reading messages... (press Ctrl-C to quit or any key to type command)". This allows users to subscribe to more channels, to try out UNSUBSCRIBE and to combine pubsub with other features such as push messages from client tracking. The "Reading messages" info message is displayed in the bottom of the output in a distinct style and moves downward as more messages appear. When any key is pressed, the info message is replaced by the prompt with for entering commands. After entering a command and the reply is displayed, the "Reading messages" info messages appears again. This is added to the repl loop in redis-cli and in the corresponding place for non-interactive mode. An indication "(subscribed mode)" is included in the prompt when entering commands in subscribed mode. Also: * Fixes a problem that UNSUBSCRIBE hanged when used with RESP3 and push callback, without first entering subscribe mode. It hanged because UNSUBSCRIBE gets one or more push replies but no in-band reply. * Exit subscribed mode after RESET. --- deps/linenoise/linenoise.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'deps') diff --git a/deps/linenoise/linenoise.c b/deps/linenoise/linenoise.c index 1b01622c5..dd86abe86 100644 --- a/deps/linenoise/linenoise.c +++ b/deps/linenoise/linenoise.c @@ -163,6 +163,7 @@ enum KEY_ACTION{ CTRL_F = 6, /* Ctrl-f */ CTRL_H = 8, /* Ctrl-h */ TAB = 9, /* Tab */ + NL = 10, /* Enter typed before raw mode was enabled */ CTRL_K = 11, /* Ctrl+k */ CTRL_L = 12, /* Ctrl+l */ ENTER = 13, /* Enter */ @@ -256,8 +257,8 @@ static int enableRawMode(int fd) { * We want read to return every single byte, without timeout. */ raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0; /* 1 byte, no timer */ - /* put terminal in raw mode after flushing */ - if (tcsetattr(fd,TCSAFLUSH,&raw) < 0) goto fatal; + /* put terminal in raw mode */ + if (tcsetattr(fd,TCSANOW,&raw) < 0) goto fatal; rawmode = 1; return 0; @@ -268,7 +269,7 @@ fatal: static void disableRawMode(int fd) { /* Don't even check the return value as it's too late. */ - if (rawmode && tcsetattr(fd,TCSAFLUSH,&orig_termios) != -1) + if (rawmode && tcsetattr(fd,TCSANOW,&orig_termios) != -1) rawmode = 0; } @@ -840,6 +841,8 @@ static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, } switch(c) { + case NL: /* enter, typed before raw mode was enabled */ + break; case ENTER: /* enter */ history_len--; free(history[history_len]); -- cgit v1.2.1