|
1 // line_editor.h |
|
2 // |
|
3 // Copyright (c) 2006 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #ifndef __LINE_EDITOR_H__ |
|
14 #define __LINE_EDITOR_H__ |
|
15 |
|
16 #include <e32std.h> |
|
17 #include <e32base.h> |
|
18 #include <e32keys.h> |
|
19 #include <fshell/line_editor_observer.h> |
|
20 #include <fshell/abstract_console_writer.h> |
|
21 #include <fshell/ioutils.h> |
|
22 |
|
23 const TInt KMaxLineLength = 256; |
|
24 #define CTRL(x) ((x)-'a'+1) |
|
25 |
|
26 class CLineHistory; |
|
27 |
|
28 // |
|
29 // MConsoleScrollObserver. |
|
30 // |
|
31 |
|
32 class MConsoleScrollObserver |
|
33 { |
|
34 public: |
|
35 virtual void CsoHandleConsoleScrolled() = 0; |
|
36 }; |
|
37 |
|
38 // |
|
39 // RConsole. |
|
40 // |
|
41 |
|
42 class RConsole |
|
43 { |
|
44 public: |
|
45 enum TCursorMode |
|
46 { |
|
47 EInsert, |
|
48 EOverwrite |
|
49 }; |
|
50 public: |
|
51 RConsole(MAbstractConsoleWriter& aStdout); |
|
52 void Close(); |
|
53 void Start(); |
|
54 void Refresh(); |
|
55 void Write(const TDesC& aDes); |
|
56 void SetCursorPosAbs(const TPoint& aPoint); |
|
57 void SetCursorPosRel(const TPoint& aPoint); |
|
58 void MoveCursorLeft(); |
|
59 void MoveCursorRight(); |
|
60 void NewLine(); |
|
61 void SetCursorMode(TCursorMode aMode); |
|
62 void SetCursorVisible(TBool aVisible); |
|
63 void ClearToEndOfLine(); |
|
64 void Clear(); |
|
65 TPoint PosFrom(const TPoint& aStartPos, TInt aLength) const; |
|
66 TPoint CursorPos() const; |
|
67 TInt AddObserver(MConsoleScrollObserver& aObserver); |
|
68 void RemoveObserver(MConsoleScrollObserver& aObserver); |
|
69 TSize Size() const; |
|
70 private: |
|
71 void CursorLeft(); |
|
72 void CursorRight(); |
|
73 void LineFeed(); |
|
74 void CarriageReturn(); |
|
75 void NotifyScrollObservers(); |
|
76 private: |
|
77 TSize iSize; |
|
78 MAbstractConsoleWriter& iStdout; |
|
79 RPointerArray<MConsoleScrollObserver> iScrollObservers; |
|
80 TPoint iCursorPos; |
|
81 TCursorMode iCursorMode; |
|
82 TBool iCursorVisible; |
|
83 }; |
|
84 |
|
85 |
|
86 // |
|
87 // TConsoleLine. |
|
88 // |
|
89 |
|
90 class TConsoleLine : public MConsoleScrollObserver |
|
91 { |
|
92 public: |
|
93 IMPORT_C TConsoleLine(RConsole& aConsole); |
|
94 IMPORT_C void Start(const TDesC& aPrompt); |
|
95 IMPORT_C void Start(const TDesC& aPrompt, const TDesC& aInitialInput); |
|
96 IMPORT_C void Replace(const TDesC& aDes); |
|
97 IMPORT_C void Replace(TInt aFrom, const TDesC& aDes); |
|
98 IMPORT_C void Insert(TChar aChar); |
|
99 IMPORT_C void Overwrite(TChar aChar); |
|
100 IMPORT_C void Redraw(); |
|
101 IMPORT_C void End(); |
|
102 IMPORT_C void DeleteLeft(); |
|
103 IMPORT_C void DeleteRight(); |
|
104 IMPORT_C void CursorLeft(); |
|
105 IMPORT_C void CursorRight(); |
|
106 IMPORT_C void CursorPreviousWord(); |
|
107 IMPORT_C void CursorNextWord(); |
|
108 IMPORT_C void CursorBeginning(); |
|
109 IMPORT_C void CursorEnd(); |
|
110 IMPORT_C void PrintCompletionPossibilitiesL(const TDesC& aPossibilities); |
|
111 IMPORT_C TPtrC Contents() const; |
|
112 IMPORT_C TPtrC ContentsToCursor() const; |
|
113 public: |
|
114 void Hide(); |
|
115 void Show(); |
|
116 void SetCursorPosition(TInt aPosition); |
|
117 void Abort(); |
|
118 private: |
|
119 void Restart(const TDesC& aPrompt); |
|
120 private: // From MConsoleScrollObserver. |
|
121 virtual void CsoHandleConsoleScrolled(); |
|
122 private: |
|
123 RConsole& iConsole; |
|
124 TBuf<KMaxLineLength> iBuf; |
|
125 TInt iPromptLength; |
|
126 TInt iBufPos; |
|
127 TPoint iStartPos; |
|
128 TBool iStarted; |
|
129 TBool iHidden; |
|
130 }; |
|
131 |
|
132 |
|
133 // |
|
134 // CLineEditor. |
|
135 // |
|
136 |
|
137 class CLineEditor : public CBase |
|
138 { |
|
139 public: |
|
140 IMPORT_C static CLineEditor* NewL( RFs& aFs, |
|
141 MAbstractConsoleWriter& aStdout, |
|
142 MLineEditorObserver& aObserver, |
|
143 MLineCompleter& aCompleter, |
|
144 const TDesC& aConsoleHistoryFile); |
|
145 IMPORT_C ~CLineEditor(); |
|
146 IMPORT_C void HandleKey(TUint aKeyCode, TUint aModifiers); |
|
147 IMPORT_C void Start(const TDesC& aPrompt); |
|
148 IMPORT_C void Start(const TDesC& aPrompt, const TDesC& aInitialInput); |
|
149 IMPORT_C void Abort(); |
|
150 |
|
151 IMPORT_C void Redraw(); |
|
152 IMPORT_C void RemovePromptAndUserInput(); |
|
153 IMPORT_C void ReinstatePromptAndUserInput(); |
|
154 private: |
|
155 CLineEditor(MAbstractConsoleWriter& aStdout, MLineEditorObserver& aObserver, MLineCompleter& aCompleter); |
|
156 void ConstructL(RFs& aFs, const TDesC& aConsoleHistoryFile); |
|
157 void InsertChar(TChar aChar); |
|
158 void HandleEnter(); |
|
159 void HandleBackspace(); |
|
160 void HandleTab(); |
|
161 void HandleTabL(); |
|
162 void HandleDelete(); |
|
163 void HandleLeftArrow(); |
|
164 void HandleRightArrow(); |
|
165 void HandleUpArrow(); |
|
166 void HandleDownArrow(); |
|
167 void HandlePreviousWord(); |
|
168 void HandleNextWord(); |
|
169 void HandleHome(); |
|
170 void HandleEnd(); |
|
171 void HandlePageUp(); |
|
172 void HandlePageDown(); |
|
173 void HandleInsert(); |
|
174 void HandleEscape(); |
|
175 void HandleF8Completion(); // DOS-style F8 line completion |
|
176 void ReplaceLine(const TDesC& aNewLine); |
|
177 private: |
|
178 enum TState |
|
179 { |
|
180 EIdle, |
|
181 EEditing, |
|
182 ERecallingHistory |
|
183 }; |
|
184 enum TMode |
|
185 { |
|
186 EInsert, |
|
187 EOverwrite |
|
188 }; |
|
189 private: |
|
190 void SetState(TState aState); |
|
191 private: |
|
192 MLineEditorObserver& iObserver; |
|
193 MLineCompleter& iCompleter; |
|
194 RConsole iConsole; |
|
195 TConsoleLine iLine; |
|
196 TBuf<KMaxLineLength> iLineBackup; |
|
197 CLineHistory* iHistory; |
|
198 TState iState; |
|
199 TMode iMode; |
|
200 }; |
|
201 |
|
202 |
|
203 #endif // __LINE_EDITOR_H__ |