From e709c3d6192cd94251e827c430e81cc933bf56e5 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Thu, 19 Feb 2009 08:30:51 +0100 Subject: [PATCH] *** empty log message *** --- selector.cc | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/selector.cc b/selector.cc index ab793b0..0d5a30e 100644 --- a/selector.cc +++ b/selector.cc @@ -28,19 +28,33 @@ using namespace std; -void build_display(char **choices, char *regexp) { +const int buffer_size = 1024; +const int nb_lines_max = 1000; + +void build_display(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 - for(int y = 0; y < 10; y++) { - printw("y = %d\n", y); + int maxx = getmaxx(stdscr); + int maxy = getmaxy(stdscr); + printw("maxx %d maxy %d\n", maxx, maxy); + printw("nb_lines %d\n", nb_lines); + 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++; + } + buffer[k++] = '\n'; + buffer[k++] = '\0'; + printw(buffer); + nb_printed_lines++; } - printw("regexp = \"%s\"", regexp); } int main(int argc, char **argv) { int dummy, xpos, ypos; - const int buffer_size = 1024; - const int nb_lines_max = 1000; char buffer[buffer_size]; char *lines[nb_lines_max]; @@ -65,6 +79,7 @@ int main(int argc, char **argv) { file.getline(buffer, buffer_size); lines[nb_lines] = new char[strlen(buffer) + 1]; strcpy(lines[nb_lines], buffer); + nb_lines++; } char regexp[buffer_size]=""; @@ -94,10 +109,12 @@ int main(int argc, char **argv) { int key; do { - build_display(0, regexp); + build_display(nb_lines, lines, regexp); key = getch(); - regexp[regexp_point++] = key; - regexp[regexp_point] = '\0'; + if(key >= 'a' && key <= 'z') { + regexp[regexp_point++] = key; + regexp[regexp_point] = '\0'; + } } while(key != 'q'); echo(); // We want to have echo -- 2.39.5