2 ///////////////////////////////////////////////////////////////////////////
5 // This program is free software: you can redistribute it and/or modify //
6 // it under the terms of the version 3 of the GNU General Public License //
7 // as published by the Free Software Foundation. //
9 // This program is distributed in the hope that it will be useful, but //
10 // WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
12 // General Public License for more details. //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 // Written by and Copyright (C) Francois Fleuret //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
21 ///////////////////////////////////////////////////////////////////////////
31 const int buffer_size = 1024;
32 const int nb_lines_max = 1000;
34 void build_display(int nb_lines, char **lines, char *regexp) {
35 char buffer[buffer_size];
36 clear(); // Cleaning the window
37 refresh(); // After doing something on the display, we refresh it
38 int maxx = getmaxx(stdscr);
39 int maxy = getmaxy(stdscr);
40 printw("maxx %d maxy %d\n", maxx, maxy);
41 printw("nb_lines %d\n", nb_lines);
42 int nb_printed_lines = 2;
43 for(int y = 0; nb_printed_lines < maxy && y < nb_lines; y++) {
45 while(lines[y][k] && k < buffer_size - 2 && k < maxx) {
46 buffer[k] = lines[y][k];
56 int main(int argc, char **argv) {
57 int dummy, xpos, ypos;
59 char buffer[buffer_size];
60 char *lines[nb_lines_max];
62 ifstream file(argv[1]);
65 cerr << argv[0] << " <file>" << endl;
70 cerr << "Can not open \""
78 while(nb_lines < nb_lines_max && !file.eof()) {
79 file.getline(buffer, buffer_size);
80 lines[nb_lines] = new char[strlen(buffer) + 1];
81 strcpy(lines[nb_lines], buffer);
85 char regexp[buffer_size]="";
89 initscr(); // Necessary to start a curses session
92 cout << "You can use color on this terminal" << endl;
94 cout << "No colors." << endl;
98 noecho(); // I don't want echo when I press a key
99 curs_set(0); // I don't want to see the cursor
101 start_color(); // We will use colors
102 init_pair(1, COLOR_RED, COLOR_BLACK); // red on black for error messages
104 // attron(COLOR_PAIR(1)); // Let's print something in red on black
105 // printw("Hello world\n"); // That's how we print something!
106 // attroff(COLOR_PAIR(1)); // Let's get back to default colors!
108 printw("Press a key to contine\n");
112 build_display(nb_lines, lines, regexp);
114 if(key >= 'a' && key <= 'z') {
115 regexp[regexp_point++] = key;
116 regexp[regexp_point] = '\0';
120 echo(); // We want to have echo
121 curs_set(1); // We want to see the cursor again
122 endwin(); // Back to normal
124 for(int l = 0; l < nb_lines; l++) {