From: Simon Glass <simon.glass@canonical.com> Factor out the open code from scene_textline_open() into a shared helper scene_txtin_open() This sets up the text editor ready for use, including copying the backup text, setting cursor position, and initialising the CLI line state. Update scene_obj_open() to call scene_txtin_open() directly for both textline and textedit objects. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- boot/scene.c | 5 ++--- boot/scene_internal.h | 10 +++++---- boot/scene_textline.c | 45 --------------------------------------- boot/scene_txtin.c | 49 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/boot/scene.c b/boot/scene.c index b05291138ed..6b5c934a2e7 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -1670,11 +1670,10 @@ static int scene_obj_open(struct scene *scn, struct scene_obj *obj) case SCENEOBJT_MENU: case SCENEOBJT_TEXT: case SCENEOBJT_BOX: - case SCENEOBJT_TEXTEDIT: break; case SCENEOBJT_TEXTLINE: - ret = scene_textline_open(scn, - (struct scene_obj_textline *)obj); + case SCENEOBJT_TEXTEDIT: + ret = scene_txtin_open(scn, obj, scene_obj_txtin(obj)); if (ret) return log_msg_ret("op", ret); break; diff --git a/boot/scene_internal.h b/boot/scene_internal.h index 96bc4e06ad6..8899ba538ae 100644 --- a/boot/scene_internal.h +++ b/boot/scene_internal.h @@ -569,15 +569,17 @@ int scene_txtin_render_deps(struct scene *scn, struct scene_obj *obj, int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox); /** - * scene_textline_open() - Open a textline object + * scene_txtin_open() - Open a text-input object * * Set up the text editor ready for use * - * @scn: Scene containing the textline - * @tline: textline object + * @scn: Scene containing the object + * @obj: Object to open + * @tin: Text-input info * Return: 0 if OK, -ve on error */ -int scene_textline_open(struct scene *scn, struct scene_obj_textline *tline); +int scene_txtin_open(struct scene *scn, struct scene_obj *obj, + struct scene_txtin *tin); /** * scene_textline_close() - Close a textline object diff --git a/boot/scene_textline.c b/boot/scene_textline.c index 46ab53e30c9..2199b3d0641 100644 --- a/boot/scene_textline.c +++ b/boot/scene_textline.c @@ -152,48 +152,3 @@ bool scene_textline_within(const struct scene *scn, return scene_within(scn, tline->tin.edit_id, x, y); } -/** - * scene_textline_putch() - Output a character to the vidconsole - * - * This is used as the putch callback for CLI line editing, so that characters - * are sent to the correct vidconsole. - * - * @cls: CLI line state - * @ch: Character to output - */ -static void scene_textline_putch(struct cli_line_state *cls, int ch) -{ - struct scene *scn = container_of(cls, struct scene, cls); - - vidconsole_put_char(scn->expo->cons, ch); -} - -int scene_textline_open(struct scene *scn, struct scene_obj_textline *tline) -{ - struct udevice *cons = scn->expo->cons; - struct scene_obj_txt *txt; - int ret; - - /* Copy the text into the scene buffer in case the edit is cancelled */ - memcpy(abuf_data(&scn->buf), abuf_data(&tline->tin.buf), - abuf_size(&scn->buf)); - - /* get the position of the editable */ - txt = scene_obj_find(scn, tline->tin.edit_id, SCENEOBJT_NONE); - if (!txt) - return log_msg_ret("cur", -ENOENT); - - vidconsole_set_cursor_pos(cons, txt->obj.bbox.x0, txt->obj.bbox.y0); - vidconsole_entry_start(cons); - cli_cread_init(&scn->cls, abuf_data(&tline->tin.buf), tline->tin.line_chars); - scn->cls.insert = true; - scn->cls.putch = scene_textline_putch; - ret = vidconsole_entry_save(cons, &scn->entry_save); - if (ret) - return log_msg_ret("sav", ret); - - /* make sure the cursor is visible */ - vidconsole_readline_start(true); - - return 0; -} diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c index 2e7c496310d..a4c373c14fa 100644 --- a/boot/scene_txtin.c +++ b/boot/scene_txtin.c @@ -10,8 +10,10 @@ #include <expo.h> #include <log.h> +#include <menu.h> #include <video_console.h> #include <linux/errno.h> +#include <linux/string.h> #include "scene_internal.h" int scene_txtin_init(struct scene_txtin *tin, uint size, uint line_chars) @@ -86,6 +88,53 @@ int scene_txtin_render_deps(struct scene *scn, struct scene_obj *obj, return 0; } +/** + * scene_txtin_putch() - Output a character to the vidconsole + * + * This is used as the putch callback for CLI line editing, so that characters + * are sent to the correct vidconsole. + * + * @cls: CLI line state + * @ch: Character to output + */ +static void scene_txtin_putch(struct cli_line_state *cls, int ch) +{ + struct scene *scn = container_of(cls, struct scene, cls); + + vidconsole_put_char(scn->expo->cons, ch); +} + +int scene_txtin_open(struct scene *scn, struct scene_obj *obj, + struct scene_txtin *tin) +{ + struct udevice *cons = scn->expo->cons; + struct scene_obj_txt *txt; + int ret; + + /* Copy the text into the scene buffer in case the edit is cancelled */ + memcpy(abuf_data(&scn->buf), abuf_data(&tin->buf), + abuf_size(&scn->buf)); + + /* get the position of the editable */ + txt = scene_obj_find(scn, tin->edit_id, SCENEOBJT_NONE); + if (!txt) + return log_msg_ret("cur", -ENOENT); + + vidconsole_set_cursor_pos(cons, txt->obj.bbox.x0, txt->obj.bbox.y0); + vidconsole_entry_start(cons); + cli_cread_init(&scn->cls, abuf_data(&tin->buf), tin->line_chars); + scn->cls.insert = true; + scn->cls.putch = scene_txtin_putch; + ret = vidconsole_entry_save(cons, &scn->entry_save); + if (ret) + return log_msg_ret("sav", ret); + + /* make sure the cursor is visible */ + vidconsole_readline_start(true); + + return 0; +} + void scene_txtin_calc_bbox(struct scene_obj *obj, struct scene_txtin *tin, struct vidconsole_bbox *bbox, struct vidconsole_bbox *edit_bbox) -- 2.43.0