Go to the source code of this file.
Data Structures | |
| struct | edit_string |
| An editable string. More... | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| int | edit_string (struct edit_string *string, int key) __nonnull |
| Edit editable string. | |
Definition in file editstring.h.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| int edit_string | ( | struct edit_string * | string, | |
| int | key | |||
| ) |
Edit editable string.
| string | Editable string | |
| key | Key pressed by user |
| key | Key returned to application, or zero |
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.
Definition at line 137 of file editstring.c.
References backspace(), edit_string::buf, CTRL_A, CTRL_B, CTRL_D, CTRL_E, CTRL_F, CTRL_K, edit_string::cursor, delete_character(), insert_character(), KEY_BACKSPACE, KEY_DC, KEY_END, KEY_HOME, KEY_LEFT, KEY_RIGHT, kill_eol(), and strlen().
Referenced by edit_editbox(), and readline().
00137 { 00138 int retval = 0; 00139 size_t len = strlen ( string->buf ); 00140 00141 /* Prepare edit history */ 00142 string->last_cursor = string->cursor; 00143 string->mod_start = string->cursor; 00144 string->mod_end = string->cursor; 00145 00146 /* Interpret key */ 00147 if ( ( key >= 0x20 ) && ( key <= 0x7e ) ) { 00148 /* Printable character; insert at current position */ 00149 insert_character ( string, key ); 00150 } else switch ( key ) { 00151 case KEY_BACKSPACE: 00152 /* Backspace */ 00153 backspace ( string ); 00154 break; 00155 case KEY_DC: 00156 case CTRL_D: 00157 /* Delete character */ 00158 delete_character ( string ); 00159 break; 00160 case CTRL_K: 00161 /* Delete to end of line */ 00162 kill_eol ( string ); 00163 break; 00164 case KEY_HOME: 00165 case CTRL_A: 00166 /* Start of line */ 00167 string->cursor = 0; 00168 break; 00169 case KEY_END: 00170 case CTRL_E: 00171 /* End of line */ 00172 string->cursor = len; 00173 break; 00174 case KEY_LEFT: 00175 case CTRL_B: 00176 /* Cursor left */ 00177 if ( string->cursor > 0 ) 00178 string->cursor--; 00179 break; 00180 case KEY_RIGHT: 00181 case CTRL_F: 00182 /* Cursor right */ 00183 if ( string->cursor < len ) 00184 string->cursor++; 00185 break; 00186 default: 00187 retval = key; 00188 break; 00189 } 00190 00191 return retval; 00192 }
1.5.7.1