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