From patchwork Sun Feb 23 14:53:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13987060 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1077C021B2 for ; Sun, 23 Feb 2025 14:54:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmDNF-0007pr-VT; Sun, 23 Feb 2025 09:54:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmDN6-0007oM-Nm for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:21 -0500 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmDN4-0007df-G6 for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:20 -0500 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5dedae49c63so6555801a12.0 for ; Sun, 23 Feb 2025 06:54:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740322456; x=1740927256; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EISobMCtsGJwgBBoRUyUGsapTk7Zv2HzSGY51pLZdkY=; b=YQHuYNA8qqmBubBupxF56G7cxiPO2JipK3HTAY8TJ4lANUFetuCF+EEBu1+f54J+rn lyNefSXJ9kkOI9Sd/Ev8u9p7/2i6nE2otoSa/lzHCrh3bATdaPckmjhCOR1gkAg/a+Tw gbJLFubWVLCXRO+5qlv1u7rJOCu9fb5pzj1d5x0GWgMghfQZBllYFPSDyqroYyREhqQw Lm+lz6q/jHZtyrReKJ/gDFtWPQnDewcT1lF/+Fww892Tg3w/mO5p/lgwPvwt1mMsOZcY 8k9gLJYlrLgObfE02vT6lsMhDYZ1n9+N88F+1CqK7FYhhmgp+fmPaJIAwzHV8lpXzR7U bgYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740322456; x=1740927256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EISobMCtsGJwgBBoRUyUGsapTk7Zv2HzSGY51pLZdkY=; b=ELoSitRWpww77kiQCCwuSUqE+cBwz3PGriZPw8G6dZyOEbkECmwaydZndnMPaUuE/G Dw8nNeEAJzGJUpzsqGC0KEMYQKdBAwqSXs2H7Gdaukv5RcU982f9uP1O7JBry6732YSD mxhMRGCJZ/uj7ZLVBMqP+pG3FE1TCoA7QgIxK6BnkJKxQ/DXyArXZHCab8Q5rmSoBJZ2 /+W6rWfbnEiN5foXb70qmuTepmOhpUfgaWBwYRugLAOS2XVnPSgUj/RKKfz9oY8VBTif 6hDDJHU7O+oMKexXg6VJ+k5EOUNKOAT8hA3ZV95kPWVJIQ8HSWUekP7qw2TNmj9Z6Bbb VXQA== X-Forwarded-Encrypted: i=1; AJvYcCVULb2w0M/sNVcKpB7Hjy/WFHkM8yjEI1RZ4ldN+Kaoy3QQkAwiIv1TeTnAEW69LycQ6/VAABXKGs/2@nongnu.org X-Gm-Message-State: AOJu0YwbEm6+mh/i7M2cNy5Uc3zO1V63vWJ3xUHuJqLpaoy/83QiSyaD c904jAJI5lDRbFG1rdXmwBWeoQM07s4ofYfWwFR0DxPRVF2hUpKn X-Gm-Gg: ASbGncuJzbPtMu9iNQy5hd1iNjeOEImQqHvpwqcmhZCaknD4InzC0rAt0y1um+1UhvB 24VyBO5TcgvGBdi2BBnjZvw8ZJFFM0cgJGxcbUHHoaGLbjPSMZLbQaJ5aPR4CHOHHoBFOO2KKTW MvDGEQa5/Nq1drhvDfKMCoMY2S5L1Oca+laYqwC7zO2HvmLJBKA/8l8lqhYKYOVyaxq/XW7wZ4Q Z0dgE10XeQtmSvR1tZQnUWmSCMq0toNsjECe2Fzb0l2ZgAybRpkHZI5sZ3YveUB5ZuIsgHCMS/Q kZqhesz9Xbeuu1jf0ikMRXTsPkC840gSg4M= X-Google-Smtp-Source: AGHT+IGcMob6w5BxKrpNJHfXRL/y4UXtRZkCdAQJlM3VLLHNm1cPdzRPc9Ea0ADL+56bguabH3wo4g== X-Received: by 2002:a05:6402:430f:b0:5e0:4710:5f47 with SMTP id 4fb4d7f45d1cf-5e0b7243e16mr9487930a12.23.1740322455481; Sun, 23 Feb 2025 06:54:15 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:1283:abda:b08f:72e4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e0a0310f66sm6431580a12.81.2025.02.23.06.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2025 06:54:15 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH 1/5] ui/console-vc: introduce parsing of the 'ESC ( ' sequence Date: Sun, 23 Feb 2025 15:53:58 +0100 Message-ID: <20250223145407.259924-2-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250223145407.259924-1-r.peniaev@gmail.com> References: <20250223145407.259924-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=r.peniaev@gmail.com; helo=mail-ed1-x52d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This change introduces parsing of the 'ESC ( ' sequence, which is supposed to change character set [1]. In the QEMU case, the introduced parsing logic does not actually change the character set, but simply parses the sequence and does not let output of a tool to be corrupted with leftovers: `top` sends 'ESC ( B', so if character sequence is not parsed correctly, chracter 'B' appears in the output: Btop - 11:08:42 up 5 min, 1 user, load average: 0BB Tasks:B 158 Btotal,B 1 Brunning,B 157 Bsleeping,B 0 BsBB %Cpu(s):B 0.0 Bus,B 0.0 Bsy,B 0.0 Bni,B 99.8 Bid,B 0.2 BB MiB Mem :B 7955.6 Btotal,B 7778.6 Bfree,B 79.6 BB MiB Swap:B 0.0 Btotal,B 0.0 Bfree,B 0.0 BB PID USER PR NI VIRT RES SHR S B B 735 root 20 0 9328 3540 3152 R B B 1 root 20 0 20084 10904 8404 S B B 2 root 20 0 0 0 0 S B [1] https://vt100.net/docs/vt100-ug/chapter3.html#SCS Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org --- ui/console-vc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ui/console-vc.c b/ui/console-vc.c index fe20579832a5..90ff0ffda8c5 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -42,6 +42,8 @@ enum TTYState { TTY_STATE_NORM, TTY_STATE_ESC, TTY_STATE_CSI, + TTY_STATE_G0, + TTY_STATE_G1, }; typedef struct QemuTextConsole { @@ -694,6 +696,10 @@ static void vc_putchar(VCChardev *vc, int ch) vc->esc_params[i] = 0; vc->nb_esc_params = 0; vc->state = TTY_STATE_CSI; + } else if (ch == '(') { + vc->state = TTY_STATE_G0; + } else if (ch == ')') { + vc->state = TTY_STATE_G1; } else { vc->state = TTY_STATE_NORM; } @@ -844,6 +850,16 @@ static void vc_putchar(VCChardev *vc, int ch) } break; } + break; + case TTY_STATE_G0: /* set character sets */ + case TTY_STATE_G1: /* set character sets */ + switch (ch) { + case 'B': + /* Latin-1 map */ + break; + } + vc->state = TTY_STATE_NORM; + break; } } From patchwork Sun Feb 23 14:53:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13987063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF9FAC021B3 for ; Sun, 23 Feb 2025 14:55:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmDNG-0007pu-0t; Sun, 23 Feb 2025 09:54:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmDN6-0007oL-NP for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:21 -0500 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmDN4-0007dk-Og for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:20 -0500 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5deb1266031so6607479a12.2 for ; Sun, 23 Feb 2025 06:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740322457; x=1740927257; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NRKO4/Lf3S1y2z89MfhWfqnGHofF5YlWQGE0xWq6QzI=; b=DuJPee2o7YXf9CYD9OztP//HkKS2Oy2t61bp7SMcBIfNVr/SNtjmoXbzSR9bzLBa5d k1R1q9R22opEp4ink9uNqjgLWtK0VUR+YfQhJE9RKQpLtsIqrlyN8j336ouCpVMJ5xLN eeWElNiYvhks7PLAmxnMeNCwSDGEa/hsyznxH+Flsof77/57iXWXH2REhQO0U2d3M3Iu 4KQDyVShBL5/amhmMv5CVjVxVsWmpFHlr/nb2Dir2FbvsZjoPeyXprABD1+/VOJn/dGW QBAk16fyeBDo+Fx6cvW3yRfHrxp9qHrJRk/PTvS7ErpDUGSh5lT7+wBxl6bKKR5JTI65 xDCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740322457; x=1740927257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NRKO4/Lf3S1y2z89MfhWfqnGHofF5YlWQGE0xWq6QzI=; b=jpL+S6eQJb5jWpogiggthXUpcCnKAjK7xwUrCIuXMflzOt9ObyYZQW+C9jkdcq16hc 70ecoxqNvilD22hi4Z9R+iExvIIGenE3tw7fH3ws6e6U3YcX3RgvVL8MlTfmBdlXk+nL kR9emk4yM0PCwp+eJ8n6p/xvTWUO5FGJs8KjgU/je/Yni6vdth25kiyEf8CZZ1K8sHh+ 5H4iBhQC8uzWRcvlVAdjPEAU8sNvbvOnvY6Ew+mSlnbwsMI/GuFi5ybtPPRhFE+ZRBvB axYMgjeMOE4bdjZBxnIPRD35jlhQjM3tC3E1nRMh26ZFyQYXx4hv1egF/ZVouL+PuRP5 cUYQ== X-Forwarded-Encrypted: i=1; AJvYcCVIDlorI1sQp03WnZbmuuznDN20Yt/RjiCWswMhTAxU++WwYBM1GK+juIOR5l/gf0Kl0dEbC/ek5bSU@nongnu.org X-Gm-Message-State: AOJu0Yx74e+i7xzjI64jvWRfF9bR5hmKkB3eAGahRZo7DAum47CkGA2E 0PrrDCvXB9wOe0WcsOiAGufqmP0PtpV/nKaRN/QCY8U7iFGPoZUC X-Gm-Gg: ASbGncuXD3KzmTo40B/gIcIOsvBm6OqyqGmcVMr0mdPoQ5WwU4QD1CgmYFctHaZawsF 4XNjuj626zS12I057i4SydDo2YtkCtotwNcWM7DGz6KBWECgO10Ce37a7cUG7sTmWPKXPazFd5n mm+BhzXLwnMoBXuLqQDCezCJUHh1swRGcrjjOvOMGj8G1oWDPH61FHQVHq+nuIVMubupGhnXIBx wLk2nhJepFRLBQ5Dg5f+3e1Xre+JOgqe0q+aLsdlCBRVVIUUITtinitkwR216GljCxVdHQoefIR Qglt+DV11dbswrBTy7OSPZSNNQRJCrfWQLE= X-Google-Smtp-Source: AGHT+IFDp3HbjbeHo960coxX2B1bxb91Moua6uoF462sA9UDbwkYBn9xXTgpTnUkk662WlpQz6+mvg== X-Received: by 2002:a05:6402:540c:b0:5e0:7d9b:b15d with SMTP id 4fb4d7f45d1cf-5e0b70e9cc6mr8530759a12.9.1740322457107; Sun, 23 Feb 2025 06:54:17 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:1283:abda:b08f:72e4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e0a0310f66sm6431580a12.81.2025.02.23.06.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2025 06:54:15 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH 2/5] ui/console-vc: report to the application instead of screen rendering Date: Sun, 23 Feb 2025 15:53:59 +0100 Message-ID: <20250223145407.259924-3-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250223145407.259924-1-r.peniaev@gmail.com> References: <20250223145407.259924-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::533; envelope-from=r.peniaev@gmail.com; helo=mail-ed1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Terminal Device Status Report (DSR) [1] should be sent to an application, not rendered to the screen. This patch fixes rendering of terminal report, which appears only on the graphical screen of the terminal (console "vc") and can be reproduced by the following command: echo -en '\e[6n'; IFS='[;' read -sdR _ row col; echo $row:$col Command requests cursor position and waits for terminal response, but instead, the response is rendered to the graphical screen and never sent to an application. Why bother? Busybox shell (ash) in Alpine distribution requests cursor position on each shell prompt (once is pressed), which makes a prompt on a graphical screen corrupted with repeating Cursor Position Report (CPR) [2]: [root@alpine ~]# \033[57;1R] Which is very annoying and incorrect. [1] https://vt100.net/docs/vt100-ug/chapter3.html#DSR [2] https://vt100.net/docs/vt100-ug/chapter3.html#CPR Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org --- ui/console-vc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ui/console-vc.c b/ui/console-vc.c index 90ff0ffda8c5..d512f57e10a9 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -617,10 +617,9 @@ static void vc_put_one(VCChardev *vc, int ch) static void vc_respond_str(VCChardev *vc, const char *buf) { - while (*buf) { - vc_put_one(vc, *buf); - buf++; - } + QemuTextConsole *s = vc->console; + + qemu_chr_be_write(s->chr, (const uint8_t *)buf, strlen(buf)); } /* set cursor, checking bounds */ From patchwork Sun Feb 23 14:54:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13987059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3614C021B6 for ; Sun, 23 Feb 2025 14:54:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmDNC-0007p6-6i; Sun, 23 Feb 2025 09:54:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmDN8-0007op-4G for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:22 -0500 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmDN5-0007dp-Ub for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:21 -0500 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-5e0505275b7so5765757a12.3 for ; Sun, 23 Feb 2025 06:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740322458; x=1740927258; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ARVfbAZthN6G0J8zifHQamYji2miOgYkQ6/AWMTqiyg=; b=br6+1qnOBzCVBaDpx7Y765uyYKQusDdKeM7HcdqUclRHN0tcyUvWNnAkor68TpYhFf qz2pev25/wBFVugJBG7Be2CWgrhN+bgtCh/IDjaZkKeIHWcqOiWZkffedM8IakYvaRL7 dgFxyVsra3UvJ31mtbsd3XUu64fKmgj6BJ1bLaAJDybOXdpD7wJj7TWcFMnNJGAc3rcQ 74fs6jFLPQ0M3LNwx8aHXT7WUnMdjqSjhvJ5lhphC7lUMB2W6vK2c0fvAVfxJ5+OqLV9 cTEKAiAFsrSuuN+Aloz5+8xa+w2GSnTF0r3HxD8MGkcPpR591++tvpn2z76lo9T9C7qA tDaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740322458; x=1740927258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ARVfbAZthN6G0J8zifHQamYji2miOgYkQ6/AWMTqiyg=; b=NJx5svq/rRQznWi7UOjCeVS8dNT06cJTRRbwSebqIN36i3RXdhG92cRX+W2TY9ubcS LEmCbkbNnx8PVQpkgMWuRGkly5vWCI/ox/wFhiRucEM5vZpIQyhPMjwsflshoFBsMrYa I9PkHDghPvH3BBbmN24p3u/neqY3DZPJoQq0YrkjlCdIdBnxNzqdmnZXSqqsr7TfmckN j9/nf+/iGD2uYorRdi7g8kByLCGW6jhiFWG6Z/c6hlCoa8Ri6Q/N6CR32HkH/o7VTRx1 iJQBiywg3v7wsvLqBSgKPcSUf4vrelJTimH18wM4ahXLJfgl49U+zOU7fmivifYMplDr iwrQ== X-Forwarded-Encrypted: i=1; AJvYcCWcPkvoZlCXuEAKNHG+VUghUhV/l6Q4xelo2/53ycQCrqob2CkEI21fFYDUUeCu/vQVrgpKPnpmsQFk@nongnu.org X-Gm-Message-State: AOJu0YwHmt9Zk+Mq/KLDEiKBqPMwFT+WDI5EH4ZykDzyjyupKWuyDeKr Emw5yIHMg/LyJSZRgV4+uaVfpA0KEEPZznGJxwjJXoi54mgk8Oy1 X-Gm-Gg: ASbGncvvNKS3fJtW5JBhcQOkSUzg8nPI/ricUmBlsaD3X41foy9gmKRWALUphzQ6OLn al6Zdk2O/ZcYo8gvmmmFyFUvwgKJwES1sDoUccKSJQFCmcPlBZ4YeDk+Gevat7d6YsofRKTwuWZ 60pM0wL1C58HvgcoTO/PJ+048nbkLdxRwJk+LPvOAChMxb9DLeEp2w70QW5vOxwoWi9B1FxrVtm LleY1jjIRul4nirrkS+2R2XFDzTkkVTfsEUYaakPoffzmsNAdiGBFZNfEmcEUNh4KIYntTlqaCz 7+wdn9OoJ9b9e9QPFFqWukf46egrHo7E8uA= X-Google-Smtp-Source: AGHT+IG3/1eo4iZ5JvQuxJiYR09fv9TtWpx2o5hxwcEmV4biPf1OO52DN6N4r8Pe3lS3zrA0CuLkZA== X-Received: by 2002:a05:6402:430c:b0:5da:d76:7b2e with SMTP id 4fb4d7f45d1cf-5e0b6fec4b4mr9947178a12.0.1740322457749; Sun, 23 Feb 2025 06:54:17 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:1283:abda:b08f:72e4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e0a0310f66sm6431580a12.81.2025.02.23.06.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2025 06:54:17 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH 3/5] ui/console-vc: report cursor position in the screen not in the scroll buffer Date: Sun, 23 Feb 2025 15:54:00 +0100 Message-ID: <20250223145407.259924-4-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250223145407.259924-1-r.peniaev@gmail.com> References: <20250223145407.259924-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=r.peniaev@gmail.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The format of the CSI cursor position report is `ESC[row;columnR`, where `row` is a row of a cursor in the screen, not in the scrollback buffer. What's the difference? Let's say the terminal screen has 24 lines, no matter how long the scrollback buffer may be, the last line is the 24th. For example the following command can be executed in xterm on the last screen line: $ echo -en '\e[6n'; IFS='[;' read -sdR _ row col; echo $row:$col 24:1 It shows the cursor position on the current screen and not relative to the backscroll buffer. Before this change the row number was always increasing for the QEMU VC and represents the cursor position relative to the backscroll buffer. Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org --- ui/console-vc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/console-vc.c b/ui/console-vc.c index d512f57e10a9..87f57f1c52c6 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -827,8 +827,7 @@ static void vc_putchar(VCChardev *vc, int ch) case 6: /* report cursor position */ response = g_strdup_printf("\033[%d;%dR", - (s->y_base + s->y) % s->total_height + 1, - s->x + 1); + s->y + 1, s->x + 1); vc_respond_str(vc, response); break; } From patchwork Sun Feb 23 14:54:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13987062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8BDFC021B2 for ; Sun, 23 Feb 2025 14:55:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmDNJ-0007r1-24; Sun, 23 Feb 2025 09:54:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmDNA-0007p3-Go for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:25 -0500 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmDN7-0007e3-5L for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:23 -0500 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5dec817f453so5934209a12.2 for ; Sun, 23 Feb 2025 06:54:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740322459; x=1740927259; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zN68A3m1xFZRBA4Wy0sLe9nvVRbka+7jawUW1pKYdX0=; b=MLZhqjw5ou7fc4Uh67QEIytHbBaBBjm82EaSm/R7xFMaEFNtD/hMlO0MSscYkVEE/5 07+ICkMRGBoa25fhR9WLOwAwyVb+fUW41RFFZTtJdIfy0A1loxk1pSPKLhfq/1/wNccW GQnxx6FTHI4bO6A8XVw2VdIr6wI4fxpnLodU5QYNMD1mw7NtH1F+xlTtvoW0yxBm1YFY 79MjlSyulZgLUGPz5wkx+fg5yp2YoOYLu+uIKdqhyeHYrZnnCVSH52qGA/YOn52ZAS/5 C2BazySfx1yZEcuTMuQQOlIaCGdVQUSd7Ud5RzvFjAPwq3/k1e/MwrBbKcKPoBQl7hM2 aq8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740322459; x=1740927259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zN68A3m1xFZRBA4Wy0sLe9nvVRbka+7jawUW1pKYdX0=; b=R8f9lFpAhRQKA4NeR3DARMdApw2Yj+Ti6EgUgMW0Tq+Qs3HJY9IGXICreBpaGVxz36 cFdhyoeCCIF/ReQbEOwm/ZzyuiXIlFv+37w2RgjIVanZp45vRiVSqLhuaacMBdJjFddk bvUMoWQ+WsbPniTcOw7bImp8woex8w2ZZL/PVu865OHw7w2HXOGmuyhlbXZ9EkPF5ZS0 XnTMeQV3nWojRuhLnIB+OPwObdFIykmqTjBriDrN3f8IUDnXmQXsgixJBjLfvuIcdFUO b2X8gOOmzUAT83giSB83kjP6GUtbI5XnkVZVkg7MRJuixBKDhNKNDpitzS3AAba1B2VB 12Qg== X-Forwarded-Encrypted: i=1; AJvYcCVOnYgf0cIupF42xJnD9iv4fxUD6KS0OL+JmeemYZduMvOQYCATzqK26xG/Hzgh2CIvgfVYXaft3eH1@nongnu.org X-Gm-Message-State: AOJu0Yy4+OixXCD82DoZBuZ2BDg8GTgqs/3xRLz4Z257T12hfbpWISrP yr2xjY3aOX5IFyPqnaKrCl9ZmOqpOC0og6RaXBemYJxTRn9SSBLzaV+B3A== X-Gm-Gg: ASbGncvw0jgz3p+jn2e6yYwvy8Q6pqWOV1o/DMM15sp5Igd3YFsFcMLHit6+FOshZnJ qHRzJJGQtFQXjjNBotzPCduIpCSnNZSjIepCllsc1zztbF+s+gLa5sFLG4c5a2zlBMMcCRJueZm YKnfmh2ebzL5AD9D8VTmVOT75hlHtGT+7I4PElcnmR7LqUs7tGpKwiJuJHSGmQ3J0AUThWhugin NUqw4PU78VSTeEmAnFDJvkwl1/+AHHqhqvKAtT1bdC6CWzkP2FTomrqlZO483KelUn9rn/gY3w6 Lb6vIYSwv9g8ptjD/8c4HsfNiRyWSx+RoeM= X-Google-Smtp-Source: AGHT+IEhb3P5TISi4jM0t2IF26KxuQA8/p+hDBNHm+mOujRQg3Cvb0SFOO+wwuXJ4WvQ7csUffnCFw== X-Received: by 2002:a05:6402:3488:b0:5e0:51a9:d425 with SMTP id 4fb4d7f45d1cf-5e0b724ecfcmr9455896a12.29.1740322459390; Sun, 23 Feb 2025 06:54:19 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:1283:abda:b08f:72e4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e0a0310f66sm6431580a12.81.2025.02.23.06.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2025 06:54:18 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH 4/5] ui/console-vc: add support for cursor DECSC and DECRC commands Date: Sun, 23 Feb 2025 15:54:01 +0100 Message-ID: <20250223145407.259924-5-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250223145407.259924-1-r.peniaev@gmail.com> References: <20250223145407.259924-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=r.peniaev@gmail.com; helo=mail-ed1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org There are aliases for save and restore cursor commands: * save cursor `ESC 7` (DEC Save Cursor [1], older VT100) `ESC [ s` (CSI Save Cursor, standard ANSI) * load cursor `ESC 8` (DEC Restore Cursor [2], older VT100) `ESC [ u` (CSI Restore Cursor, standard ANSI) This change introduces older DEC sequencies for compatibility with some scripts (for example [3]) and tools. This change also adds saving and restoring of character attributes, which is according to the VT spec [1][2] [1] https://vt100.net/docs/vt510-rm/DECSC.html [2] https://vt100.net/docs/vt510-rm/DECRC.html [3] https://wiki.archlinux.org/title/Working_with_the_serial_console#Resizing_a_terminal Signed-off-by: Roman Penyaev Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org --- ui/console-vc.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/ui/console-vc.c b/ui/console-vc.c index 87f57f1c52c6..522adc2806c8 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -90,6 +90,7 @@ struct VCChardev { int esc_params[MAX_ESC_PARAMS]; int nb_esc_params; TextAttributes t_attrib; /* currently active text attributes */ + TextAttributes t_attrib_saved; int x_saved, y_saved; }; typedef struct VCChardev VCChardev; @@ -644,6 +645,31 @@ static void vc_set_cursor(VCChardev *vc, int x, int y) s->y = y; } +/** + * vc_save_cursor() - saves cursor position and character attributes. + */ +static void vc_save_cursor(VCChardev *vc) +{ + QemuTextConsole *s = vc->console; + + vc->x_saved = s->x; + vc->y_saved = s->y; + vc->t_attrib_saved = vc->t_attrib; +} + +/** + * vc_restore_cursor() - restores cursor position and character + * attributes from saved state. + */ +static void vc_restore_cursor(VCChardev *vc) +{ + QemuTextConsole *s = vc->console; + + s->x = vc->x_saved; + s->y = vc->y_saved; + vc->t_attrib = vc->t_attrib_saved; +} + static void vc_putchar(VCChardev *vc, int ch) { QemuTextConsole *s = vc->console; @@ -699,6 +725,12 @@ static void vc_putchar(VCChardev *vc, int ch) vc->state = TTY_STATE_G0; } else if (ch == ')') { vc->state = TTY_STATE_G1; + } else if (ch == '7') { + vc_save_cursor(vc); + vc->state = TTY_STATE_NORM; + } else if (ch == '8') { + vc_restore_cursor(vc); + vc->state = TTY_STATE_NORM; } else { vc->state = TTY_STATE_NORM; } @@ -833,14 +865,10 @@ static void vc_putchar(VCChardev *vc, int ch) } break; case 's': - /* save cursor position */ - vc->x_saved = s->x; - vc->y_saved = s->y; + vc_save_cursor(vc); break; case 'u': - /* restore cursor position */ - s->x = vc->x_saved; - s->y = vc->y_saved; + vc_restore_cursor(vc); break; default: trace_console_putchar_unhandled(ch); From patchwork Sun Feb 23 14:54:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13987064 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6CE87C021B3 for ; Sun, 23 Feb 2025 14:55:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tmDNI-0007qm-HN; Sun, 23 Feb 2025 09:54:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tmDNA-0007p4-Gj for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:25 -0500 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tmDN8-0007eR-BF for qemu-devel@nongnu.org; Sun, 23 Feb 2025 09:54:23 -0500 Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5deb1266031so6607518a12.2 for ; Sun, 23 Feb 2025 06:54:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740322461; x=1740927261; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qlkiO7qYj5+41IEd2vHxj8OZTpyw2odXgSQfKCBV+pM=; b=fFPe9G28NzXhSrAWNPrlnc12+pZskXRzinLRmjhXWkVmzeGQbnHJqMND/ZcyZMxsZL rBaWjUs81WjFXbdp8iZ3a6qG/yOjCaU5si1s4+kp8HgqfWOMJ0psESBG3mM7TySChA1Y K5AC5AFJJHZ891QIBQLvrQ5Ml3xKOMAGnypHFYNJjwcmze7QDsiZL2Mqahi11bfTmISr dWJSdQ2yZD3SJJKPZpteP+ERQviOF3d8ExJy7yAKh6F0RRipa8dQt5J3iEbDuaDR3W5t 4yD9OxVA3m4+67a74JDwwfz10zgcWmSyv1M4ahTz2Exnl4Z6a0fiJmGlKKDGE4qwZ7Nt vyIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740322461; x=1740927261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qlkiO7qYj5+41IEd2vHxj8OZTpyw2odXgSQfKCBV+pM=; b=NaXR+7q/RftcfQ0Mq1qkym37BWe7sqXMGWhpfBOMGIAc8B+149cvlr/tstNdHSv/Ye c/Vej0GsuB4n4BEMqjAb66CkLt1IHKhKFhjvX6KnsGeYnx5OdV4nv6MoDsRYGl60biOF JEKkjpo3qNhvvfYXqMuHOYiHimXNrfSWHq4uNbtQAadFTxSrA5NCMLA8iXMJnA/6ioqK PPV0W9cM0/5p2Tvhwhlbv3p0HdKSTpBehpRauh3jBNVRUS5Nl6BOyYe4ScsLFHl3kCne CNDg66sa8rY5TumOZQ5ngz8Jki4aHMDRHbtKToatpLZczBHJD/lJeRxBR7hHNqQ4mwrl Z7Eg== X-Forwarded-Encrypted: i=1; AJvYcCXxs/T9pM8s+HFfGo7362GKifbqMfE3D7B18nmr7iB7ZAnzdcNx+m458oE1IrFc6xfOOYpmJPex0TGk@nongnu.org X-Gm-Message-State: AOJu0YzbD8t4rHQu6bMiaqJhqC5OdYWP0u7f9pc+mJEO/NGnmYRthWx9 29aNbgwAYwNfYhgiIf0B2N4x0mTYjmrDNrQBVZ2AdxZw0Ug2nh5osNn1gw== X-Gm-Gg: ASbGncslPawDE7dGftFwLXWROngLdpfx47MJ3SDpsAZ+BWXJYxaZ0G9r9I3CSyatIhj X3pJakUABiqTkXueaJntfVbd1OnDFTqNGFfWF6xiRNGXir10SGwnnZrHKdATZv9J1euA29qHGIy Lvy4MN/89P+wJpehPUh/VR0zxRLiISGm/BLBy0XjNB2qFAaGBlK8ihCd5+N6hod/FLkcaj/FEYB SaEq5Uq1otSQM8cubiNfUIVDWc//ftrwfvJWZdpvXrhQqCLh81iD9ms3pOL5B/B9ci2CrcoMkHy R1vMoS4gYnsnNaYv7XlIC8a7XM1sIPyJvzw= X-Google-Smtp-Source: AGHT+IGwlpGLJMymcQmKnHxvt+6dfornRgVDkEolcde+LA78oGI9KApPhqSzHOEfIdqH8yBzd6SKdA== X-Received: by 2002:a05:6402:3583:b0:5dc:cf9b:b048 with SMTP id 4fb4d7f45d1cf-5e0b70cb80bmr8898270a12.1.1740322460423; Sun, 23 Feb 2025 06:54:20 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:1283:abda:b08f:72e4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e0a0310f66sm6431580a12.81.2025.02.23.06.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2025 06:54:19 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH 5/5] ui/console-vc: implement DCH (delete) and ICH (insert) commands Date: Sun, 23 Feb 2025 15:54:02 +0100 Message-ID: <20250223145407.259924-6-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250223145407.259924-1-r.peniaev@gmail.com> References: <20250223145407.259924-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=r.peniaev@gmail.com; helo=mail-ed1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 Cc: "Marc-André Lureau" Cc: qemu-devel@nongnu.org --- ui/console-vc.c | 108 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 6 deletions(-) diff --git a/ui/console-vc.c b/ui/console-vc.c index 522adc2806c8..bc667897d1bc 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -598,21 +598,29 @@ static void vc_clear_xy(VCChardev *vc, int x, int y) vc_update_xy(vc, x, y); } -static void vc_put_one(VCChardev *vc, int ch) +static void vc_insert_xy(VCChardev *vc, int ch, int x, int y) { QemuTextConsole *s = vc->console; TextCell *c; int y1; + + y1 = (s->y_base + y) % s->total_height; + c = &s->cells[y1 * s->width + x]; + c->ch = ch; + c->t_attrib = vc->t_attrib; + vc_update_xy(vc, x, y); +} + +static void vc_put_one(VCChardev *vc, int ch) +{ + QemuTextConsole *s = vc->console; + if (s->x >= s->width) { /* line wrap */ s->x = 0; vc_put_lf(vc); } - y1 = (s->y_base + s->y) % s->total_height; - c = &s->cells[y1 * s->width + s->x]; - c->ch = ch; - c->t_attrib = vc->t_attrib; - vc_update_xy(vc, s->x, s->y); + vc_insert_xy(vc, ch, s->x, s->y); s->x++; } @@ -645,6 +653,88 @@ static void vc_set_cursor(VCChardev *vc, int x, int y) s->y = 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 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. + */ +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 spaces */ + for (x1 = s->x; x1 < s->x + nr; x1++) { + vc_insert_xy(vc, ' ', x1, s->y); + } +} + /** * vc_save_cursor() - saves cursor position and character attributes. */ @@ -847,6 +937,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 +963,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;