From 35f5674e21b17ae2eaf8f0f8036d27477ef75dc1 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Thu, 19 Feb 2009 09:09:01 +0100 Subject: [PATCH] Automatic commit --- selector.cc | 54 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/selector.cc b/selector.cc index 0d5a30e..34ed86b 100644 --- a/selector.cc +++ b/selector.cc @@ -29,30 +29,40 @@ using namespace std; const int buffer_size = 1024; -const int nb_lines_max = 1000; +const int nb_lines_max = 100000; -void build_display(int nb_lines, char **lines, char *regexp) { +void build_display(int key, int nb_lines, char **lines, char *regexp) { char buffer[buffer_size]; clear(); // Cleaning the window refresh(); // After doing something on the display, we refresh it int maxx = getmaxx(stdscr); int maxy = getmaxy(stdscr); - printw("maxx %d maxy %d\n", maxx, maxy); - printw("nb_lines %d\n", nb_lines); + use_default_colors(); + // printw("maxx %d maxy %d key %d\n", maxx, maxy, key); + printw("\n"); + printw("\n"); int nb_printed_lines = 2; for(int y = 0; nb_printed_lines < maxy && y < nb_lines; y++) { - int k = 0; - while(lines[y][k] && k < buffer_size - 2 && k < maxx) { - buffer[k] = lines[y][k]; - k++; + if(strstr(lines[y], regexp)) { + int k = 0; + while(lines[y][k] && k < buffer_size - 2 && k < maxx) { + buffer[k] = lines[y][k]; + k++; + } + buffer[k++] = '\n'; + buffer[k++] = '\0'; + printw(buffer); + nb_printed_lines++; } - buffer[k++] = '\n'; - buffer[k++] = '\0'; - printw(buffer); - nb_printed_lines++; } + move(0, 0); + attron(COLOR_PAIR(1)); // Let's print something in red on black + printw("%d/%d pattern: %s\n", nb_printed_lines, nb_lines - 2, regexp); + attroff(COLOR_PAIR(1)); // Let's get back to default colors! } +// I should find were this is defined ... + int main(int argc, char **argv) { int dummy, xpos, ypos; @@ -97,25 +107,29 @@ int main(int argc, char **argv) { noecho(); // I don't want echo when I press a key curs_set(0); // I don't want to see the cursor + keypad(stdscr, TRUE); start_color(); // We will use colors - init_pair(1, COLOR_RED, COLOR_BLACK); // red on black for error messages - - // attron(COLOR_PAIR(1)); // Let's print something in red on black - // printw("Hello world\n"); // That's how we print something! - // attroff(COLOR_PAIR(1)); // Let's get back to default colors! + init_pair(1, COLOR_WHITE, COLOR_BLACK); // red on black for error messages printw("Press a key to contine\n"); int key; + build_display(-1, nb_lines, lines, regexp); + do { - build_display(nb_lines, lines, regexp); key = getch(); - if(key >= 'a' && key <= 'z') { + if(key >= ' ' && key <= 'z') { regexp[regexp_point++] = key; regexp[regexp_point] = '\0'; + } else if(key == KEY_BACKSPACE || key == KEY_DC) { + if(regexp_point > 0) { + regexp_point--; + regexp[regexp_point] = '\0'; + } } - } while(key != 'q'); + build_display(key, nb_lines, lines, regexp); + } while(key != '\n' && key != KEY_ENTER); echo(); // We want to have echo curs_set(1); // We want to see the cursor again -- 2.39.5