00001 // ===================================================================== 00028 // ===================================================================== 00029 #ifndef CLDAQ__TTERMINALUSERINTERFACE_HH 00030 #define CLDAQ__TTERMINALUSERINTERFACE_HH 00031 00032 #include "Tglobals.h" 00033 #include "TUserInterface.hh" 00034 00035 00055 class TTerminalUserInterface 00056 : public TUserInterface 00057 { 00058 00059 private: 00060 Tint theCommandHistoryIndex; 00061 Tint theCursorPosition; 00062 Tstring thePrompt; 00063 Tstring theAcceptString; 00064 Tstring theStringBuffer; 00065 Tstring theCommandBuffer; 00066 struct termios theTerminal; 00067 00068 public: 00069 TTerminalUserInterface( const Tstring& prompt = Tprompt, 00070 const Tstring& history = Tproject + ".last" ); 00071 ~TTerminalUserInterface(); 00072 00073 public: 00074 Tbool AcceptCommand(); 00075 const Tstring& GetInputCommand(); 00076 Tvoid NotFoundCommand( const Tstring& commandname ) const; 00077 00078 public: 00079 Tint GetCommandHistoryIndex() const; 00080 Tint GetCursorPosition() const; 00081 const Tstring& GetPrompt() const; 00082 const Tstring& GetAcceptString() const; 00083 const Tstring& GetStringBuffer() const; 00084 const Tstring& GetCommandBuffer() const; 00085 Tvoid SetCursorPosition( Tint position ); 00086 Tvoid SetPrompt( const Tstring& prompt ); 00087 Tvoid SetAcceptString( const Tstring& accept ); 00088 Tvoid SetStringBuffer( const Tstring& buffer ); 00089 Tvoid SetCommandBuffer( const Tstring& buffer ); 00090 Tvoid SetCommandHistoryIndex( Tint index ); 00091 00092 protected: 00093 const Tstring& readLine(); 00094 Tvoid initializeCommandLine(); 00095 Tvoid insertCharacter( Tchar cc ); 00096 Tvoid backspaceCharacter(); 00097 Tvoid deleteCharacter(); 00098 Tvoid clearLine(); 00099 Tvoid clearScreen(); 00100 Tvoid clearAfterCursor(); 00101 Tvoid forwardCursor(); 00102 Tvoid backwardCursor(); 00103 Tvoid moveCursorTop(); 00104 Tvoid moveCursorEnd(); 00105 Tvoid nextCommand(); 00106 Tvoid previousCommand(); 00107 Tvoid completeCommand(); 00108 Tvoid complete(); 00109 Tvoid complete( const Tstring& input ); 00110 Tvoid complete( const TstringList& inputs ); 00111 Tvoid completeDirectory(); 00112 Tvoid completeDirectory( const Tstring& input ); 00113 Tvoid cutCharacter(); 00114 Tvoid pasteCharacter(); 00115 Tvoid suspendTerminal() const; 00116 Tvoid setTerminalInputMode(); 00117 Tvoid resetTerminal(); 00118 Tbool isCursorEnd() const; 00119 Tbool isCursorTop() const; 00120 TstringList divide( const Tstring& input ) const; 00121 00122 #ifdef __CLDAQ_ROOT_DLL 00123 ClassDef(TTerminalUserInterface,0) 00124 #endif 00125 00126 }; 00127 00128 inline Tint TTerminalUserInterface::GetCommandHistoryIndex() const 00129 { 00130 return theCommandHistoryIndex; 00131 } 00132 00133 inline Tvoid TTerminalUserInterface::SetCommandHistoryIndex( Tint index ) 00134 { 00135 theCommandHistoryIndex = index; 00136 return; 00137 } 00138 00139 inline Tint TTerminalUserInterface::GetCursorPosition() const 00140 { 00141 return theCursorPosition; 00142 } 00143 00144 inline const Tstring& TTerminalUserInterface::GetPrompt() const 00145 { 00146 return thePrompt; 00147 } 00148 00149 inline const Tstring& TTerminalUserInterface::GetAcceptString() const 00150 { 00151 return theAcceptString; 00152 } 00153 00154 inline const Tstring& TTerminalUserInterface::GetStringBuffer() const 00155 { 00156 return theStringBuffer; 00157 } 00158 00159 inline const Tstring& TTerminalUserInterface::GetCommandBuffer() const 00160 { 00161 return theCommandBuffer; 00162 } 00163 00164 inline Tvoid TTerminalUserInterface::SetCursorPosition( Tint position ) 00165 { 00166 theCursorPosition = position; 00167 return; 00168 } 00169 00170 inline Tvoid TTerminalUserInterface::SetPrompt( const Tstring& prompt ) 00171 { 00172 thePrompt = prompt; 00173 return; 00174 } 00175 00176 inline Tvoid TTerminalUserInterface::SetAcceptString( const Tstring& accept ) 00177 { 00178 theAcceptString = accept; 00179 return; 00180 } 00181 00182 inline Tvoid TTerminalUserInterface::SetStringBuffer( const Tstring& buffer ) 00183 { 00184 theStringBuffer = buffer; 00185 return; 00186 } 00187 00188 inline Tvoid TTerminalUserInterface::SetCommandBuffer( const Tstring& buffer ) 00189 { 00190 theCommandBuffer = buffer; 00191 return; 00192 } 00193 00194 inline Tbool TTerminalUserInterface::isCursorEnd() const 00195 { 00196 return ( theCursorPosition == (Tint)( theAcceptString.size() ) ) ? Ttrue : Tfalse; 00197 } 00198 00199 inline Tbool TTerminalUserInterface::isCursorTop() const 00200 { 00201 return ( theCursorPosition == 0 ) ? Ttrue : Tfalse; 00202 } 00203 00204 #endif