[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 17/19] monitor: Improve mux'ed console experience
From: |
Jan Kiszka |
Subject: |
[Qemu-devel] [PATCH v2 17/19] monitor: Improve mux'ed console experience |
Date: |
Sat, 21 Feb 2009 19:29:17 +0100 |
User-agent: |
StGIT/0.14.2 |
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 <address@hidden>
---
monitor.c | 27 ++++++++++++++++++++++-----
qemu-char.c | 11 +++++++++--
qemu-char.h | 8 +++++---
readline.c | 5 +++++
readline.h | 1 +
5 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/monitor.c b/monitor.c
index ba0e9a8..7cae863 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2887,12 +2887,27 @@ static void monitor_event(void *opaque, int event)
{
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;
+
+ case CHR_EVENT_MUX_OUT:
+ if (mon->suspend_cnt == 0)
+ monitor_printf(mon, "\n");
+ monitor_flush(mon);
+ monitor_suspend(mon);
+ break;
- monitor_printf(mon, "QEMU %s monitor - type 'help' for more information\n",
- QEMU_VERSION);
- readline_show_prompt(mon->rs);
+ 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)
@@ -2909,6 +2924,8 @@ void monitor_init(CharDriverState *chr, int flags)
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);
diff --git a/qemu-char.c b/qemu-char.c
index f815646..8c5544c 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -310,6 +310,12 @@ static void mux_print_help(CharDriverState *chr)
}
}
+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 @@ static int mux_proc_byte(CharDriverState *chr, MuxDriver
*d, int ch)
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 @@ static void mux_chr_event(void *opaque, int event)
/* 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)
diff --git a/qemu-char.h b/qemu-char.h
index e5ad45c..e1aa8db 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -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
diff --git a/readline.c b/readline.c
index 1868b10..9c4b68b 100644
--- a/readline.c
+++ b/readline.c
@@ -444,6 +444,11 @@ void readline_start(ReadLineState *rs, const char *prompt,
int read_password,
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;
}
diff --git a/readline.h b/readline.h
index fcf0f33..fc9806e 100644
--- a/readline.h
+++ b/readline.h
@@ -46,6 +46,7 @@ void readline_handle_byte(ReadLineState *rs, int ch);
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,
- [Qemu-devel] [PATCH v2 07/19] monitor: Report encrypted disks in snapshot mode, (continued)
- [Qemu-devel] [PATCH v2 07/19] monitor: Report encrypted disks in snapshot mode, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 14/19] monitor: Drop banner hiding, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 11/19] monitor: Rework modal password input, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 19/19] monitor: Pass-through for gdbstub, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 13/19] monitor: Rework terminal management, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 10/19] monitor: Break out readline_show_prompt, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 16/19] monitor: Decouple terminals, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 18/19] monitor: Introduce MONITOR_USE_READLINE flag, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 15/19] monitor: Introduce ReadLineState, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 12/19] monitor: Rework API, Jan Kiszka, 2009/02/21
- [Qemu-devel] [PATCH v2 17/19] monitor: Improve mux'ed console experience,
Jan Kiszka <=
- Re: [Qemu-devel] [PATCH v2 00/19] monitor rework, Anthony Liguori, 2009/02/27