char *title = 0;
int error_flash = 0;
-#define COLOR_MODELINE 1
-#define COLOR_FOCUS_LINE 2
-#define COLOR_ERROR 3
-
int attr_modeline, attr_focus_line, attr_error;
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
-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);
exit(1);
}
- init_pair(COLOR_MODELINE, color_fg_modeline, color_bg_modeline);
- init_pair(COLOR_FOCUS_LINE, color_fg_highlight, color_bg_highlight);
- init_pair(COLOR_ERROR, COLOR_WHITE, COLOR_RED);
+ init_pair(1, color_fg_modeline, color_bg_modeline);
+ attr_modeline = COLOR_PAIR(1);
+
+ init_pair(2, color_fg_highlight, color_bg_highlight);
+ attr_focus_line = COLOR_PAIR(2);
- attr_modeline = COLOR_PAIR(COLOR_MODELINE);
- attr_focus_line = COLOR_PAIR(COLOR_FOCUS_LINE);
- attr_error = COLOR_PAIR(COLOR_ERROR);
+ init_pair(3, COLOR_WHITE, COLOR_RED);
+ attr_error = COLOR_PAIR(3);
}
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;
}