00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __UT_CmdLineReader_h__
00024 #define __UT_CmdLineReader_h__
00025
00026 #include "UT_API.h"
00027 #include "UT_WorkBuffer.h"
00028 #include "UT_StringArray.h"
00029
00030 typedef void (*UT_TabCallback)(UT_WorkBuffer &, int &);
00031
00032 class UT_API UT_CmdLineReader
00033 {
00034 public:
00035
00036
00037
00038
00039 UT_CmdLineReader(
00040 UT_TabCallback tab_callback=NULL,
00041 UT_TabCallback double_tab_callback=NULL);
00042 ~UT_CmdLineReader();
00043
00044
00045
00046
00047
00048 bool readLine(UT_WorkBuffer &line);
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 bool readPartOfLine(UT_WorkBuffer &line, bool &done_line);
00062
00063
00064
00065 bool hasUnhandledInput() const { return myUnhandledInput.length() != 0; }
00066
00067
00068
00069
00070
00071
00072 void disableLineBuffering();
00073 void reenableLineBuffering();
00074 bool isLineBufferingEnabled() const;
00075
00076 static UT_CmdLineReader *getInstance();
00077
00078 private:
00079 void construct();
00080
00081 bool readAvailableInput(UT_WorkBuffer &buffer);
00082 bool handleNextBufferedKey(bool &done_line);
00083
00084 void insertChar(char ch);
00085 void insertString(const char *str);
00086 void removeCharBefore();
00087 void removeCharAt();
00088 void removeWordBefore();
00089
00090 void updateDisplay(const UT_WorkBuffer &old_line, int old_cursor_pos,
00091 const UT_WorkBuffer &new_line, int new_cursor_pos);
00092 int tabLengthAtPosition(int tab_start_pos);
00093 int *buildCharIndexToLengthArray(const UT_WorkBuffer &line);
00094 void printExpandedChar(
00095 char chr, int index, int *char_lengths, char replacement='\0');
00096
00097 void moveUpThroughHistory();
00098 void moveDownThroughHistory();
00099
00100
00101
00102 bool myAllowCmdLineEditing;
00103
00104
00105
00106 class TerminalData;
00107 TerminalData *myTerminalData;
00108
00109 bool myLineBufferingIsDisabled;
00110 bool myLineBufferingWasDisabled;
00111 bool myIsReadingLine;
00112 UT_WorkBuffer myLine;
00113 UT_WorkBuffer myUnhandledInput;
00114 int myCursorPos;
00115 UT_StringArray myHistory;
00116 int myHistoryIndex;
00117 UT_TabCallback myTabCallback;
00118 UT_TabCallback myDoubleTabCallback;
00119 int myTabLength;
00120 bool myJustReadTab;
00121
00122 UT_String myEscapeKey;
00123 UT_String myCtrlAKey;
00124 UT_String myCtrlDKey;
00125 UT_String myCtrlEKey;
00126 UT_String myCtrlWKey;
00127 UT_String myLeftArrowKey;
00128 UT_String myRightArrowKey;
00129 UT_String myUpArrowKey;
00130 UT_String myDownArrowKey;
00131 UT_String myBackspaceKey;
00132 UT_String myDeleteKey;
00133 UT_String myHomeKey;
00134 UT_String myEndKey;
00135
00136 static UT_CmdLineReader *theInstance;
00137 };
00138
00139 #endif