|
@@ -241,13 +241,14 @@ void history_free ( struct readline_history *history ) {
|
241
|
241
|
* Read line from console (with history)
|
242
|
242
|
*
|
243
|
243
|
* @v prompt Prompt string
|
|
244
|
+ * @v prefill Prefill string, or NULL for no prefill
|
244
|
245
|
* @v history History buffer, or NULL for no history
|
245
|
246
|
* @ret line Line read from console (excluding terminating newline)
|
246
|
247
|
*
|
247
|
248
|
* The returned line is allocated with malloc(); the caller must
|
248
|
249
|
* eventually call free() to release the storage.
|
249
|
250
|
*/
|
250
|
|
-char * readline_history ( const char *prompt,
|
|
251
|
+char * readline_history ( const char *prompt, const char *prefill,
|
251
|
252
|
struct readline_history *history ) {
|
252
|
253
|
char buf[READLINE_MAX];
|
253
|
254
|
struct edit_string string;
|
|
@@ -265,6 +266,12 @@ char * readline_history ( const char *prompt,
|
265
|
266
|
init_editstring ( &string, buf, sizeof ( buf ) );
|
266
|
267
|
buf[0] = '\0';
|
267
|
268
|
|
|
269
|
+ /* Prefill string, if applicable */
|
|
270
|
+ if ( prefill ) {
|
|
271
|
+ replace_string ( &string, prefill );
|
|
272
|
+ sync_console ( &string );
|
|
273
|
+ }
|
|
274
|
+
|
268
|
275
|
while ( 1 ) {
|
269
|
276
|
/* Handle keypress */
|
270
|
277
|
key = edit_string ( &string, getkey ( 0 ) );
|
|
@@ -321,5 +328,5 @@ char * readline_history ( const char *prompt,
|
321
|
328
|
* eventually call free() to release the storage.
|
322
|
329
|
*/
|
323
|
330
|
char * readline ( const char *prompt ) {
|
324
|
|
- return readline_history ( prompt, NULL );
|
|
331
|
+ return readline_history ( prompt, NULL, NULL );
|
325
|
332
|
}
|