//////////////////////////////////////////////////////////////////////
-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) {
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);
}
}
- // 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) {
}
}
+ // 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);
}
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 {
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
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]);
}
}
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;
}