aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Penyaev <r.peniaev@gmail.com>2025-02-26 08:59:11 +0100
committerMarc-André Lureau <marcandre.lureau@redhat.com>2025-03-05 09:34:14 +0400
commita97ef3624437c5a5fbc8bd45e2a206d10ca840be (patch)
tree693f0b8b7f1eb500dc98d9df119c520aa91247d8
parent1a0fd7838a9dddf91241bc9faa471dc9dec04329 (diff)
downloadqemu-a97ef3624437c5a5fbc8bd45e2a206d10ca840be.zip
qemu-a97ef3624437c5a5fbc8bd45e2a206d10ca840be.tar.gz
qemu-a97ef3624437c5a5fbc8bd45e2a206d10ca840be.tar.bz2
ui/console-vc: implement DCH (delete) and ICH (insert) commands
This patch implements DCH (delete character) and ICH (insert character) commands. DCH - Delete Character: "As characters are deleted, the remaining characters between the cursor and right margin move to the left. Character attributes move with the characters. The terminal adds blank spaces with no visual character attributes at the right margin. DCH has no effect outside the scrolling margins" [1]. ICH - Insert Character: "The ICH sequence inserts Pn blank characters with the normal character attribute. The cursor remains at the beginning of the blank characters. Text between the cursor and right margin moves to the right. Characters scrolled past the right margin are lost. ICH has no effect outside the scrolling margins" [2]. Without these commands console is barely usable. [1] https://vt100.net/docs/vt510-rm/DCH.html [1] https://vt100.net/docs/vt510-rm/ICH.html Signed-off-by: Roman Penyaev <r.peniaev@gmail.com> Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com> Cc: qemu-devel@nongnu.org Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20250226075913.353676-6-r.peniaev@gmail.com>
-rw-r--r--ui/console-vc.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/ui/console-vc.c b/ui/console-vc.c
index 522adc2..df13415 100644
--- a/ui/console-vc.c
+++ b/ui/console-vc.c
@@ -646,6 +646,88 @@ static void vc_set_cursor(VCChardev *vc, int x, int y)
}
/**
+ * vc_csi_P() - (DCH) deletes one or more characters from the cursor
+ * position to the right. As characters are deleted, the remaining
+ * characters between the cursor and right margin move to the
+ * left. Character attributes move with the characters.
+ */
+static void vc_csi_P(struct VCChardev *vc, unsigned int nr)
+{
+ QemuTextConsole *s = vc->console;
+ TextCell *c1, *c2;
+ unsigned int x1, x2, y;
+ unsigned int end, len;
+
+ if (!nr) {
+ nr = 1;
+ }
+ if (nr > s->width - s->x) {
+ nr = s->width - s->x;
+ if (!nr) {
+ return;
+ }
+ }
+
+ x1 = s->x;
+ x2 = s->x + nr;
+ len = s->width - x2;
+ if (len) {
+ y = (s->y_base + s->y) % s->total_height;
+ c1 = &s->cells[y * s->width + x1];
+ c2 = &s->cells[y * s->width + x2];
+ memmove(c1, c2, len * sizeof(*c1));
+ for (end = x1 + len; x1 < end; x1++) {
+ vc_update_xy(vc, x1, s->y);
+ }
+ }
+ /* Clear the rest */
+ for (; x1 < s->width; x1++) {
+ vc_clear_xy(vc, x1, s->y);
+ }
+}
+
+/**
+ * vc_csi_at() - (ICH) inserts `nr` blank characters with the default
+ * character attribute. The cursor remains at the beginning of the
+ * blank characters. Text between the cursor and right margin moves to
+ * the right. Characters scrolled past the right margin are lost.
+ */
+static void vc_csi_at(struct VCChardev *vc, unsigned int nr)
+{
+ QemuTextConsole *s = vc->console;
+ TextCell *c1, *c2;
+ unsigned int x1, x2, y;
+ unsigned int end, len;
+
+ if (!nr) {
+ nr = 1;
+ }
+ if (nr > s->width - s->x) {
+ nr = s->width - s->x;
+ if (!nr) {
+ return;
+ }
+ }
+
+ x1 = s->x + nr;
+ x2 = s->x;
+ len = s->width - x1;
+ if (len) {
+ y = (s->y_base + s->y) % s->total_height;
+ c1 = &s->cells[y * s->width + x1];
+ c2 = &s->cells[y * s->width + x2];
+ memmove(c1, c2, len * sizeof(*c1));
+ for (end = x1 + len; x1 < end; x1++) {
+ vc_update_xy(vc, x1, s->y);
+ }
+ }
+ /* Insert blanks */
+ for (x1 = s->x; x1 < s->x + nr; x1++) {
+ vc_clear_xy(vc, x1, s->y);
+ }
+}
+
+/**
* vc_save_cursor() - saves cursor position and character attributes.
*/
static void vc_save_cursor(VCChardev *vc)
@@ -847,6 +929,9 @@ static void vc_putchar(VCChardev *vc, int ch)
break;
}
break;
+ case 'P':
+ vc_csi_P(vc, vc->esc_params[0]);
+ break;
case 'm':
vc_handle_escape(vc);
break;
@@ -870,6 +955,9 @@ static void vc_putchar(VCChardev *vc, int ch)
case 'u':
vc_restore_cursor(vc);
break;
+ case '@':
+ vc_csi_at(vc, vc->esc_params[0]);
+ break;
default:
trace_console_putchar_unhandled(ch);
break;