mirror of https://github.com/ipxe/ipxe.git
[readline] Add TAB support
Signed-off-by: AtieP <nosequiensoy8664@gmail.com> This commit adds TAB support, so when you're typing a command and you press TAB, similar commands are shown.pull/596/head
parent
bc5c612f75
commit
2aebb209be
|
@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <ipxe/command.h>
|
||||||
#include <ipxe/console.h>
|
#include <ipxe/console.h>
|
||||||
#include <ipxe/keys.h>
|
#include <ipxe/keys.h>
|
||||||
#include <ipxe/editstring.h>
|
#include <ipxe/editstring.h>
|
||||||
|
@ -324,6 +325,38 @@ int readline_history ( const char *prompt, const char *prefill,
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
move_by = -1;
|
move_by = -1;
|
||||||
break;
|
break;
|
||||||
|
case TAB: {
|
||||||
|
int new_line_printed, matches_found;
|
||||||
|
struct command *cmd;
|
||||||
|
new_line_printed = matches_found = 0;
|
||||||
|
|
||||||
|
for_each_table_entry ( cmd, COMMANDS ) {
|
||||||
|
if ( strncmp ( buf, cmd->name, strlen ( buf ) ) == 0 ) {
|
||||||
|
if ( !new_line_printed) {
|
||||||
|
printf("\n");
|
||||||
|
new_line_printed = 1;
|
||||||
|
matches_found = 1;
|
||||||
|
}
|
||||||
|
printf ( "%s ", cmd->name );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( matches_found ) {
|
||||||
|
printf ( "\n" );
|
||||||
|
|
||||||
|
/* Printing the prompt and creating a new editstring to print
|
||||||
|
the already typed command */
|
||||||
|
|
||||||
|
if ( prompt )
|
||||||
|
printf ( "%s", prompt );
|
||||||
|
|
||||||
|
memset ( &string, 0, sizeof ( string ) );
|
||||||
|
init_editstring ( &string, buf, READLINE_MAX );
|
||||||
|
replace_string ( &string, buf );
|
||||||
|
sync_console ( &string );
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue