From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LfMZa-0008Tx-Mc for qemu-devel@nongnu.org; Thu, 05 Mar 2009 18:01:50 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LfMZZ-0008Ta-MF for qemu-devel@nongnu.org; Thu, 05 Mar 2009 18:01:50 -0500 Received: from [199.232.76.173] (port=37326 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfMZZ-0008TV-H2 for qemu-devel@nongnu.org; Thu, 05 Mar 2009 18:01:49 -0500 Received: from savannah.gnu.org ([199.232.41.3]:59824 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LfMZZ-0005fD-1j for qemu-devel@nongnu.org; Thu, 05 Mar 2009 18:01:49 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LfMZY-0002Pw-Je for qemu-devel@nongnu.org; Thu, 05 Mar 2009 23:01:48 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LfMZY-0002PO-8Y for qemu-devel@nongnu.org; Thu, 05 Mar 2009 23:01:48 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 05 Mar 2009 23:01:48 +0000 Subject: [Qemu-devel] [6716] monitor: Improve mux'ed console experience (Jan Kiszka) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6716 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6716 Author: aliguori Date: 2009-03-05 23:01:47 +0000 (Thu, 05 Mar 2009) Log Message: ----------- monitor: Improve mux'ed console experience (Jan Kiszka) Up to now, you never really knew if you already switched the console after pressing CTRL-A C or if you mistyped it again. This patch clarifies the situation by providing a prompt in a new line and injecting a linebreak when switching away again. For this purpose, the two events CHR_EVENT_MUX_IN and CHR_EVENT_MUX_OUT are introduced and distributed on focus switches. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/monitor.c trunk/qemu-char.c trunk/qemu-char.h trunk/readline.c trunk/readline.h Modified: trunk/monitor.c =================================================================== --- trunk/monitor.c 2009-03-05 23:01:42 UTC (rev 6715) +++ trunk/monitor.c 2009-03-05 23:01:47 UTC (rev 6716) @@ -2918,12 +2918,27 @@ { Monitor *mon = opaque; - if (event != CHR_EVENT_RESET) - return; + switch (event) { + case CHR_EVENT_MUX_IN: + readline_restart(mon->rs); + monitor_resume(mon); + monitor_flush(mon); + break; - monitor_printf(mon, "QEMU %s monitor - type 'help' for more information\n", - QEMU_VERSION); - readline_show_prompt(mon->rs); + case CHR_EVENT_MUX_OUT: + if (mon->suspend_cnt == 0) + monitor_printf(mon, "\n"); + monitor_flush(mon); + monitor_suspend(mon); + break; + + case CHR_EVENT_RESET: + monitor_printf(mon, "QEMU %s monitor - type 'help' for more " + "information\n", QEMU_VERSION); + if (mon->chr->focus == 0) + readline_show_prompt(mon->rs); + break; + } } void monitor_init(CharDriverState *chr, int flags) @@ -2940,6 +2955,8 @@ mon->chr = chr; mon->flags = flags; + if (mon->chr->focus != 0) + mon->suspend_cnt = 1; /* mux'ed monitors start suspended */ mon->rs = readline_init(mon, monitor_find_completion); monitor_read_command(mon, 0); Modified: trunk/qemu-char.c =================================================================== --- trunk/qemu-char.c 2009-03-05 23:01:42 UTC (rev 6715) +++ trunk/qemu-char.c 2009-03-05 23:01:47 UTC (rev 6716) @@ -310,6 +310,12 @@ } } +static void mux_chr_send_event(MuxDriver *d, int mux_nr, int event) +{ + if (d->chr_event[mux_nr]) + d->chr_event[mux_nr](d->ext_opaque[mux_nr], event); +} + static int mux_proc_byte(CharDriverState *chr, MuxDriver *d, int ch) { if (d->term_got_escape) { @@ -341,9 +347,11 @@ break; case 'c': /* Switch to the next registered device */ + mux_chr_send_event(d, chr->focus, CHR_EVENT_MUX_OUT); chr->focus++; if (chr->focus >= d->mux_cnt) chr->focus = 0; + mux_chr_send_event(d, chr->focus, CHR_EVENT_MUX_IN); break; case 't': term_timestamps = !term_timestamps; @@ -413,8 +421,7 @@ /* Send the event to all registered listeners */ for (i = 0; i < d->mux_cnt; i++) - if (d->chr_event[i]) - d->chr_event[i](d->ext_opaque[i], event); + mux_chr_send_event(d, i, event); } static void mux_chr_update_read_handler(CharDriverState *chr) Modified: trunk/qemu-char.h =================================================================== --- trunk/qemu-char.h 2009-03-05 23:01:42 UTC (rev 6715) +++ trunk/qemu-char.h 2009-03-05 23:01:47 UTC (rev 6716) @@ -6,9 +6,11 @@ /* character device */ -#define CHR_EVENT_BREAK 0 /* serial break char */ -#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */ -#define CHR_EVENT_RESET 2 /* new connection established */ +#define CHR_EVENT_BREAK 0 /* serial break char */ +#define CHR_EVENT_FOCUS 1 /* focus to this terminal (modal input needed) */ +#define CHR_EVENT_RESET 2 /* new connection established */ +#define CHR_EVENT_MUX_IN 3 /* mux-focus was set to this terminal */ +#define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */ #define CHR_IOCTL_SERIAL_SET_PARAMS 1 Modified: trunk/readline.c =================================================================== --- trunk/readline.c 2009-03-05 23:01:42 UTC (rev 6715) +++ trunk/readline.c 2009-03-05 23:01:47 UTC (rev 6716) @@ -444,6 +444,11 @@ rs->readline_func = readline_func; rs->readline_opaque = opaque; rs->read_password = read_password; + readline_restart(rs); +} + +void readline_restart(ReadLineState *rs) +{ rs->cmd_buf_index = 0; rs->cmd_buf_size = 0; } Modified: trunk/readline.h =================================================================== --- trunk/readline.h 2009-03-05 23:01:42 UTC (rev 6715) +++ trunk/readline.h 2009-03-05 23:01:47 UTC (rev 6716) @@ -46,6 +46,7 @@ void readline_start(ReadLineState *rs, const char *prompt, int read_password, ReadLineFunc *readline_func, void *opaque); +void readline_restart(ReadLineState *rs); void readline_show_prompt(ReadLineState *rs); ReadLineState *readline_init(Monitor *mon,