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 line, 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);
+
+ clear(); // Cleaning the window
+ refresh(); // After doing something on the display, we refresh it
+
+ use_default_colors();
+
+ 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++;
}
+
+ // Draw the modeline
+
+ 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!
}
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(0, 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(0, 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