GetLine.h

Go to the documentation of this file.
00001 #ifndef __GETLINE_H__
00002 #define __GETLINE_H__
00003 
00004 /*
00005 
00006 $Header$
00007 
00008 */
00009 
00010 #include "Object.h"
00011 
00012 static const unsigned int GL_LIMIT_BUFFER_SIZE      = 1024;
00013 static const unsigned int GL_LIMIT_HISTORY_SIZE     = 100;
00014 static const unsigned int GL_LIMIT_SEARCH_SIZE      = 100;
00015 static const unsigned int GL_LIMIT_PROMPT_SIZE      = 80;
00016 static const unsigned int GL_LIMIT_MIN_SCREEN_WIDTH = 21;
00017 
00018 static const unsigned int GL_DEFAULT_TERM_WIDTH = 80;
00019 static const unsigned int GL_DEFAULT_SCROLL     = 27;
00020 
00021 // Errors.
00022 static const char *const ERROR_GETLINE_WRONG_SCREEN_WIDTH    = "Wrong screen width (%d).";
00023 static const char *const ERROR_GETLINE_INPUT_BUFFER_OVERFLOW = "Input buffer overflow.";
00024 static const char *const ERROR_GETLINE_MISSING_HANDLER       = "Missing mandatory handler.";
00025 
00026 typedef enum
00027 {
00028   GL_MODE_NORMAL,
00029   GL_MODE_ESC,
00030   GL_MODE_SQ_PAR
00031 } GlInputMode;
00032 
00033 class GetLine : public Object
00034 {
00035 
00036   PYLON_OBJECT
00037 
00038 public:
00039 
00040   GetLine();
00041   virtual ~GetLine();
00042 
00043   int historyAdd(char *line);
00044   int setWidth(const int width);
00045   int setPrompt(const char *prompt);
00046   int pushChar(char c);
00047 
00048 protected:
00049 
00050   virtual int onTab(char *buffer, const int promptWidth, int *cursorLoc, int *i);
00051   virtual int onInput(const char *buffer);
00052   virtual int onOutput(const char *buf) = 0;
00053   virtual int onPutc(const char c) = 0;
00054   virtual int onPuts(const char *buf) = 0;
00055   virtual unsigned int onStrlen(const char *str);
00056 
00057   String prompt() const;
00058 
00059 private:
00060 
00061   void init();        // Prepare to edit a line.
00062   void cleanup();     // To undo _gl_init.
00063   void charInit();    // Get ready for no echo input.
00064   void charCleanup(); // Undo char_init.
00065 
00066   void addChar(int c); // Install specified char.
00067   void del(int loc);   // Del, either left (-1) or cur (0).
00068   void fixup(char *prompt, int change, int cursor); // Fixup state variables and screen.
00069   void kill(int pos);  // Delete to EOL.
00070   void newLine();      // Handle \n or \r.
00071   void redraw();       // Issue \n and redraw all.
00072   void transpose();    // Transpose two chars.
00073   void yank();         // Yank killed text.
00074   void word(int dir);  // Move a word.
00075 
00076   void histInit();       // Initializes hist pointers.
00077   void histCleanup();    // Initializes hist pointers.
00078   char *histNext();      // Return ptr to next item.
00079   char *histPrev();      // Return ptr to prev item.
00080   char *histSave(char *p);          // Makes copy of a String, without NL.
00081 
00082   void searchUpdate(int c);
00083   void searchAddChar(int c); // Increment search String.
00084   void searchTerm();         // Reset with current contents.
00085   void searchBack(int n);    // Look back for current String.
00086   void searchForw(int n);    // Look forw for current String.
00087 
00088   int _prevNl;                         // Previuos input char was newline.
00089   int _prevCr;                         // Previuos input char was CR.
00090   GlInputMode _mode;                   // Current input mode.
00091   int _initDone;                       // Terminal mode flag.
00092   int _termW;                          // Actual terminal width.
00093   int _scroll;                         // Width of EOL scrolling region.
00094   int _extent;                         // How far to redraw, 0 means all.
00095   int _width;                          // Net size available for input.
00096   int _extent0;                        // How far to redraw, 0 means all.
00097   int _overwrite;                      // Overwrite mode.
00098   int _pos;                            // Position of input.
00099   int _cnt;                            // Size of input.
00100   char _buf[GL_LIMIT_BUFFER_SIZE];     // Input buffer.
00101   char _killBuf[GL_LIMIT_BUFFER_SIZE]; // Killed text.
00102   char _prompt[GL_LIMIT_PROMPT_SIZE];  // To save the prompt String.
00103   int _searchMode;                     // Search mode flag.
00104   int _shift;                          // Index of first on screen character.
00105   int _offRight;                       // True if more text right of screen.
00106   int _offLeft;                        // True if more text left of screen.
00107   char _lastPrompt[GL_LIMIT_PROMPT_SIZE];
00108 
00109   int _histPos;
00110   int _histLast;
00111   char *_histPrevEntry;
00112   char *_histBuf[GL_LIMIT_HISTORY_SIZE];
00113 
00114   char _searchPrompt[GL_LIMIT_SEARCH_SIZE + 1]; // Prompt includes search String.
00115   char _searchString[GL_LIMIT_SEARCH_SIZE];
00116   int _searchPos;                               // Current location in search_string.
00117   int _searchForwFlg;                           // Search direction flag.
00118   int _searchLast;                              // Last match found.
00119 };
00120 
00121 #endif

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1