From patchwork Wed Feb 26 07:59:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13991686 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 AF5ECC021BC for ; Wed, 26 Feb 2025 08:00:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnCKE-0007PH-JQ; Wed, 26 Feb 2025 02:59: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 1tnCKA-0007IJ-Vy for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:23 -0500 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tnCK8-0007g3-Vd for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:22 -0500 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-aaec61d0f65so1305276366b.1 for ; Tue, 25 Feb 2025 23:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740556759; x=1741161559; 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=K5Dg4OvfqrvdOmvG2hbYK7yXIxN9LEUDWAVxjA+pLxk4z8+tXH9bkyQHm1qV5xL8t6 raaD6rcLBAZBBmuNEK6WWxjOi1T/4o/qT+22KbdcpvxlDPS9VcuhkeJZH8Es0HYeEoSx GuHN1v4O4e/LITIZkxACKugVuWHoX3uM5rGqrXMYmdIpMZuJxfGt269mtbdtdLNUDCdd np0T5LM9jQAY8FexRxY2Uv7X1je73Uz13zxFcZ6qehXyNAQNgj4ZNjp3+LiVNTlhWy6/ kqCUykYEJR4W2Ho4fUZqn+xmYfXjWGQPOt6nibWn4qMaI1zUQOT8r0/2vIPDXsuwvTnR 15eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740556759; x=1741161559; 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=OQWswkJ0jKON6TyrhhPPyUnsefz4+mSDY37sXXv2o/xbcjRuII2PlCkxG5+qk6NuBm 0HK4Nrx1ZdGuNwRD+03nG1+fheo6Stum9mf3W2/V2iCxq6ed/8MGgsKkp4wCbUJ8+6Dk ukOnyz0F+hIk4erwtzEDIPyQ7TUHxgWKvnWqtzNgM3H9yg3YU8CTSDhlJla+yeNDvcF3 B1l07fIkUrnZQhqry5t88iKPXWxwVcTLvBHF74mSAK1Bk6xV48x7VhnHt18Se5n4eBSG dYqnY6yC67OOx+AAXocBT1mjoz9rg0d5oEnduMqY6oxByHMPUZwigCg1ewFXli1iqbG3 F6oA== X-Forwarded-Encrypted: i=1; AJvYcCWdOuWsplHAo4gYWVbtMoXaGEmSqv3+iGBhVWYY4HJCB9jP8TPDIbPus6e56NHuCOSxMaaVPRWPqq0B@nongnu.org X-Gm-Message-State: AOJu0YyZnyt9R+Bhj/b9kqpvmg6s6j38cCOmJv2g5Su2Dcux16SXKrkF cM4zqqlhuOQMLcHv5mHSXAJ9W1AyNX119IScfm7gXejAq5E0RmoW X-Gm-Gg: ASbGnctU8z92Wv3NMIUUhymPdU/Z6coBDx0oYjTlkKLhFEwxYZxHizpToLctelE0e4p h58uKZDfW2nfZZn5glpGSNql42ASVk4FERqybMuvmt20B7Z4aPi9ncYKJjxlAqv2QUBs1rId22z daMmw5dwP3xDehXh1ZdSDPfrj3UDnz55AZCWgmXuZPyxyzIQq6g09oxzmWfxt/yrmUltFhdvDth WIuWhQs+C2qfjwrbq6Vry2NDzOT5K+26pgYVFtr/A21uUwHXCNcmzH0kezwzYuyGGFeR0iPr6fX 70xVfDbK0srqrik9NAHZJZ+oUVbG2ZlT9gQ= X-Google-Smtp-Source: AGHT+IHWUH++GE8qoFPI1YIgth4LbdXUIY7e/s3mqIulhuZtZcEt6D3YItDv9e5k4A7jfUTQVp9oXQ== X-Received: by 2002:a17:907:7f90:b0:ab7:bc17:b3a4 with SMTP id a640c23a62f3a-abed0e098a3mr808370866b.34.1740556759090; Tue, 25 Feb 2025 23:59:19 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:c48e:2efa:cdfc:e268]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abed2013355sm280107866b.113.2025.02.25.23.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 23:59:18 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH v2 1/5] ui/console-vc: introduce parsing of the 'ESC ( ' sequence Date: Wed, 26 Feb 2025 08:59:07 +0100 Message-ID: <20250226075913.353676-2-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250226075913.353676-1-r.peniaev@gmail.com> References: <20250226075913.353676-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=r.peniaev@gmail.com; helo=mail-ej1-x62a.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 Wed Feb 26 07:59:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13991712 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 E42F3C021B8 for ; Wed, 26 Feb 2025 08:01:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnCKD-0007MB-JL; Wed, 26 Feb 2025 02:59:25 -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 1tnCKB-0007IT-Dx for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:23 -0500 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tnCK9-0007g9-Gg for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:23 -0500 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-aaeec07b705so1081745166b.2 for ; Tue, 25 Feb 2025 23:59:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740556760; x=1741161560; 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=dSJ5Qdws0UG7tOHwHMA/CtMtB3b08dFPMK/T2yNcD94=; b=FJesK+VmL54mLyX1xasiCaovg52o95qOFSMEJHExRGwWO/PDIk6lmbiWJzcII6OQHg bX35qRPmI9a9Mc7rWUZLAMVUl0KIu/+nlIohdOolG6H5hNbbEONvomE0lI/pV6C3WNHA llGpHkmqHEkz4x2g2TsqMHNrSd9b33d6+0AWyKlrw5qSXyh25aWNgfwAvBpzFsDEVhFO ulQcwTFI3faPgOy/ws8kZYp0JAQbxOrTgjJjEOzI/aT9vagJPrH4M3bdNCciBQsGuRSy KqFYvb9cLhv8nxZurVupgzrsU5VVM8uog+LZgpv2VlQ1m4sgRxL9+F91JCqYi+Yj+rpx 7WGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740556760; x=1741161560; 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=dSJ5Qdws0UG7tOHwHMA/CtMtB3b08dFPMK/T2yNcD94=; b=v3Ize7VQ/+4947GsyAZzOEHIeQp2RSBFiNTE88uIVZod++mVofoBy8hgjJ9+RXOVB5 YIax7ZqwFlTHoR4lTOgcGLZ8fzXkiRgHyZXo5yI8JWKc+hawa0XtT3JWV92NFbwUroG5 fK7vtwPYKmKdAbM3o8td8qy9ZhfvIDcU0ICO7dFoGDKJdxnew3Ey7bgzJbgC4q5m61fS btOvQ96s1qxUXenQjXAmAp7XHeZKNJx8OMfTb4TgpRbP02FFKMS4DRdjCNMuk1CIpJHG Uz2yG8PRi65dxbmFo3g5xikLcutnB+UFky0H19FMDF/9vAhYUNq/rWoyXOiseJAgO81d 5/Dw== X-Forwarded-Encrypted: i=1; AJvYcCXLaWoHSXEYziFeb3B+mQFx1An7MKQTct02ChYnE+fm/RmuAy0K+nIgKfu4Kti+dY547g3TGaa6Hc2B@nongnu.org X-Gm-Message-State: AOJu0Ywynx2qXrr5r/2luQN6b8fKPkWb02JzSIFkxBANOnAR/er7gZYq 1JigalhjZo5ND3B6XUe/8Fig3akARQzkqcfaRe7vLz6iTNfGn2IhRmvm+w== X-Gm-Gg: ASbGncu1MV/vKFpRwRBUxfCCJNCTXkVymXLKcCIMmYx83ZMX5GK1yAfLC3NVk0/LBfs uS5BM1ts0JnmYGjlnOH+LWx2wiI4K/bxLtHq/PleX0QF4Xhnw4dPi0TxG+hK53SOtJBi2oRpHhj vrC9HyX4CCo02QTREaZu1gPqlY85M0iAMdkCntZ55ZGMOyhdP2jIsRrKrYVwol1qURJNHElh1wn BjApb/KNxuaVOzeGuIrmVY9OIG8C67EKEKKpaMn6w8TB127C8nOnz8SnS7IPiuVns0wthC2cwnM 5qth7SO+0ihH/j2slq2AnMUKnoEYUG2KV7I= X-Google-Smtp-Source: AGHT+IEeaMN92comtl+sPf3175ewhNSPKmK+znHdmzN+rV5Gp+RVIQ0u//9ED09/vnpJYbGWN5NtLg== X-Received: by 2002:a17:907:6d05:b0:aba:598b:dbde with SMTP id a640c23a62f3a-abc0d97e504mr2147887566b.8.1740556759709; Tue, 25 Feb 2025 23:59:19 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:c48e:2efa:cdfc:e268]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abed2013355sm280107866b.113.2025.02.25.23.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 23:59:19 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH v2 2/5] ui/console-vc: report to the application instead of screen rendering Date: Wed, 26 Feb 2025 08:59:08 +0100 Message-ID: <20250226075913.353676-3-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250226075913.353676-1-r.peniaev@gmail.com> References: <20250226075913.353676-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=r.peniaev@gmail.com; helo=mail-ej1-x634.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 appear 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 Wed Feb 26 07:59:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13991685 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 A9931C021B8 for ; Wed, 26 Feb 2025 08:00:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnCKG-0007Qu-0K; Wed, 26 Feb 2025 02:59:29 -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 1tnCKD-0007Ma-DD for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:25 -0500 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tnCKB-0007gn-63 for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:25 -0500 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-ab771575040so106658066b.1 for ; Tue, 25 Feb 2025 23:59:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740556761; x=1741161561; 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=g5OJbl6sTwlNMA3UCSgSkZcD6fLBqn2Q654CKc6NrlxaJIOScQn+RdLxY66Qp8f061 Ca3g4ZpnJzJD6zDwyKkdSC1pr4vQiWo9zC2qd4eQjtHq8LjiKyqszzT2SVy/YOFI6CTP ZS6oH0odED+aNvU9dSKV3N9Icex+6Lz81Kf4mqkAqcfH7LCeRiWz4KqqtrgpuWOxCSQQ YypQ7y5Yd+05+qvqOxrbY642CmoHdrpmISn54LG1QsjIoNUWmuIvTKbc4DEUszX2PCTP 7NZNZ8US/l8nqsf6UgRQsWynkER2X7mJ/aUkJfCgzPcdvrZSxFP3zepQ9kiyD6o7JYjQ rCMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740556761; x=1741161561; 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=INS19YqqpISL9SmOJ3xubBvZJw0NcWlQhjq5urQhzXXjGWzSgxBRyxXLtN1mB2MEMU vx/SCdh5L+a40vBozHLbqZNeJAs3PKKcV8RBLD4yrcrI7IEzucMxPbZvJbm4ufIZDfJN mdAOcDS6PsRcTUQYiNzJWFiEvG248l+KwvYOPm/8mwUsShqc2kTozSkeFvOfQVAB49nf uIPN4+UEtY1JuobbFPdKiuv25mC5GqI6yzlKdrQRQ+abENuvQNds5O7adUTzsg9CqVBQ T5yMpZt64waNsHHCwxPPBJwCQuSIUpCvdjfGiZk72qHZilrCgaRtYYCZkq7n0DJdX6LY 4kDw== X-Forwarded-Encrypted: i=1; AJvYcCXBVpPGyk5et1aNola15WJlvy+dlaUcr3TRdRRDeVnai5kxlqPK85DsNNG8B5XZu4J0GfyBswftdNly@nongnu.org X-Gm-Message-State: AOJu0YylKtxc5XGgtv1r6H7oi728a9ABZ/XwnC6RB7chsY6WP4QO8DBr xfua3RMCM7JTMGZ9xDBkFh9s9On+7ByjlF2tKffnTVYmp3gwOYGRLUI2DQ== X-Gm-Gg: ASbGncsmr4bGlapAcRzi3j6bSSzok7yxxcTaFus31jQY0BF09JmKkMH6x7/a4iah6Mb N7TZEGPvGa9GoWL1CXUzZxERlxeigP/mTTwk/xRSZQIGc4AkH8W8GsV43k6qSPpveDq6DQ5Kf4F /i8Yw2wGVFqMgd2C3fpFqnDEk82f7biMyDyeMpUetIu2IGW0OsRplOHzhz7DDUIHl89VJujQo7p eZRsPFV8+UmdV48C1Mn6HTPyawZzH8PQAVUOjnld9AW1SbnVqY8TYJ7xPQYcgvSPKYL0tIgzKzZ 85FH34GfittbODjCSFur/HsG/y7Qx0stmNA= X-Google-Smtp-Source: AGHT+IESuCS42A3aoL1h0RL0yFzUUnaSn2hH5S60F0GoJxuHORZJbS8s+nSzlpaAuDcnjY7pDnLryg== X-Received: by 2002:a17:906:3151:b0:ab6:504a:4c03 with SMTP id a640c23a62f3a-abc0b037859mr1551857866b.24.1740556761223; Tue, 25 Feb 2025 23:59:21 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:c48e:2efa:cdfc:e268]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abed2013355sm280107866b.113.2025.02.25.23.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 23:59:20 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH v2 3/5] ui/console-vc: report cursor position in the screen not in the scroll buffer Date: Wed, 26 Feb 2025 08:59:09 +0100 Message-ID: <20250226075913.353676-4-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250226075913.353676-1-r.peniaev@gmail.com> References: <20250226075913.353676-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=r.peniaev@gmail.com; helo=mail-ej1-x62a.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 Wed Feb 26 07:59:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13991684 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 34926C021B8 for ; Wed, 26 Feb 2025 07:59:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnCKG-0007Qv-0g; Wed, 26 Feb 2025 02:59:29 -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 1tnCKD-0007N4-Rz for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:25 -0500 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tnCKC-0007h0-0f for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:25 -0500 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-abbdc4a0b5aso116850266b.0 for ; Tue, 25 Feb 2025 23:59:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740556762; x=1741161562; 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=mb+Lc8pP9QiB/I/lCIje0dor1HXI/I2LsOt+x9cXS+GRbdSYJNvKaNKua7OXsF0xOm aqIdV24DbTuU3BjdbJGbt4OIUOyYK74sHelfxW8LX5Z3rVueZZ7p7bQ4t47rm5HoAnzM 9CuBS1VNiPhpwYwyK+7O3OVbwociJsB5aWgGLgHpV8nGHO6LYH4lIl/iH9EQt3BFqARP zQBufNmoRItCZk7ffJADyDS+8LZXMXTYnw4ob5nUwAwa8oOPMC0mnkRZ7nlSA1vGthqq kT5UVwjvDWfipVUNkTvfLITMp6IYxzEAX9usHp0ommD+Bz0SAgH887P7UuZVa6Nerqsa QOnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740556762; x=1741161562; 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=E9kG28w2+w8gD3VlEt1N61n7iv0z0BZ7TSR4U8UHInnT06ILM/Z0jeZGIFuxpVpczs gsXvHTNSodoXxn1ug3kwicHRj5owqufsANCpD9D+8qbf1ue6yv0/XB+DfGTzplz1n58T oiUqLHHkpZ8Jz1qOBnNvReM1cH8G4oZ8yErPghWd93yB2Q+HNHcoE8qjZJNMSu2JbDry nJyEzn9yOMFy0NFtXkmNcftS8tSN5QS8nHPOm7ThNi45e8HzzAZbca6ipOcOPOtOGUK0 wrL31OR5jVKUAFLekUIfQWMPpjTMjVzHYbuAEX+pZv3lkkIteUjZUvDrNK2HyjF+7S7f TLwg== X-Forwarded-Encrypted: i=1; AJvYcCVb2BVCWvhR1lyHDE5PXZ769AR0MnajzZxjx/B+r6l1EXzRxyX9xxQowVtYs7X79g3voiJYGm6I2yn+@nongnu.org X-Gm-Message-State: AOJu0YyOhCNAbYUhEyDQpY03oX7RFC4dJMqfeU4dmmqrFqZGi81fRVYT jyDywkH1FAcSn4wSrwXZ/7bVDblKIF3H9Jop8LMeWrC6fMyGcR00 X-Gm-Gg: ASbGncvb90SzdpTMMzv5a+HPgg6IEl0csFSlOgxwU4ZN7HMVnehdop/ijquzINP8WK6 DfUoR9nQ4Y5ihqI/zuobNCqf9PC71yPo4Dde+rOXKaHFdfD+4N4e6044iogxdCRL3qk3bgzBFeB LoKEqKd9Oa41667/ba8RVIEGdiDc5r4kKg8Ap5lbckYeOVat26kKykSVCT/cDVGy7iDADIn2JjN +Ycn4DTrPc+gYyABAzFBF2STQxFUaEpGr2y+y2o+1mu7x0py4EkcZpHFNu0gLBhLLSErdF0fWAY ZCb2zRYAXPFq2DJcNwSlhntWPJVmBRX111s= X-Google-Smtp-Source: AGHT+IG+PcTx2bjs3mr38WTm8CepdGFQI+yeyx9p4zbFCrUdjHnpkDj+Ezj7uh4E/ZAQKixRlA08Aw== X-Received: by 2002:a17:907:180a:b0:abb:b533:3e82 with SMTP id a640c23a62f3a-abbeded95ccmr2142470266b.20.1740556762016; Tue, 25 Feb 2025 23:59:22 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:c48e:2efa:cdfc:e268]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abed2013355sm280107866b.113.2025.02.25.23.59.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 23:59:21 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH v2 4/5] ui/console-vc: add support for cursor DECSC and DECRC commands Date: Wed, 26 Feb 2025 08:59:10 +0100 Message-ID: <20250226075913.353676-5-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250226075913.353676-1-r.peniaev@gmail.com> References: <20250226075913.353676-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=r.peniaev@gmail.com; helo=mail-ej1-x62d.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 Wed Feb 26 07:59:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Penyaev X-Patchwork-Id: 13991711 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 8CCEAC021B8 for ; Wed, 26 Feb 2025 08:00:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tnCKL-0007So-Bh; Wed, 26 Feb 2025 02:59: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 1tnCKE-0007QC-Vx for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:27 -0500 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tnCKC-0007hQ-MZ for qemu-devel@nongnu.org; Wed, 26 Feb 2025 02:59:26 -0500 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-abbdc4a0b5aso116855866b.0 for ; Tue, 25 Feb 2025 23:59:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740556763; x=1741161563; 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=R99e/0pJ92SgYpcF19F0TSmaPaY9J1HBgHMMR0nIINY=; b=Y7DcZ2okuCfSmIoUNNP5+g8o/eQP/sxyyuc+duwdBbGviepC9iBOx1u6mWoQWPAST3 tRRlRMvuWO6ykeRo3Acrotx6fNNjzKj7Shq6IAWy9Q0O0eCkbMLoCQqdzajEfhhka6id qALwRj/vGba5VrrqwWJgl2Hk9Vk3IeHWWmQY1KTkiPN0wp4dBShHPeKHhGQwRUtQjrnL cJmcjHKreVLZ4mzKG/EJ0zpB6O3jvrEuwQR8b9uYWMLd+l/yaKpv8jo/+CjsT5tE6auB NL6fceM417Y0h3+/AW5kFgiYGOwK+BjCZPdnNmaAYwnSTg1bIJcFw6vqH6ugNQTCbG6M +HMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740556763; x=1741161563; 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=R99e/0pJ92SgYpcF19F0TSmaPaY9J1HBgHMMR0nIINY=; b=O+Bn3c8Nf6QOqHtFbsHo32wc6tlGhTCXsEopuXEo/ZZQSPb8Yw2IoKib73UkaOAek8 GnNPjtFi7jusMTer8sySCzPwr3pWHkF4YKAjaeS1Iwt0Qlkdk1M4ZBE1zc8IlDm54o6l EbL2fAOSy5qZNIMkUFXBKiO/OgRKy/R2seN7Jb104QauPGsVHeqWqQeEEGXl9LKc+CF7 XlbCC/w4VpLgvZs84Ur8ySCkUnNSp9vxzYnQncsi8BSgCUBxCHgaGQYv42BYc6uoO7Nq QVlJkI2j6xtn2srpbUy7I/HcfL1QjwMLSsxN2eulXB7i46XaSLPxuU0X8DWq8czJYep4 drrQ== X-Forwarded-Encrypted: i=1; AJvYcCXydyKUMVkfsIvNM6KdqNyykSRm/pNTJPN3IJyLvwjaRi05nK17pmYxkSbYAkOTv0nYGu8KGEmiA6kI@nongnu.org X-Gm-Message-State: AOJu0YzQPfzjCyjTRzeLkVtJulXcZJAoCHLmi/SEbxk7sBa+GjVaQIFe jEX2VzYJQbdVG5MQf41Ebu4Us0Wc//unxrQFBM1bW3MwT6y2DlMX X-Gm-Gg: ASbGncscsh58ayaU8AeOuYTi64kPIcHWoitvIwCgcopXZx3ADxqAloIOC+fI9J3WF/+ gObCNmnbT6OsgZl9U89D+whYV+Bgah0kk0RUxG4PmgkCHrAM3CJDch8AA1XANsI5CougVJoxGIp 6Nh8fSefQLrUda+9Y6+pjO0+QZx5e4TwyDvc0iBJY1QtjVCmJtAba1ge54uX4nRRQBGji/uzz3X u6JIBY50gYc4+pfCsHrkV4ltkOhMWAOHwzvnCkRrhmIw0K0melO7Prd9uonQQhxgW2Lt08AN9jy 1mGXZdibcq9AJo26AGwX7KxBFiu1MJTvZVc= X-Google-Smtp-Source: AGHT+IGFM1FIUi1Mfo5FjPwx5/l20abT9mdE3Xj6ZBiiN78gN6+yTivz+AwJ6T4K6//mlczr2Z/EBA== X-Received: by 2002:a17:907:8b96:b0:abb:ebf8:72d9 with SMTP id a640c23a62f3a-abbeddc91a6mr2767081666b.15.1740556763177; Tue, 25 Feb 2025 23:59:23 -0800 (PST) Received: from think.fritz.box ([2a02:8109:8384:1400:c48e:2efa:cdfc:e268]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abed2013355sm280107866b.113.2025.02.25.23.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2025 23:59:22 -0800 (PST) From: Roman Penyaev To: Cc: Roman Penyaev , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , qemu-devel@nongnu.org Subject: [PATCH v2 5/5] ui/console-vc: implement DCH (delete) and ICH (insert) commands Date: Wed, 26 Feb 2025 08:59:11 +0100 Message-ID: <20250226075913.353676-6-r.peniaev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250226075913.353676-1-r.peniaev@gmail.com> References: <20250226075913.353676-1-r.peniaev@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=r.peniaev@gmail.com; helo=mail-ej1-x62c.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 | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/ui/console-vc.c b/ui/console-vc.c index 522adc2806c8..df1341513d53 100644 --- a/ui/console-vc.c +++ b/ui/console-vc.c @@ -645,6 +645,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 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. */ @@ -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;