Automatic commit
authorFrancois Fleuret <francois@fleuret.org>
Thu, 19 Feb 2009 07:08:40 +0000 (08:08 +0100)
committerFrancois Fleuret <francois@fleuret.org>
Thu, 19 Feb 2009 07:08:40 +0000 (08:08 +0100)
Makefile [new file with mode: 0644]
selector.cc [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..3136365
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,3 @@
+
+all: selector.cc
+       g++ -lncurses -o selector selector.cc
diff --git a/selector.cc b/selector.cc
new file mode 100644 (file)
index 0000000..ab793b0
--- /dev/null
@@ -0,0 +1,112 @@
+
+///////////////////////////////////////////////////////////////////////////
+// START_IP_HEADER                                                       //
+//                                                                       //
+// This program is free software: you can redistribute it and/or modify  //
+// it under the terms of the version 3 of the GNU General Public License //
+// as published by the Free Software Foundation.                         //
+//                                                                       //
+// This program is distributed in the hope that it will be useful, but   //
+// WITHOUT ANY WARRANTY; without even the implied warranty of            //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      //
+// General Public License for more details.                              //
+//                                                                       //
+// You should have received a copy of the GNU General Public License     //
+// along with this program. If not, see <http://www.gnu.org/licenses/>.  //
+//                                                                       //
+// Written by and Copyright (C) Francois Fleuret                         //
+// Contact <francois.fleuret@idiap.ch> for comments & bug reports        //
+//                                                                       //
+// END_IP_HEADER                                                         //
+///////////////////////////////////////////////////////////////////////////
+
+#include <stdio.h>
+#include <ncurses.h>
+#include <iostream>
+#include <fstream>
+#include <string.h>
+
+using namespace std;
+
+void build_display(char **choices, char *regexp) {
+  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);
+  }
+  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];
+
+  ifstream file(argv[1]);
+
+  if(argc != 2) {
+    cerr << argv[0] << " <file>" << endl;
+    return 1;
+  }
+
+  if(file.fail()) {
+    cerr << "Can not open \""
+         << argv[1]
+         << "\""
+         << endl;
+    return 1;
+  }
+
+  int nb_lines = 0;
+  while(nb_lines < nb_lines_max && !file.eof()) {
+    file.getline(buffer, buffer_size);
+    lines[nb_lines] = new char[strlen(buffer) + 1];
+    strcpy(lines[nb_lines], buffer);
+  }
+
+  char regexp[buffer_size]="";
+  int regexp_point;
+  regexp_point = 0;
+
+  initscr();        // Necessary to start a curses session
+
+  if (has_colors()) {
+    cout << "You can use color on this terminal" << endl;
+  } else {
+    cout << "No colors." << endl;
+    return 1;
+  }
+
+  noecho();        // I don't want echo when I press a key
+  curs_set(0);     // I don't want to see the cursor
+
+  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!
+
+  printw("Press a key to contine\n");
+  int key;
+
+  do {
+    build_display(0, regexp);
+    key = getch();
+    regexp[regexp_point++] = key;
+    regexp[regexp_point] = '\0';
+  } while(key != 'q');
+
+  echo();         // We want to have echo
+  curs_set(1);    // We want to see the cursor again
+  endwin();       // Back to normal
+
+  for(int l = 0; l < nb_lines; l++) {
+    delete[] lines[l];
+  }
+
+  return 0;
+}