[Concept,12/14] video: Move cli_index into vidconsole_ctx

Message ID 20260116171424.398597-13-sjg@u-boot.org
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 cli_index field from vidconsole_priv into vidconsole_ctx as
part of the per-client context refactoring. This field tracks the
character position within CLI text entry.

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

 drivers/video/console_normal.c    | 8 ++++----
 drivers/video/vidconsole-uclass.c | 4 ++--
 include/video_console.h           | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
  

Patch

diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 95cde3aa709..283bbdff681 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -107,7 +107,7 @@  static __maybe_unused int console_get_cursor_info(struct udevice *dev)
 
 	x = VID_TO_PIXEL(vc_priv->xmark_frac);
 	y = vc_priv->ymark;
-	index = vc_priv->cli_index;
+	index = ctx->cli_index;
 
 	/* rounded up character position in this line */
 	xpos = (x + ctx->x_charsize - 1) / ctx->x_charsize;
@@ -141,7 +141,7 @@  static __maybe_unused int console_get_cursor_info(struct udevice *dev)
 	curs->x = x;
 	curs->y = y;
 	curs->height = ctx->y_charsize;
-	curs->index = vc_priv->cli_index;
+	curs->index = ctx->cli_index;
 
 	return 0;
 }
@@ -162,7 +162,7 @@  static __maybe_unused int normal_entry_save(struct udevice *dev,
 
 	store.xpos_frac = ctx->xcur_frac;
 	store.ypos  = ctx->ycur;
-	store.cli_index  = vc_priv->cli_index;
+	store.cli_index  = ctx->cli_index;
 	memcpy(abuf_data(buf), &store, size);
 
 	return 0;
@@ -182,7 +182,7 @@  static __maybe_unused int normal_entry_restore(struct udevice *dev,
 
 	ctx->xcur_frac = store.xpos_frac;
 	ctx->ycur = store.ypos;
-	vc_priv->cli_index = store.cli_index;
+	ctx->cli_index = store.cli_index;
 
 	return 0;
 }
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 1e9c0b4b730..4570c9fe60d 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -84,7 +84,7 @@  static int vidconsole_back(struct udevice *dev)
 		if (ctx->ycur < 0)
 			ctx->ycur = 0;
 	}
-	assert(priv->cli_index);
+	assert(ctx->cli_index);
 	cli_index_adjust(priv, -1);
 
 	return video_sync(dev->parent, false);
@@ -841,7 +841,7 @@  int vidconsole_mark_start(struct udevice *dev)
 
 	priv->xmark_frac = ctx->xcur_frac;
 	priv->ymark = ctx->ycur;
-	priv->cli_index = 0;
+	ctx->cli_index = 0;
 	if (ops->mark_start) {
 		int ret;
 
diff --git a/include/video_console.h b/include/video_console.h
index 6dfa2214448..559263e214b 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -86,6 +86,7 @@  struct vidconsole_cursor {
  * @xcur_frac:		Current X position, in fractional units (VID_TO_POS(x))
  * @ycur:		Current Y position in pixels (0=top)
  * @last_ch:		Last character written to the text console on this line
+ * @cli_index:		Character index into the CLI text (0=start)
  */
 struct vidconsole_ctx {
 	int rows;
@@ -95,6 +96,7 @@  struct vidconsole_ctx {
 	int xcur_frac;
 	int ycur;
 	int last_ch;
+	int cli_index;
 };
 
 /**
@@ -139,7 +141,6 @@  struct vidconsole_ansi {
  * @xstart_frac:	Left margin for the text console in fractional units
  * @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)
  * @ansi:		ANSI escape-sequence state
  * @utf8_buf:		Buffer to accumulate UTF-8 byte sequence
  * @quiet:		Suppress all output from stdio
@@ -153,7 +154,6 @@  struct vidconsole_priv {
 	int xstart_frac;
 	int xmark_frac;
 	int ymark;
-	int cli_index;
 	struct vidconsole_ansi ansi;
 	char utf8_buf[5];
 	bool quiet;
@@ -615,7 +615,7 @@  static inline void vidconsole_readline_end(void)
 static inline void cli_index_adjust(struct vidconsole_priv *priv, int by)
 {
 	if (CONFIG_IS_ENABLED(CURSOR))
-		priv->cli_index += by;
+		priv->ctx.cli_index += by;
 }
 
 /**