comparison mcabber/src/screen.c @ 1177:10733d7de004

Refactor readline_accept_line() and readline_accept_line_down_hist() Add a parameter to readline_accept_line() for "down history".
author Mikael Berthe <mikael@lilotux.net>
date Wed, 04 Apr 2007 22:34:00 +0200
parents 547a8ca7c1a8
children 220e04816524
comparison
equal deleted inserted replaced
1176:547a8ca7c1a8 1177:10733d7de004
2471 2471
2472 ptr_inputline = next_char(ptr_inputline); 2472 ptr_inputline = next_char(ptr_inputline);
2473 check_offset(1); 2473 check_offset(1);
2474 } 2474 }
2475 2475
2476 int readline_accept_line(void) 2476 // readline_accept_line(down_history)
2477 // Validate current command line.
2478 // If down_history is true, load the next history line.
2479 int readline_accept_line(int down_history)
2477 { 2480 {
2478 scr_CheckAutoAway(TRUE); 2481 scr_CheckAutoAway(TRUE);
2479 if (process_line(inputLine)) 2482 if (process_line(inputLine))
2480 return 255; 2483 return 255;
2481 // Add line to history 2484 // Add line to history
2483 // Reset the line 2486 // Reset the line
2484 ptr_inputline = inputLine; 2487 ptr_inputline = inputLine;
2485 *ptr_inputline = 0; 2488 *ptr_inputline = 0;
2486 inputline_offset = 0; 2489 inputline_offset = 0;
2487 2490
2488 // Reset history line pointer 2491 if (down_history) {
2489 cmdhisto_cur = NULL; 2492 // Use next history line instead of a blank line
2490 2493 const char *l = scr_cmdhisto_next("", 0);
2491 return 0; 2494 if (l) strcpy(inputLine, l);
2492 } 2495 // Reset backup history line
2493 2496 cmdhisto_backup[0] = 0;
2494 int readline_accept_line_down_hist(void) 2497 } else {
2495 { 2498 // Reset history line pointer
2496 scr_CheckAutoAway(TRUE); 2499 cmdhisto_cur = NULL;
2497 if (process_line(inputLine)) 2500 }
2498 return 255;
2499 // Add line to history
2500 scr_cmdhisto_addline(inputLine);
2501 // Reset the line
2502 ptr_inputline = inputLine;
2503 *ptr_inputline = 0;
2504 inputline_offset = 0;
2505
2506 // Use next history line instead of a blank line
2507 const char *l = scr_cmdhisto_next("", 0);
2508 if (l) strcpy(inputLine, l);
2509 // Reset backup history line
2510 cmdhisto_backup[0] = 0;
2511
2512 return 0; 2501 return 0;
2513 } 2502 }
2514 2503
2515 void readline_cancel_completion(void) 2504 void readline_cancel_completion(void)
2516 { 2505 {
3092 break; 3081 break;
3093 case 9: // Tab 3082 case 9: // Tab
3094 readline_do_completion(); 3083 readline_do_completion();
3095 break; 3084 break;
3096 case 13: // Enter 3085 case 13: // Enter
3097 if (readline_accept_line() == 255) return 255; 3086 if (readline_accept_line(FALSE) == 255)
3087 return 255;
3098 break; 3088 break;
3099 case 3: // Ctrl-C 3089 case 3: // Ctrl-C
3100 scr_handle_CtrlC(); 3090 scr_handle_CtrlC();
3101 break; 3091 break;
3102 case KEY_RESIZE: 3092 case KEY_RESIZE: