ui/console-vc: extract vt100_keysym() from qemu_text_console_handle_keysym()
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. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Marc-André Lureau committed
Feb 19, 2026 at 22:36 UTC
c81db697a494b0cc2e9950415aaa730daceb6723
1 file changed
+18
-11
ui/console-vc.c
+18
-11
@@ -331,24 +331,25 @@ static void vt100_write(QemuVT100 *vt, const void *buf, size_t len)
331
vt->out_flush(vt);
332
}
333
334
-/* called when an ascii key is pressed */
335
-void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym)
334
+static int vt100_input(QemuVT100 *vt, const uint8_t *buf, int len);
335
+
336
+static void vt100_keysym(QemuVT100 *vt, int keysym)
337
{
338
uint8_t buf[16], *q;
339
int c;
340
341
switch(keysym) {
342
case QEMU_KEY_CTRL_UP:
342
- vt100_scroll(&s->vt, -1);
343
+ vt100_scroll(vt, -1);
344
break;
345
case QEMU_KEY_CTRL_DOWN:
345
- vt100_scroll(&s->vt, 1);
346
+ vt100_scroll(vt, 1);
347
break;
348
case QEMU_KEY_CTRL_PAGEUP:
348
- vt100_scroll(&s->vt, -10);
349
+ vt100_scroll(vt, -10);
350
break;
351
case QEMU_KEY_CTRL_PAGEDOWN:
351
- vt100_scroll(&s->vt, 10);
352
+ vt100_scroll(vt, 10);
353
break;
354
default:
355
/* convert the QEMU keysym to VT100 key string */
@@ -365,18 +366,24 @@ void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym)
366
*q++ = '\033';
367
*q++ = '[';
368
*q++ = keysym & 0xff;
368
- } else if (s->vt.echo && (keysym == '\r' || keysym == '\n')) {
369
- qemu_chr_write(s->chr, (uint8_t *)"\r", 1, true);
369
+ } else if (vt->echo && (keysym == '\r' || keysym == '\n')) {
370
+ vt100_input(vt, (uint8_t *)"\r", 1);
371
*q++ = '\n';
372
} else {
373
*q++ = keysym;
374
}
374
- if (s->vt.echo) {
375
- qemu_chr_write(s->chr, buf, q - buf, true);
375
+ if (vt->echo) {
376
+ vt100_input(vt, buf, q - buf);
377
}
377
- vt100_write(&s->vt, buf, q - buf);
378
+ vt100_write(vt, buf, q - buf);
379
break;
380
}
381
+
382
+}
383
+/* called when an ascii key is pressed */
384
+void qemu_text_console_handle_keysym(QemuTextConsole *s, int keysym)
385
+{
386
+ vt100_keysym(&s->vt, keysym);
387
}
388
389
static void text_console_update(void *opaque, console_ch_t *chardata)