Move the keysym handling logic out of qemu_text_console_handle_keysym()
into a new vt100_keysym() helper that operates on QemuVT100 directly,
continuing the effort to decouple the VT100 layer from the console layer.
The echo path is updated to call vt100_input() instead of
qemu_chr_write(), since the function no longer has direct access
to the chardev.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
ui/console-vc.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/ui/console-vc.c b/ui/console-vc.c
index 3ef492c2d4c..dcd6445a1c3 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -326,24 +326,25 @@ static void vt100_write(QemuVT100 *vt, const void *buf, size_t len)
vt->out_flush(vt);
}
-/* called when an ascii key is pressed */
-void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym)
+static int vt100_input(QemuVT100 *vt, const uint8_t *buf, int len);
+
+static void vt100_keysym(QemuVT100 *vt, int keysym)
{
uint8_t buf[16], *q;
int c;
switch(keysym) {
case QEMU_KEY_CTRL_UP:
- vt100_scroll(&s->vt, -1);
+ vt100_scroll(vt, -1);
break;
case QEMU_KEY_CTRL_DOWN:
- vt100_scroll(&s->vt, 1);
+ vt100_scroll(vt, 1);
break;
case QEMU_KEY_CTRL_PAGEUP:
- vt100_scroll(&s->vt, -10);
+ vt100_scroll(vt, -10);
break;
case QEMU_KEY_CTRL_PAGEDOWN:
- vt100_scroll(&s->vt, 10);
+ vt100_scroll(vt, 10);
break;
default:
/* convert the QEMU keysym to VT100 key string */
@@ -360,18 +361,24 @@ void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym)
*q++ = '\033';
*q++ = '[';
*q++ = keysym & 0xff;
- } else if (s->vt.echo && (keysym == '\r' || keysym == '\n')) {
- qemu_chr_write(s->chr, (uint8_t *)"\r", 1, true);
+ } else if (vt->echo && (keysym == '\r' || keysym == '\n')) {
+ vt100_input(vt, (uint8_t *)"\r", 1);
*q++ = '\n';
} else {
*q++ = keysym;
}
- if (s->vt.echo) {
- qemu_chr_write(s->chr, buf, q - buf, true);
+ if (vt->echo) {
+ vt100_input(vt, buf, q - buf);
}
- vt100_write(&s->vt, buf, q - buf);
+ vt100_write(vt, buf, q - buf);
break;
}
+
+}
+/* called when an ascii key is pressed */
+void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym)
+{
+ vt100_keysym(&s->vt, keysym);
}
static void text_console_update(void *opaque, console_ch_t *chardata)
--
2.53.0