[Concept,05/36] video: Add per-device vidconsole_readline_start/end()

Message ID 20260120231814.2033069-6-sjg@u-boot.org
State New
Headers
Series video: Add multiple-context support to vidconsole (part F) |

Commit Message

Simon Glass Jan. 20, 2026, 11:17 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add vidconsole_readline_start() and vidconsole_readline_end() functions
that operate on a single device. Rename the existing functions that
iterate all consoles to have an _all suffix.

Update scene_txtin.c to use the per-device versions with the expo's
console, and cli_readline.c to use the _all versions.

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

 boot/scene_txtin.c                |  4 ++--
 common/cli_readline.c             |  4 ++--
 drivers/video/vidconsole-uclass.c | 36 +++++++++++++++++-----------
 include/video_console.h           | 39 ++++++++++++++++++++++++++-----
 4 files changed, 59 insertions(+), 24 deletions(-)
  

Patch

diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c
index b5413dc145f..2b72ecaed39 100644
--- a/boot/scene_txtin.c
+++ b/boot/scene_txtin.c
@@ -107,7 +107,7 @@  static void scene_txtin_putch(struct cli_line_state *cls, int ch)
 void scene_txtin_close(struct scene *scn)
 {
 	/* cursor is not needed now */
-	vidconsole_readline_end();
+	vidconsole_readline_end(scn->expo->cons);
 }
 
 int scene_txtin_open(struct scene *scn, struct scene_obj *obj,
@@ -137,7 +137,7 @@  int scene_txtin_open(struct scene *scn, struct scene_obj *obj,
 		return log_msg_ret("sav", ret);
 
 	/* make sure the cursor is visible */
-	vidconsole_readline_start(true);
+	vidconsole_readline_start(cons, true);
 
 	return 0;
 }
diff --git a/common/cli_readline.c b/common/cli_readline.c
index 0173072109b..27fecd835a0 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -710,7 +710,7 @@  int cli_readline_into_buffer(const char *const prompt, char *buffer,
 			puts(prompt);
 
 		/* tell the vidconsole the cursor is at its start position */
-		vidconsole_readline_start(false);
+		vidconsole_readline_start_all(false);
 		rc = cread_line(prompt, p, &len, timeout);
 		rc = rc < 0 ? rc : len;
 
@@ -721,7 +721,7 @@  int cli_readline_into_buffer(const char *const prompt, char *buffer,
 	pager_set_bypass(gd_pager(), old_bypass);
 	pager_reset(gd_pager());
 
-	vidconsole_readline_end();
+	vidconsole_readline_end_all();
 
 	return rc;
 }
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 679d5d46f81..200bc60c55b 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -1019,30 +1019,38 @@  void vidconsole_idle(struct udevice *dev)
 }
 
 #ifdef CONFIG_CURSOR
-void vidconsole_readline_start(bool indent)
+void vidconsole_readline_start(struct udevice *dev, bool indent)
 {
-	struct uclass *uc;
-	struct udevice *dev;
+	struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
 
-	uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, dev, uc) {
-		struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
+	ctx->curs.indent = indent;
+	ctx->curs.enabled = true;
+	vidconsole_mark_start(dev);
+}
 
-		ctx->curs.indent = indent;
-		ctx->curs.enabled = true;
-		vidconsole_mark_start(dev);
-	}
+void vidconsole_readline_end(struct udevice *dev)
+{
+	struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
+
+	ctx->curs.enabled = false;
 }
 
-void vidconsole_readline_end(void)
+void vidconsole_readline_start_all(bool indent)
 {
 	struct uclass *uc;
 	struct udevice *dev;
 
-	uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, dev, uc) {
-		struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
+	uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, dev, uc)
+		vidconsole_readline_start(dev, indent);
+}
 
-		ctx->curs.enabled = false;
-	}
+void vidconsole_readline_end_all(void)
+{
+	struct uclass *uc;
+	struct udevice *dev;
+
+	uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, dev, uc)
+		vidconsole_readline_end(dev);
 }
 #endif /* CURSOR */
 
diff --git a/include/video_console.h b/include/video_console.h
index bb0445dc7c9..663f89b25f2 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -591,22 +591,41 @@  int vidconsole_show_cursor(struct udevice *dev);
 int vidconsole_hide_cursor(struct udevice *dev);
 
 /**
- * vidconsole_readline_start() - Enable cursor for all video consoles
+ * vidconsole_readline_start() - Enable cursor for a video console
+ *
+ * Called at the start of command line input to show the cursor
+ *
+ * @dev: vidconsole device
+ * @indent: indent subsequent lines to the same position as the first line
+ */
+void vidconsole_readline_start(struct udevice *dev, bool indent);
+
+/**
+ * vidconsole_readline_end() - Disable cursor for a video console
+ *
+ * Called at the end of command line input to hide the cursor
+ *
+ * @dev: vidconsole device
+ */
+void vidconsole_readline_end(struct udevice *dev);
+
+/**
+ * vidconsole_readline_start_all() - Enable cursor for all video consoles
  *
  * Called at the start of command line input to show cursors on all
  * active video consoles
  *
  * @indent: indent subsequent lines to the same position as the first line
  */
-void vidconsole_readline_start(bool indent);
+void vidconsole_readline_start_all(bool indent);
 
 /**
- * vidconsole_readline_end() - Disable cursor for all video consoles
+ * vidconsole_readline_end_all() - Disable cursor for all video consoles
  *
  * Called at the end of command line input to hide cursors on all
  * active video consoles
  */
-void vidconsole_readline_end(void);
+void vidconsole_readline_end_all(void);
 #else
 static inline int vidconsole_show_cursor(struct udevice *dev)
 {
@@ -618,11 +637,19 @@  static inline int vidconsole_hide_cursor(struct udevice *dev)
 	return 0;
 }
 
-static inline void vidconsole_readline_start(bool indent)
+static inline void vidconsole_readline_start(struct udevice *dev, bool indent)
+{
+}
+
+static inline void vidconsole_readline_end(struct udevice *dev)
+{
+}
+
+static inline void vidconsole_readline_start_all(bool indent)
 {
 }
 
-static inline void vidconsole_readline_end(void)
+static inline void vidconsole_readline_end_all(void)
 {
 }
 #endif /* CONFIG_CURSOR */