Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1.  
  2. /** \file commandline.h
  3.  *  Implementation of a platform-independent command line with history.
  4.  *
  5.  *  The class CCommandLine has two roles:
  6.  *  1) It has an outside interface, ReadLine(), that yields to the
  7.  *     system until the user is finished entering an expression at
  8.  *     the command line. The result can be found in iLine.
  9.  *  2) It defines a mini-API needed to implement the command line.
  10.  *     For each platform Yacas is meant to run on there should be a
  11.  *     CCommandLine-derived class if this functionality is to be used.
  12.  *
  13.  */
  14.  
  15. #ifndef __commandline_h__
  16. #define __commandline_h__
  17.  
  18. #include "lispstring.h"
  19. #include "yacasbase.h"
  20.  
  21. enum ESpecialChars
  22. {
  23.     eDelete     = 0x1000,
  24.     eBackSpace,
  25.     eLeft,
  26.     eRight,
  27.     eUp,
  28.     eDown,
  29.     eHome,
  30.     eEnd,
  31.     eEnter,
  32.     eTab,
  33.     eEscape
  34. };
  35.  
  36. /**
  37.  *  Implementation of a platform-independent command line with history.
  38.  *
  39.  *  The class CCommandLine has two roles:
  40.  *  1) It has an outside interface, ReadLine(), that yields to the
  41.  *     system until the user is finished entering an expression at
  42.  *     the command line. The result can be found in iLine.
  43.  *  2) It defines a mini-API needed to implement the command line.
  44.  *     For each platform Yacas is meant to run on there should be a
  45.  *     CCommandLine-derived class if this functionality is to be used.
  46.  *
  47.  *  The derived class is responsible for filling the history list,
  48.  *  and for externalizing the history list to disk when the system
  49.  *  shuts down.
  50.  */
  51.  
  52. /// \class CConsoleHistory, implement history list the user can browse through.
  53. class CConsoleHistory
  54. {
  55. public:
  56.   CConsoleHistory() : iHistory(),history(0) {}
  57.   void ResetHistoryPosition();
  58.   void AddLine(LispString& aString);
  59.   void Append(LispString * aString);
  60.   LispInt ArrowUp(LispString& aString,LispInt &aCursorPos);
  61.   LispInt ArrowDown(LispString& aString,LispInt &aCursorPos);
  62.   LispInt Complete(LispString& aString,LispInt &aCursorPos);
  63.   LispInt NrLines();
  64.   LispString * GetLine(LispInt aLine);
  65. protected:
  66.   CDeletingArrayGrower<LispString *, ArrOpsDeletingPtr<LispString> > iHistory;
  67.   LispInt history;
  68. };
  69.  
  70. class CCommandLine : public YacasBase
  71. {
  72. public:
  73.   CCommandLine() : iFullLineDirty(LispFalse),iHistoryUnchanged(0),iLine(),iSubLine(),iHistoryList() {};
  74.   virtual ~CCommandLine();
  75.   /// Call this function if the user needs to enter an expression.
  76.   virtual void ReadLine(LispChar * prompt);
  77. public: //platform stuff
  78.   /** return a key press, which is either an ascii value, or one
  79.    * of the values specified in ESpecialChars
  80.    */
  81.   virtual LispInt GetKey() = 0;
  82.   /// Go to the next line on the console (carriage return/line feed).
  83.   virtual void NewLine()   = 0;
  84.   /** Show the current line (in iSubLine), with the required prompt,
  85.    *  and the cursor position at cursor (starting from the prompt).
  86.    */
  87.   virtual void ShowLine(LispChar * prompt,
  88.                         LispInt promptlen,LispInt cursor) = 0;
  89.   /// Pause for a short while. Used when matching brackets.
  90.   virtual void Pause() = 0;
  91.  
  92.   /// Maximum number of history lines to be saved (-1 is all)
  93.   virtual void MaxHistoryLinesSaved(LispInt aNrLines);
  94.  
  95. protected:
  96.   virtual void ReadLineSub(LispChar * prompt);
  97. private:
  98.   void GetHistory(LispInt aLine);
  99.   void ShowOpen(LispChar * prompt,LispInt promptlen,
  100.                 LispChar aOpen, LispChar aClose, LispInt aCurPos);
  101. protected:
  102.   LispInt iFullLineDirty;
  103.   LispInt iHistoryUnchanged;
  104.  
  105. public:
  106.   LispString iLine;
  107.   LispString iSubLine;
  108.  
  109.   CConsoleHistory iHistoryList;
  110. };
  111.  
  112. #endif
  113.