From: Francois Fleuret Date: Mon, 8 Jun 2009 07:58:31 +0000 (+0200) Subject: Cosmetics. X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=selector.git;a=commitdiff_plain;h=5b4e65213ae6101671e4eb06788b152b34b34d15 Cosmetics. --- diff --git a/selector.cc b/selector.cc index 7488bfd..f740e89 100644 --- a/selector.cc +++ b/selector.cc @@ -333,7 +333,20 @@ int next_visible(int current_line, int nb_lines, char **lines, matcher_t *matche ////////////////////////////////////////////////////////////////////// -void update_screen(int *current_focus_line, int *temporary_line, int motion, +// The value passed to this routine in current_focus_line is the index +// of the line to highlighted if it matches the matcher. The line +// highlighted is the first the one matching the matcher in that +// order: The current_focus_line itself, the first with a greated +// index, the first with a lesser index. + +// The index of the line actually shown highlighted is written in +// displayed_focus_line (it can be -1) + +// If there is a motion and a line is actually shown highlighted, its +// value is written in current_focus_line + +void update_screen(int *current_focus_line, int *displayed_focus_line, + int motion, int nb_lines, char **lines, int cursor_position, char *pattern) { @@ -343,8 +356,6 @@ void update_screen(int *current_focus_line, int *temporary_line, int motion, initialize_matcher(use_regexp, case_sensitive, &matcher, pattern); - // We now take care of printing the lines per se - int console_width = getmaxx(stdscr); int console_height = getmaxy(stdscr); @@ -394,7 +405,7 @@ void update_screen(int *current_focus_line, int *temporary_line, int motion, } } - // Here new_focus_line is either a line number matching the patterns, or -1 + // Here new_focus_line is either a line number matching the pattern, or -1 if(new_focus_line >= 0) { @@ -466,12 +477,15 @@ void update_screen(int *current_focus_line, int *temporary_line, int motion, } } + // If we are on a focused line and we moved, this become the new + // focus line + if(motion != 0) { *current_focus_line = new_focus_line; } } - *temporary_line = new_focus_line; + *displayed_focus_line = new_focus_line; if(nb_printed_lines == 0) { attron(attr_error); @@ -912,9 +926,10 @@ int main(int argc, char **argv) { } int key; - int current_focus_line = 0, temporary_line = 0; + int current_focus_line = 0, displayed_focus_line = 0; - update_screen(¤t_focus_line, &temporary_line, 0, + update_screen(¤t_focus_line, &displayed_focus_line, + 0, nb_lines, labels, cursor_position, pattern); do { @@ -1005,7 +1020,8 @@ int main(int argc, char **argv) { clear(); } - update_screen(¤t_focus_line, &temporary_line, motion, + update_screen(¤t_focus_line, &displayed_focus_line, + motion, nb_lines, labels, cursor_position, pattern); } while(key != '\007' && // ^G @@ -1022,8 +1038,8 @@ int main(int argc, char **argv) { if((key == KEY_ENTER || key == '\n')) { if(output_to_vt_buffer) { - if(temporary_line >= 0 && temporary_line < nb_lines) { - inject_into_tty_buffer(lines[temporary_line]); + if(displayed_focus_line >= 0 && displayed_focus_line < nb_lines) { + inject_into_tty_buffer(lines[displayed_focus_line]); } } @@ -1033,8 +1049,8 @@ int main(int argc, char **argv) { cerr << "Can not open " << output_filename << " for writing." << endl; exit(1); } else { - if(temporary_line >= 0 && temporary_line < nb_lines) { - out << lines[temporary_line] << endl; + if(displayed_focus_line >= 0 && displayed_focus_line < nb_lines) { + out << lines[displayed_focus_line] << endl; } else { out << endl; }