Преглед изворни кода

[cmdline] Add support for shell history

The up and down arrow keys will now function roughly as expected at
the iPXE command line.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown пре 13 година
родитељ
комит
de2d983ab8
1 измењених фајлова са 10 додато и 1 уклоњено
  1. 10
    1
      src/hci/shell.c

+ 10
- 1
src/hci/shell.c Прегледај датотеку

@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
21 21
 #include <stdint.h>
22 22
 #include <stdlib.h>
23 23
 #include <stdio.h>
24
+#include <string.h>
24 25
 #include <getopt.h>
25 26
 #include <readline/readline.h>
26 27
 #include <ipxe/command.h>
@@ -75,17 +76,25 @@ struct command help_command __command = {
75 76
  *
76 77
  */
77 78
 int shell ( void ) {
79
+	struct readline_history history;
78 80
 	char *line;
79 81
 	int rc = 0;
80 82
 
83
+	/* Initialise shell history */
84
+	memset ( &history, 0, sizeof ( history ) );
85
+
86
+	/* Read and execute commands */
81 87
 	do {
82
-		line = readline ( shell_prompt );
88
+		line = readline_history ( shell_prompt, &history );
83 89
 		if ( line ) {
84 90
 			rc = system ( line );
85 91
 			free ( line );
86 92
 		}
87 93
 	} while ( ! shell_stopped ( SHELL_STOP_COMMAND_SEQUENCE ) );
88 94
 
95
+	/* Discard shell history */
96
+	history_free ( &history );
97
+
89 98
 	return rc;
90 99
 }
91 100
 

Loading…
Откажи
Сачувај