read_experiment.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <cxxtls/cursorwindow.h>
00030 #include <portable_io.h>
00031 #include <stdlib.h>
00032 #include <signal.h>
00033 #include <unistd.h>
00034 #include <cxxtls/sequence_map.h>
00035 #include <curses.h>
00036 #include <term.h>
00037 #include <string.h>
00038 #include <termios.h>
00039
00040 using namespace std;
00041 using namespace cxxtls;
00042
00043 namespace CursesInterface
00044 {
00045 extern int read_mapped_key(CursorWindow&);
00046 extern bool winch_occurred;
00047 };
00048
00049 class ResizeHandler
00050 : public CursorWindow::resize_handler
00051 {
00052 public:
00053
00054 void operator() (CursorWindow* w)
00055 {
00056
00057
00058 CursorWindow::row_col size = w->size();
00059
00060 w->set_text_attribute(CursorWindow::normal);
00061
00062 if(size.row_ < 1 || size.row_ > 200)
00063 cout << "window rows is way off" << endl;
00064
00065 if(size.col_ < 1 || size.col_ > 200)
00066 cout << "window cols is way off" << endl;
00067
00068 int i;
00069
00070 for(i=0; i < size.row_; ++i)
00071 {
00072 char buffer[40];
00073
00074 sprintf(buffer, "row %d", i);
00075
00076 w->set_curpos(i,0);
00077
00078 w->write(buffer);
00079
00080 }
00081
00082
00083 w->set_text_attribute(CursorWindow::reversed);
00084
00085 w->set_curpos(0,0);
00086 w->write("*");
00087 w->set_curpos(size.row_-1, 0);
00088 w->write("*");
00089 w->set_curpos(0, size.col_-1);
00090 w->write("*");
00091 w->set_curpos(size.row_-1, size.col_-1);
00092 w->write("*");
00093
00094 w->set_curpos(10,10);
00095
00096 }
00097 };
00098
00099
00100
00101 int main()
00102 {
00103 CursorWindow w;
00104
00105 w.open();
00106
00107 ResizeHandler h;
00108
00109 h(&w);
00110
00111 w.set_resize_handler(&h);
00112
00113
00114 w.set_curpos(0,0);
00115 w.write("press a key");
00116
00117 CursesInterface::winch_occurred=false;
00118
00119 for(;;)
00120 {
00121 int code = CursesInterface::read_mapped_key(w);
00122 CursesInterface::winch_occurred=false;
00123
00124 w.set_text_attribute(CursorWindow::normal);
00125 w.write(CursorWindow::key_name(code));
00126
00127 {
00128 static int count=0;
00129
00130 ++count;
00131
00132 char tmp[40];
00133
00134 sprintf(tmp, " [%d]", count);
00135
00136 w.write(tmp);
00137
00138
00139 }
00140
00141 if(code == ' ')
00142 break;
00143
00144 }
00145
00146
00147 }
00148
00149
00150