read_experiment.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // Copyright 2002, Lowell Boggs Jr.
00004 //
00005 // This file or directory, containing source code for a computer program,
00006 // is Copyrighted by Lowell Boggs, Jr.  987 Regency Drive, Lewisville
00007 // TX (USA), 75067.  You may use, copy, modify, and distribute this
00008 // source file without charge or obligation so long as you agree to
00009 // the following:
00010 //
00011 //  1.  You must indemnify Lowell Boggs against any and all financial
00012 //      obligations caused by its use, misuse, function, or malfunction.
00013 //      Further, you acknowledge that there is no warranty of any kind,
00014 //      whatsoever.
00015 //
00016 //  2.  You agree not to attempt to patent any portion of this original
00017 //      work -- though you may attempt to patent your own extensions to
00018 //      it if you so choose.
00019 //
00020 //  3.  You keep this copyright notice with the file and all copies
00021 //      of the file and do not change it anyway except language translation.
00022 //
00023 // You are responsible for enforcing your own compliance with these
00024 // conditions and may not use this source file if you cannot agree to the
00025 // above terms and conditions.
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      // paint the window
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 
Generated on Wed Feb 29 22:50:05 2012 for CXXUtilities by  doxygen 1.6.3