From 6d645205fcd54e4b61d1bf62a09aebee0a01dec9 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Wed, 11 Mar 2009 02:59:15 +0100 Subject: [PATCH] Automatic commit --- selector.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/selector.cc b/selector.cc index 1ac71b2..0878f82 100644 --- a/selector.cc +++ b/selector.cc @@ -31,7 +31,7 @@ using namespace std; const int buffer_size = 1024; const int nb_lines_max = 100000; -void refresh_screen(int *screen_line, int *line, int nb_lines, char **lines, char *regexp, int noblink) { +int refresh_screen(int *screen_line, int *line, int nb_lines, char **lines, char *regexp, int noblink) { char buffer[buffer_size]; int maxx = getmaxx(stdscr); @@ -47,6 +47,7 @@ void refresh_screen(int *screen_line, int *line, int nb_lines, char **lines, cha int nb_printed_lines = 1, last_printer_line = -1; int y = 0; + int current_line = -1; while(nb_printed_lines < maxy && y < nb_lines) { if(strstr(lines[y], regexp) && @@ -70,6 +71,7 @@ void refresh_screen(int *screen_line, int *line, int nb_lines, char **lines, cha attron(COLOR_PAIR(2)); printw(buffer); attroff(COLOR_PAIR(2)); + current_line = y; } else { printw(buffer); } @@ -103,6 +105,8 @@ void refresh_screen(int *screen_line, int *line, int nb_lines, char **lines, cha attroff(COLOR_PAIR(1)); refresh(); // After doing something on the display, we refresh it + + return current_line; } int main(int argc, char **argv) { @@ -159,6 +163,8 @@ int main(int argc, char **argv) { refresh_screen(&screen_line, &line, nb_lines, lines, regexp, noblink); + int current_line = -1; + do { key = getch(); @@ -185,13 +191,17 @@ int main(int argc, char **argv) { line++; } - refresh_screen(&screen_line, &line, nb_lines, lines, regexp, noblink); + current_line = refresh_screen(&screen_line, &line, nb_lines, lines, regexp, noblink); } while(key != '\n' && key != KEY_ENTER && key != ''); echo(); curs_set(1); endwin(); + ofstream out("/tmp/selector.out"); + out << lines[current_line] << endl; + out.flush(); + for(int l = 0; l < nb_lines; l++) { delete[] lines[l]; } -- 2.39.5