[Concept,14/14] video: Move ansi and utf8_buf into vidconsole_ctx

Message ID 20260116101415.14.I33b9868999de00f88d957f23cf1d62a5fe0e9cff@changeid
State New
Headers
Series video: Add per-client context to vidconsole |

Commit Message

Simon Glass Jan. 16, 2026, 5:14 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move the ansi struct and utf8_buf array from vidconsole_priv into
vidconsole_ctx as part of the per-client context refactoring. These
fields hold parsing state for ANSI escape sequences and UTF-8 byte
accumulation, which need to be per-client to avoid interference when
multiple clients send interleaved data.

Also move struct vidconsole_ansi definition before struct vidconsole_ctx
since the latter now contains the former.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 drivers/video/vidconsole-uclass.c |  6 ++--
 include/video_console.h           | 50 +++++++++++++++----------------
 2 files changed, 28 insertions(+), 28 deletions(-)
  

Patch

diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 182505d1056..2136253b15e 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -195,7 +195,7 @@  static void vidconsole_escape_char(struct udevice *dev, char ch)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
 	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
-	struct vidconsole_ansi *ansi = &priv->ansi;
+	struct vidconsole_ansi *ansi = &ctx->ansi;
 
 	if (!IS_ENABLED(CONFIG_VIDEO_ANSI))
 		goto error;
@@ -487,7 +487,7 @@  int vidconsole_put_char(struct udevice *dev, char ch)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
 	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
-	struct vidconsole_ansi *ansi = &priv->ansi;
+	struct vidconsole_ansi *ansi = &ctx->ansi;
 	int cp, ret;
 
 	/* Hide cursor to avoid artifacts */
@@ -526,7 +526,7 @@  int vidconsole_put_char(struct udevice *dev, char ch)
 		break;
 	default:
 		if (CONFIG_IS_ENABLED(CHARSET)) {
-			cp = utf8_to_utf32_stream(ch, priv->utf8_buf);
+			cp = utf8_to_utf32_stream(ch, ctx->utf8_buf);
 			if (cp == 0)
 				return 0;
 		} else {
diff --git a/include/video_console.h b/include/video_console.h
index 73c4f54f62c..bc468d753d4 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -73,6 +73,27 @@  struct vidconsole_cursor {
 	uint index;
 };
 
+/**
+ * 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_ctx - per-client context for a video console
  *
@@ -89,6 +110,8 @@  struct vidconsole_cursor {
  * @cli_index:		Character index into the CLI text (0=start)
  * @xmark_frac:		X position of start of CLI text entry, in fractional units
  * @ymark:		Y position of start of CLI text
+ * @ansi:		ANSI escape-sequence state
+ * @utf8_buf:		Buffer to accumulate UTF-8 byte sequence
  */
 struct vidconsole_ctx {
 	int rows;
@@ -101,27 +124,8 @@  struct vidconsole_ctx {
 	int cli_index;
 	int xmark_frac;
 	int ymark;
-};
-
-/**
- * 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_ansi ansi;
+	char utf8_buf[5];
 };
 
 /**
@@ -143,8 +147,6 @@  struct vidconsole_ansi {
  * @tab_width_frac:	Tab width in fractional units
  * @xsize_frac:		Width of the display in fractional units
  * @xstart_frac:	Left margin for the text console in fractional units
- * @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
  */
@@ -154,8 +156,6 @@  struct vidconsole_priv {
 	int tab_width_frac;
 	int xsize_frac;
 	int xstart_frac;
-	struct vidconsole_ansi ansi;
-	char utf8_buf[5];
 	bool quiet;
 	struct vidconsole_cursor curs;
 };