+ if(new_line == nb_lines) {
+ new_line = -1;
+ }
+ }
+ }
+
+ // Here new_line is either a line number matching the regexp, or -1
+
+ if(new_line >= 0) {
+ int first_line = new_line, last_line = new_line, nb_match = 1;
+
+ while(nb_match < console_height && (first_line > 0 || last_line < nb_lines - 1)) {
+
+ if(first_line > 0) {
+ first_line--;
+ while(first_line > 0 && !match(lines[first_line], regexp)) {
+ first_line--;
+ }
+ if(match(lines[first_line], regexp)) {
+ nb_match++;
+ }
+ }
+
+ if(last_line < nb_lines - 1) {
+ last_line++;
+ while(last_line < nb_lines - 1 && !match(lines[last_line], regexp)) {
+ last_line++;
+ }
+
+ if(match(lines[last_line], regexp)) {
+ nb_match++;
+ }
+ }
+ }
+
+ for(int l = first_line; l <= last_line; l++) {
+ if(match(lines[l], regexp)) {
+ int k = 0;
+
+ while(lines[l][k] && k < buffer_size - 2 && k < console_width - 1) {
+ buffer[k] = lines[l][k];
+ k++;
+ }
+
+ if(noblink) {
+ while(k < console_width - 1) {
+ buffer[k++] = ' ';
+ }
+ }
+ buffer[k++] = '\n';
+ buffer[k++] = '\0';
+
+ if(l == new_line) {
+ attron(COLOR_PAIR(2));
+ printw(buffer);
+ attroff(COLOR_PAIR(2));
+ } else {
+ printw(buffer);
+ }
+
+ last_printer_line = l;
+ nb_printed_lines++;
+ }
+ }
+
+ *current_line = new_line;
+ }
+
+ if(noblink) { // Erase the rest of the window. That's slightly ugly.
+ int k = 0;
+ while(k < console_width - 1) {
+ buffer[k++] = ' ';
+ }
+ buffer[k++] = '\n';
+ buffer[k++] = '\0';
+ for(int l = nb_printed_lines; l < console_height; l++) {