# HG changeset patch # User Mikael Berthe # Date 1175718840 -7200 # Node ID 10733d7de004c08302ac2731c2d1ed7eab8fa563 # Parent 547a8ca7c1a80d7d3ac0c9b02c2f57756c564ebe Refactor readline_accept_line() and readline_accept_line_down_hist() Add a parameter to readline_accept_line() for "down history". diff -r 547a8ca7c1a8 -r 10733d7de004 mcabber/src/commands.c --- a/mcabber/src/commands.c Wed Apr 04 22:03:49 2007 +0200 +++ b/mcabber/src/commands.c Wed Apr 04 22:34:00 2007 +0200 @@ -2774,9 +2774,9 @@ } else if (!strcasecmp(arg, "send_multiline")) { readline_send_multiline(); } else if (!strcasecmp(arg, "iline_accept")) { - retval_for_cmds = readline_accept_line(); - } else if (!strcasecmp(arg, "iline_accept_down_hist")) { // May be too long - retval_for_cmds = readline_accept_line_down_hist(); + retval_for_cmds = readline_accept_line(FALSE); + } else if (!strcasecmp(arg, "iline_accept_down_hist")) { + retval_for_cmds = readline_accept_line(TRUE); } else if (!strcasecmp(arg, "compl_cancel")) { readline_cancel_completion(); } else if (!strcasecmp(arg, "compl_do")) { diff -r 547a8ca7c1a8 -r 10733d7de004 mcabber/src/screen.c --- a/mcabber/src/screen.c Wed Apr 04 22:03:49 2007 +0200 +++ b/mcabber/src/screen.c Wed Apr 04 22:34:00 2007 +0200 @@ -2473,7 +2473,10 @@ check_offset(1); } -int readline_accept_line(void) +// readline_accept_line(down_history) +// Validate current command line. +// If down_history is true, load the next history line. +int readline_accept_line(int down_history) { scr_CheckAutoAway(TRUE); if (process_line(inputLine)) @@ -2485,30 +2488,16 @@ *ptr_inputline = 0; inputline_offset = 0; - // Reset history line pointer - cmdhisto_cur = NULL; - - return 0; -} - -int readline_accept_line_down_hist(void) -{ - scr_CheckAutoAway(TRUE); - if (process_line(inputLine)) - return 255; - // Add line to history - scr_cmdhisto_addline(inputLine); - // Reset the line - ptr_inputline = inputLine; - *ptr_inputline = 0; - inputline_offset = 0; - - // Use next history line instead of a blank line - const char *l = scr_cmdhisto_next("", 0); - if (l) strcpy(inputLine, l); - // Reset backup history line - cmdhisto_backup[0] = 0; - + if (down_history) { + // Use next history line instead of a blank line + const char *l = scr_cmdhisto_next("", 0); + if (l) strcpy(inputLine, l); + // Reset backup history line + cmdhisto_backup[0] = 0; + } else { + // Reset history line pointer + cmdhisto_cur = NULL; + } return 0; } @@ -3094,7 +3083,8 @@ readline_do_completion(); break; case 13: // Enter - if (readline_accept_line() == 255) return 255; + if (readline_accept_line(FALSE) == 255) + return 255; break; case 3: // Ctrl-C scr_handle_CtrlC(); diff -r 547a8ca7c1a8 -r 10733d7de004 mcabber/src/screen.h --- a/mcabber/src/screen.h Wed Apr 04 22:03:49 2007 +0200 +++ b/mcabber/src/screen.h Wed Apr 04 22:34:00 2007 +0200 @@ -138,8 +138,7 @@ void readline_capitalize_word(void); void readline_backward_char(void); void readline_forward_char(void); -int readline_accept_line(void); -int readline_accept_line_down_hist(void); +int readline_accept_line(int down_history); void readline_cancel_completion(void); void readline_do_completion(void); void readline_refresh_screen(void);