diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-04-15 15:59:49 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-04-15 15:59:49 +0100 |
commit | 40b51124400df9cb0c57512ff93ac21827d5bac0 (patch) | |
tree | fefb7a187eda31347f14f7317b29ed6427a271e2 /src/hci/mucurses | |
parent | 27ecc36c0bef804d12dbf8c29684c8e8159c8e47 (diff) | |
download | ipxe-40b51124400df9cb0c57512ff93ac21827d5bac0.tar.gz |
[hci] Use dynamically allocated buffers for editable strings
Editable strings currently require a fixed-size buffer, which is
inelegant and limits the potential for creating interactive forms with
a variable number of edit box widgets.
Remove this limitation by switching to using a dynamically allocated
buffer for editable strings and edit box widgets.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci/mucurses')
-rw-r--r-- | src/hci/mucurses/widgets/editbox.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/hci/mucurses/widgets/editbox.c b/src/hci/mucurses/widgets/editbox.c index 210de4481..fddd2742e 100644 --- a/src/hci/mucurses/widgets/editbox.c +++ b/src/hci/mucurses/widgets/editbox.c @@ -39,20 +39,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * Initialise text box widget * * @v box Editable text box widget - * @v buf Text buffer - * @v len Size of text buffer + * @v buf Dynamically allocated string buffer * @v win Containing window * @v row Row * @v col Starting column * @v width Width * @v flags Flags */ -void init_editbox ( struct edit_box *box, char *buf, size_t len, +void init_editbox ( struct edit_box *box, char **buf, WINDOW *win, unsigned int row, unsigned int col, unsigned int width, unsigned int flags ) { memset ( box, 0, sizeof ( *box ) ); - init_editstring ( &box->string, buf, len ); - box->string.cursor = strlen ( buf ); + init_editstring ( &box->string, buf ); + box->string.cursor = ( *buf ? strlen ( *buf ) : 0 ); box->win = ( win ? win : stdscr ); box->row = row; box->col = col; @@ -67,6 +66,7 @@ void init_editbox ( struct edit_box *box, char *buf, size_t len, * */ void draw_editbox ( struct edit_box *box ) { + const char *content = *(box->string.buf); size_t width = box->width; char buf[ width + 1 ]; signed int cursor_offset, underflow, overflow, first; @@ -90,13 +90,13 @@ void draw_editbox ( struct edit_box *box ) { /* Construct underscore-padded string portion */ memset ( buf, '_', width ); buf[width] = '\0'; - len = ( strlen ( box->string.buf ) - first ); + len = ( content ? ( strlen ( content ) - first ) : 0 ); if ( len > width ) len = width; if ( box->flags & EDITBOX_STARS ) { memset ( buf, '*', len ); } else { - memcpy ( buf, ( box->string.buf + first ), len ); + memcpy ( buf, ( content + first ), len ); } /* Print box content and move cursor */ |