From patchwork Tue Jan 20 23:17:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1682 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=1768951156; bh=RlQy3N3oaThD7xX9SHJewQdKaH9HpSTeulD/VycWUfo=; 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=gACNymlq0PMt7uzM2dJULOXE3pgeBxnoorxr22R3PsK7Qe6r9S3Xxaql55xFgAU8h wCGyEz0cV6kPGWItp5eAIEV8l+QMu5Sno4HEdHj28CEQOp7U/3nRVjsFCI5OFbyIC5 iyf2kmquO8wF5jFdVkXNulomxGuYt7cWKLZNlEm6M1ShpkCvf+Dj+GTIeCFxFtiIE9 XnChpV762j6j4qGKsDndZUZynSXHdMum7hmKo4HTquqMiUhm5yUtnO1zyHHTyXuXWI GV5asPZA1kK5cdtqOm1E6Ur8aCgIdWg6Wpjt06i2ZdUvPrCB71jaegvKKPbNYChT6K melil8NEakw2g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5E65769589 for ; Tue, 20 Jan 2026 16:19: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 10024) with ESMTP id vdWe4jP_N-oU for ; Tue, 20 Jan 2026 16:19:16 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951156; bh=RlQy3N3oaThD7xX9SHJewQdKaH9HpSTeulD/VycWUfo=; 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=gACNymlq0PMt7uzM2dJULOXE3pgeBxnoorxr22R3PsK7Qe6r9S3Xxaql55xFgAU8h wCGyEz0cV6kPGWItp5eAIEV8l+QMu5Sno4HEdHj28CEQOp7U/3nRVjsFCI5OFbyIC5 iyf2kmquO8wF5jFdVkXNulomxGuYt7cWKLZNlEm6M1ShpkCvf+Dj+GTIeCFxFtiIE9 XnChpV762j6j4qGKsDndZUZynSXHdMum7hmKo4HTquqMiUhm5yUtnO1zyHHTyXuXWI GV5asPZA1kK5cdtqOm1E6Ur8aCgIdWg6Wpjt06i2ZdUvPrCB71jaegvKKPbNYChT6K melil8NEakw2g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4C43E6957E for ; Tue, 20 Jan 2026 16:19:16 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951154; bh=rTSRL2ebK+l3r8jYjHcMCzTr6mlIuQkGxRKs00Wglas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sMN0heGg7clUDrDLZmJ4H6VvxG1Frgl2Z/OQNT5MAhCv+NB6gkIrd8WfNcAP0PFP6 UmO+axBT+QX6q2gK85Xpv9PJumfXDmR7c1f0Q1rVS/IIdBLp+yu2dIhcmOIYR6xhVx LGZ8lS4+FBflqVFABNGYRcjBz07Cad4ZZ3BTry3JGtRc3vYiq5OYDfn9WrBpjzroEG hkqADQG29FoNTWEjE8ARWzJBj3F+eH1R24eYZzCnf85V5JBp8vQ3WNWtT1QFFKRRQJ fIcdR3Uxx4sWycDCpkCsmWQTJbx1dBbUjibmPLmGDQGzgxbq1OqawkY3/OQ7EePaUt OEigR4Giqm+Rg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9823E69572; Tue, 20 Jan 2026 16:19:14 -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 QHpVlbrQEdzZ; Tue, 20 Jan 2026 16:19:14 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951150; bh=59WcpGtiT0yY2IOHceMK+8dSMsamgT7XthqtVdHOjc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BnvFba834Wq+R6xyxwppDfFgeUzalVyB2G+iGX4NwjCuljjbWpj/auN7UfqsF/qRj g/BEqGjZMLjzEMZm/9uuBYZA/UFTZ7d3scYlQvFqZMAU2suWIK5xXPUKwiM4WAGg21 uRtckav4LRcQeuma8kj+8TOAKJz/dmtePW1szIe2M0H6qt2A/XFXlSURYf5+u+TnxH eIRfGuYJ2RZ0KHrqaWNa4UohFVbC1WbMcsI9L3VXyZGOdD5wCKF3v9sFIggevz6pZ/ V6ckGUltR3bEap3vHj//QHz+LMsBuXp+da2o6bV7mBMU+WbA/Bah9Kt45SPGtpminl Tnd/GZpd/NwlA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 414716913F; Tue, 20 Jan 2026 16:19:10 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 20 Jan 2026 16:17:36 -0700 Message-ID: <20260120231814.2033069-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120231814.2033069-1-sjg@u-boot.org> References: <20260120231814.2033069-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: JWKIJFAPWLZZNOEHN4DIBFORTYAKE6PF X-Message-ID-Hash: JWKIJFAPWLZZNOEHN4DIBFORTYAKE6PF 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 09/36] expo: Use text-input CLI line state instead of scene's 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 Update scene_txtin to use tin->cls instead of scn->cls, so that each text-input object maintains its own CLI line-editing state. Add a priv pointer to struct cli_line_state so the putch callback can access the scene without using container_of. This is necessary because the cls is now embedded in scene_txtin rather than scene. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- boot/scene_txtin.c | 18 +++++++++++------- include/cli.h | 2 ++ test/boot/expo.c | 12 ++++++------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c index d08b9e4ff0f..296b2fb1a1b 100644 --- a/boot/scene_txtin.c +++ b/boot/scene_txtin.c @@ -63,6 +63,7 @@ int scene_txtin_arrange(struct scene *scn, struct expo_arrange_info *arr, int scene_txtin_render_deps(struct scene *scn, struct scene_obj *obj, struct scene_txtin *tin) { + struct cli_line_state *cls = &tin->cls; const bool open = obj->flags & SCENEOF_OPEN; struct udevice *cons = scn->expo->cons; uint i; @@ -77,7 +78,7 @@ int scene_txtin_render_deps(struct scene *scn, struct scene_obj *obj, scene_render_obj(scn, tin->edit_id); /* move cursor back to the correct position */ - for (i = scn->cls.num; i < scn->cls.eol_num; i++) + for (i = cls->num; i < cls->eol_num; i++) vidconsole_put_char(cons, '\b'); ret = vidconsole_entry_save(cons, &scn->entry_save); if (ret) @@ -100,7 +101,7 @@ int scene_txtin_render_deps(struct scene *scn, struct scene_obj *obj, */ static void scene_txtin_putch(struct cli_line_state *cls, int ch) { - struct scene *scn = container_of(cls, struct scene, cls); + struct scene *scn = cls->priv; vidconsole_put_char(scn->expo->cons, ch); } @@ -114,6 +115,7 @@ void scene_txtin_close(struct scene *scn) int scene_txtin_open(struct scene *scn, struct scene_obj *obj, struct scene_txtin *tin) { + struct cli_line_state *cls = &tin->cls; struct udevice *cons = scn->expo->cons; struct scene_obj_txt *txt; int ret; @@ -129,10 +131,11 @@ int scene_txtin_open(struct scene *scn, struct scene_obj *obj, vidconsole_set_cursor_pos(cons, NULL, txt->obj.bbox.x0, txt->obj.bbox.y0); vidconsole_entry_start(cons, NULL); - cli_cread_init(&scn->cls, abuf_data(&tin->buf), tin->line_chars); - scn->cls.insert = true; - scn->cls.putch = scene_txtin_putch; - cli_cread_add_initial(&scn->cls); + cli_cread_init(cls, abuf_data(&tin->buf), tin->line_chars); + cls->insert = true; + cls->putch = scene_txtin_putch; + cls->priv = scn; + cli_cread_add_initial(cls); ret = vidconsole_entry_save(cons, &scn->entry_save); if (ret) return log_msg_ret("sav", ret); @@ -162,6 +165,7 @@ void scene_txtin_calc_bbox(struct scene_obj *obj, struct scene_txtin *tin, int scene_txtin_send_key(struct scene_obj *obj, struct scene_txtin *tin, int key, struct expo_action *event) { + struct cli_line_state *cls = &tin->cls; const bool open = obj->flags & SCENEOF_OPEN; struct scene *scn = obj->scene; @@ -196,7 +200,7 @@ int scene_txtin_send_key(struct scene_obj *obj, struct scene_txtin *tin, ret = vidconsole_entry_restore(cons, &scn->entry_save); if (ret) return log_msg_ret("sav", ret); - ret = cread_line_process_ch(&scn->cls, key); + ret = cread_line_process_ch(cls, key); ret = vidconsole_entry_save(cons, &scn->entry_save); if (ret) return log_msg_ret("sav", ret); diff --git a/include/cli.h b/include/cli.h index ec0f5d31046..a02e228bf8a 100644 --- a/include/cli.h +++ b/include/cli.h @@ -37,6 +37,7 @@ struct cli_ch_state { * @buf: Buffer containing line * @prompt: Prompt for the line * @putch: Function to call to output a character (NULL to use putc()) + * @priv: Private data for putch callback */ struct cli_line_state { uint num; @@ -48,6 +49,7 @@ struct cli_line_state { char *buf; const char *prompt; void (*putch)(struct cli_line_state *cls, int ch); + void *priv; }; /** diff --git a/test/boot/expo.c b/test/boot/expo.c index d7430dc4284..f94927eb6b7 100644 --- a/test/boot/expo.c +++ b/test/boot/expo.c @@ -1481,8 +1481,8 @@ static int expo_render_textline(struct unit_test_state *uts) ut_assertok(expo_send_key(exp, CTL_CH('b'))); /* check cursor moved back one position, before 'a' */ - ut_asserteq(14, scn->cls.num); - ut_asserteq(15, scn->cls.eol_num); + ut_asserteq(14, tline->tin.cls.num); + ut_asserteq(15, tline->tin.cls.eol_num); ut_asserteq_str("sample hopwinda", abuf_data(&tline->tin.buf)); ut_assertok(scene_arrange(scn)); ut_assertok(expo_render(exp)); @@ -1493,8 +1493,8 @@ static int expo_render_textline(struct unit_test_state *uts) ut_assertok(expo_send_key(exp, CTL_CH('b'))); /* check cursor moved back three more positions, before 'i' */ - ut_asserteq(11, scn->cls.num); - ut_asserteq(15, scn->cls.eol_num); + ut_asserteq(11, tline->tin.cls.num); + ut_asserteq(15, tline->tin.cls.eol_num); ut_asserteq_str("sample hopwinda", abuf_data(&tline->tin.buf)); ut_assertok(scene_arrange(scn)); ut_assertok(expo_render(exp)); @@ -1504,8 +1504,8 @@ static int expo_render_textline(struct unit_test_state *uts) ut_assertok(expo_send_key(exp, CTL_CH('d'))); /* check character deleted at cursor position */ - ut_asserteq(11, scn->cls.num); - ut_asserteq(14, scn->cls.eol_num); + ut_asserteq(11, tline->tin.cls.num); + ut_asserteq(14, tline->tin.cls.eol_num); ut_asserteq_str("sample hopwnda", abuf_data(&tline->tin.buf)); ut_assertok(scene_arrange(scn)); ut_assertok(expo_render(exp));