diff options
author | Michael Brown | 2006-12-20 00:24:16 +0100 |
---|---|---|
committer | Michael Brown | 2006-12-20 00:24:16 +0100 |
commit | 66007fa448e3a0ced0c8c6d13a8fad281c483055 (patch) | |
tree | b350c576b43d936a967f8df75ff6ae152e4d836d /src/hci/editstring.c | |
parent | Explicitly move cursor to top-left of screen, in case the clear screen (diff) | |
download | ipxe-66007fa448e3a0ced0c8c6d13a8fad281c483055.tar.gz ipxe-66007fa448e3a0ced0c8c6d13a8fad281c483055.tar.xz ipxe-66007fa448e3a0ced0c8c6d13a8fad281c483055.zip |
Provide an edit history to allow caller to efficiently update display.
Diffstat (limited to 'src/hci/editstring.c')
-rw-r--r-- | src/hci/editstring.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/hci/editstring.c b/src/hci/editstring.c index a17b5761..f6a11617 100644 --- a/src/hci/editstring.c +++ b/src/hci/editstring.c @@ -35,7 +35,7 @@ */ static void insert_delete ( struct edit_string *string, size_t delete_len, const char *insert_text ) { - size_t old_len, max_delete_len, insert_len, max_insert_len; + size_t old_len, max_delete_len, insert_len, max_insert_len, new_len; /* Calculate lengths */ old_len = strlen ( string->buf ); @@ -47,6 +47,11 @@ static void insert_delete ( struct edit_string *string, size_t delete_len, max_insert_len = ( ( string->len - 1 ) - ( old_len - delete_len ) ); if ( insert_len > max_insert_len ) insert_len = max_insert_len; + new_len = ( old_len - delete_len + insert_len ); + + /* Fill in edit history */ + string->mod_start = string->cursor; + string->mod_end = ( ( new_len > old_len ) ? new_len : old_len ); /* Move data following the cursor */ memmove ( ( string->buf + string->cursor + insert_len ), @@ -113,10 +118,19 @@ static void kill_eol ( struct edit_string *string ) { * zero, otherwise it will return the original key. * * This function does not update the display in any way. + * + * The string's edit history will be updated to allow the caller to + * efficiently bring the display into sync with the string content. */ int edit_string ( struct edit_string *string, int key ) { int retval = 0; + /* Prepare edit history */ + string->last_cursor = string->cursor; + string->mod_start = string->cursor; + string->mod_end = string->cursor; + + /* Interpret key */ if ( ( key >= 0x20 ) && ( key <= 0x7e ) ) { /* Printable character; insert at current position */ insert_character ( string, key ); |