Subversion Repositories Kolibri OS

Rev

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

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