Browse Source

[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 years ago
parent
commit
de2d983ab8
1 changed files with 10 additions and 1 deletions
  1. 10
    1
      src/hci/shell.c

+ 10
- 1
src/hci/shell.c View File

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

Loading…
Cancel
Save