Commit 5b0d272717ac6a1a2bc382f591a6a0a30ee52774

Authored by aliguori
1 parent a770dc7e

monitor: Provide empty command as final history entry (Jan Kiszka)

Provide an empty line as last entry in command line history, just like
bash e.g. does.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6842 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 5 additions and 3 deletions
readline.c
@@ -196,12 +196,14 @@ static void readline_up_char(ReadLineState *rs) @@ -196,12 +196,14 @@ static void readline_up_char(ReadLineState *rs)
196 196
197 static void readline_down_char(ReadLineState *rs) 197 static void readline_down_char(ReadLineState *rs)
198 { 198 {
199 - if (rs->hist_entry == READLINE_MAX_CMDS - 1 || rs->hist_entry == -1)  
200 - return;  
201 - if (rs->history[++rs->hist_entry] != NULL) { 199 + if (rs->hist_entry == -1)
  200 + return;
  201 + if (rs->hist_entry < READLINE_MAX_CMDS - 1 &&
  202 + rs->history[++rs->hist_entry] != NULL) {
202 pstrcpy(rs->cmd_buf, sizeof(rs->cmd_buf), 203 pstrcpy(rs->cmd_buf, sizeof(rs->cmd_buf),
203 rs->history[rs->hist_entry]); 204 rs->history[rs->hist_entry]);
204 } else { 205 } else {
  206 + rs->cmd_buf[0] = 0;
205 rs->hist_entry = -1; 207 rs->hist_entry = -1;
206 } 208 }
207 rs->cmd_buf_index = rs->cmd_buf_size = strlen(rs->cmd_buf); 209 rs->cmd_buf_index = rs->cmd_buf_size = strlen(rs->cmd_buf);