From patchwork Fri Jan 16 17:14:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1536 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583719; bh=VgAN+17KpI1Y1lE40F57Gr/pUD1y5rSe0rv4S3TkEsE=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=iGrK+osRuvxM+O0PtMpLoN45zZc5zhy1Jb1SWQubMRozSWbBWXbEkZ41IDH4/qlOn Yq5BsXKeI7euekhjkNh6hC0D0OnhRn7NcYHe5GC9tHUePLWcyuxDte8DNMlMOhoTu5 m4h2/ChHhQtmTfIQbwrNUXHHeqZij2jJmtAAssT4NY/kRT2iL8ntixHW42wKIIWvQq R590spsPsQTLZd7bt2e7Pd05mOcQHokPfD7DOtB0MlhxEbBgR82y/cjrLgMeHUU5dc Igxam/ZB6jAjhqbjZaOc+8DX1S4vtPJio36Bgm/aaSwXJevak1WS8wwl/sryyWt9zI vob/TLzI8bcLA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2040A693B2 for ; Fri, 16 Jan 2026 10:15:19 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id YYApdEnNVvKk for ; Fri, 16 Jan 2026 10:15:19 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583718; bh=VgAN+17KpI1Y1lE40F57Gr/pUD1y5rSe0rv4S3TkEsE=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=F0YEEzJCDxkTQkyKfM/qwOqMsDDqRiG2zxmFEJXyFoM4BEHAHoqaEHPl/6G5S8Ldu BQXwEOIJMmItxnibgrjK9lcmr5i0kAkHjzHxEHQ01YxQjNbvkrxX1DPV2Adgy1jWQx 9MEXbfn2nUNFCaMjBFYoP53f2q/MphhVEUuw8Wr+TgWpnEch8N1B6LvJos8bgZo/he fFeyOrfuGMR3dr56fxanEP4jXuvhibipXd8i0hjHFQaWCh6k69o42fK+pbj/axbPyN of7FVU/eCS9xxemOINbadFISE6ddccPsJqp6oYELa3o4JkN5YdLbLyHROsSwc8SOb7 9nPEF9VYlRQOw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E7CA2693B0 for ; Fri, 16 Jan 2026 10:15:18 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583716; bh=KYfIrm2sC8N3kyPqbB2tjSpw15gQBhJgQC9iTWGd5gY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ua1MJC+g/mSMifI0qHmlP9ttoiTGx7LV4m6hauCNIpbWGBBxvXInEbyhGmYg94PCK t6xu5wjo+sSDtMYiF3Mhuq6epASnAD5VMDSsKCa+dH5mcK08t6m01ki4QBC1GEPiBA D/nAw4cgD8f0BdMLJn14CcBOlDOz2wSelLOllVsAfdoFRgD962shqz6/4I6w+CXXUO BxTXTkNIjUR6Oz0bJsPUSbGFG/EAUlZdMId6KF9M8Pv93JZJ6BrEOwcKoPHzMZuh6Y IDOVlzlbb8Yl5WAuaGMe6DgOVNdMqhEYITMHfCA2DZIjB95OKWgZQcGmEEy2/BNmmj rglIpNYUDvIZA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F0DF66913F; Fri, 16 Jan 2026 10:15:16 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id le3S6NqjGjKn; Fri, 16 Jan 2026 10:15:16 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768583712; bh=3xrz1i4u1DZqRJTRFF+0HHxtn2p20DkO7Vg6yZVsnuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WT4EmC0GLx5bogaY7OXctV4gOM4st7963+HcRgY1mwBQRXFX5whg6a0AgjJuB6BZ9 3UcfvLmxNFxdMRft59o8hu4jyYuxLchq3tLANtvaDUHe3I3cBb9IBCvm0pMqL1LGCg ONUDpaxdBHdm4GFZe6XVFrCs5Z9quOtC8gue/MmSuYQWSJ+Jy+yNzxVmLLv14mmDBy vbo4+hrnYXciqUz6O2DopkXgHK6M/3aiDInLVxxwPcRLJEwKmK8U78hqqCsNLBVY5N 68Cs+EsY7scd5PrjwItVnezC4vEt/ZzUr9nXenFvtv8BoByEScfLWRkoDA/1mLVzSG 0I1y86b1QdtsA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 78EA26932E; Fri, 16 Jan 2026 10:15:12 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 10:14:10 -0700 Message-ID: <20260116171424.398597-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116171424.398597-1-sjg@u-boot.org> References: <20260116171424.398597-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: WJWJYDJR2TNLZRYHQ73FW45OFHVXIRHS X-Message-ID-Hash: WJWJYDJR2TNLZRYHQ73FW45OFHVXIRHS X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 08/14] video: Create struct vidconsole_ansi for ANSI state List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass The ANSI escape-sequence state in struct vidconsole_priv is related and can be grouped together. Create a new struct vidconsole_ansi to hold these fields and update vidconsole-uclass.c to use a local pointer variable for cleaner access. Move escape, escape_len, row_saved, col_saved, and escape_buf into the new struct. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- drivers/video/vidconsole-uclass.c | 44 ++++++++++++++++--------------- include/video_console.h | 38 +++++++++++++++----------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 71bcac4288e..ddcf2e87b6b 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -193,29 +193,30 @@ static void get_cursor_position(struct vidconsole_priv *priv, static void vidconsole_escape_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ansi *ansi = &priv->ansi; if (!IS_ENABLED(CONFIG_VIDEO_ANSI)) goto error; /* Sanity checking for bogus ESC sequences: */ - if (priv->escape_len >= sizeof(priv->escape_buf)) + if (ansi->escape_len >= sizeof(ansi->escape_buf)) goto error; - if (priv->escape_len == 0) { + if (ansi->escape_len == 0) { switch (ch) { case '7': /* Save cursor position */ - get_cursor_position(priv, &priv->row_saved, - &priv->col_saved); - priv->escape = 0; + get_cursor_position(priv, &ansi->row_saved, + &ansi->col_saved); + ansi->escape = 0; return; case '8': { /* Restore cursor position */ - int row = priv->row_saved; - int col = priv->col_saved; + int row = ansi->row_saved; + int col = ansi->col_saved; set_cursor_position(dev, row, col); - priv->escape = 0; + ansi->escape = 0; return; } case '[': @@ -225,7 +226,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) } } - priv->escape_buf[priv->escape_len++] = ch; + ansi->escape_buf[ansi->escape_len++] = ch; /* * Escape sequences are terminated by a letter, so keep @@ -239,7 +240,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) * surprising if you hit any debug prints that come back to * this console. */ - priv->escape = 0; + ansi->escape = 0; switch (ch) { case 'A': @@ -249,7 +250,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) case 'E': case 'F': { int row, col, num; - char *s = priv->escape_buf; + char *s = ansi->escape_buf; /* * Cursor up/down: [%dA, [%dB, [%dE, [%dF @@ -282,7 +283,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) case 'H': case 'f': { int row, col; - char *s = priv->escape_buf; + char *s = ansi->escape_buf; /* * Set cursor position: [%d;%df or [%d;%dH @@ -317,7 +318,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) * probably require some additions to video-uclass (and * are not really needed yet by efi_console) */ - parsenum(priv->escape_buf + 1, &mode); + parsenum(ansi->escape_buf + 1, &mode); if (mode == 2) { int ret; @@ -345,7 +346,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) * [0K - clear line to end * [2K - clear entire line */ - parsenum(priv->escape_buf + 1, &mode); + parsenum(ansi->escape_buf + 1, &mode); if (mode == 2) { int row, col; @@ -357,8 +358,8 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) } case 'm': { struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); - char *s = priv->escape_buf; - char *end = &priv->escape_buf[priv->escape_len]; + char *s = ansi->escape_buf; + char *end = &ansi->escape_buf[ansi->escape_len]; /* * Set graphics mode: [%d;...;%dm @@ -437,14 +438,14 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) } default: debug("unrecognized escape sequence: %*s\n", - priv->escape_len, priv->escape_buf); + ansi->escape_len, ansi->escape_buf); } return; error: /* something went wrong, just revert to normal mode: */ - priv->escape = 0; + ansi->escape = 0; } /* Put that actual character on the screen (using the UTF-32 code points). */ @@ -482,20 +483,21 @@ static int vidconsole_output_glyph(struct udevice *dev, int ch) int vidconsole_put_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + struct vidconsole_ansi *ansi = &priv->ansi; int cp, ret; /* Hide cursor to avoid artifacts */ vidconsole_hide_cursor(dev); - if (priv->escape) { + if (ansi->escape) { vidconsole_escape_char(dev, ch); return 0; } switch (ch) { case '\x1b': - priv->escape_len = 0; - priv->escape = 1; + ansi->escape_len = 0; + ansi->escape = 1; break; case '\a': /* beep */ diff --git a/include/video_console.h b/include/video_console.h index 0d0e6edbfb7..6f74f64cddf 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -91,6 +91,27 @@ struct vidconsole_ctx { int y_charsize; }; +/** + * struct vidconsole_ansi - ANSI escape-sequence state + * + * ANSI escape sequences are accumulated character by character, starting after + * the ESC char (0x1b) until the entire sequence is consumed, at which point it + * is acted upon. + * + * @escape: True if currently accumulating an ANSI escape sequence + * @escape_len: Length of accumulated escape sequence so far + * @row_saved: Saved Y position in pixels (0=top) + * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) + * @escape_buf: Buffer to accumulate escape sequence + */ +struct vidconsole_ansi { + int escape; + int escape_len; + int row_saved; + int col_saved; + char escape_buf[32]; +}; + /** * struct vidconsole_priv - uclass-private data about a console device * @@ -116,11 +137,7 @@ struct vidconsole_ctx { * @xmark_frac: X position of start of CLI text entry, in fractional units * @ymark: Y position of start of CLI text * @cli_index: Character index into the CLI text (0=start) - * @escape: TRUE if currently accumulating an ANSI escape sequence - * @escape_len: Length of accumulated escape sequence so far - * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) - * @row_saved: Saved Y position in pixels (0=top) - * @escape_buf: Buffer to accumulate escape sequence + * @ansi: ANSI escape-sequence state * @utf8_buf: Buffer to accumulate UTF-8 byte sequence * @quiet: Suppress all output from stdio * @curs: Cursor state and management @@ -137,16 +154,7 @@ struct vidconsole_priv { int xmark_frac; int ymark; int cli_index; - /* - * ANSI escape sequences are accumulated character by character, - * starting after the ESC char (0x1b) until the entire sequence - * is consumed at which point it is acted upon. - */ - int escape; - int escape_len; - int row_saved; - int col_saved; - char escape_buf[32]; + struct vidconsole_ansi ansi; char utf8_buf[5]; bool quiet; struct vidconsole_cursor curs;