1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*
* Copyright (c) 2002-2006 Samit Basu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __KeyManager_hpp__
#define __KeyManager_hpp__
#include <list>
#include "Scope.hpp"
#include <QEventLoop>
#include "Context.hpp"
#define KM_CTRLA 0x01
#define KM_CTRLB 0x02
#define KM_CTRLZ 0x1A
#define KM_CTRLD 0x04
#define KM_CTRLE 0x05
#define KM_TAB 0x09
#define KM_CTRLK 0x0b
#define KM_CTRLW 0x17
#define KM_CTRLY 0x19
#define KM_BACKSPACE 0x08
#define KM_BACKSPACEALT 0x7f
#define KM_ESC 0x1b
#define KM_NEWLINE 0x0d
#define KM_LEFT 0x101
#define KM_RIGHT 0x102
#define KM_UP 0x103
#define KM_DOWN 0x104
#define KM_DELETE 0x108
#define KM_INSERT 0x105
#define KM_HOME 0x106
#define KM_END 0x107
class KeyManager : public QObject
{
Q_OBJECT
public:
KeyManager();
virtual ~KeyManager();
void Redisplay();
void setTerminalWidth(int w);
void AddCharToLine(QChar c);
void ReplacePrompt(QString prmt);
int DisplayPrompt();
void OutputChar(QChar c, QChar pad);
void OutputString(QString msg, QChar c);
void TerminalMove(int n);
void SetTermCurpos(int n);
void PlaceCursor(int n);
int DisplayedCharWidth(QChar c, int aterm_curpos);
int DisplayedStringWidth(QString s, int nc, int offset);
int BuffCurposToTermCurpos(int n);
void DeleteChars(int nc, int cut);
void TruncateDisplay();
void EndOfLine();
void KillLine();
int getTerminalWidth();
void RegisterTerm(QObject* term);
void SetCompletionContext(Context* ctxt);
Context* GetCompletionContext();
void getKeyPress();
private:
Context *context;
StringVector GetCompletions(QString line, int word_end,
QString &matchString);
void CursorLeft();
void CursorRight();
void BeginningOfLine();
void BackwardDeleteChar();
void ForwardDeleteChar();
void HistorySearchBackward();
void HistorySearchForward();
void AddHistory(QString line);
void HistoryFindForwards();
void HistoryFindBackwards();
void AddStringToLine(QString s);
void SearchPrefix(QString aline, int alen);
void Yank();
void ClearCurrentLine();
void ListCompletions(StringVector completions);
void CompleteWord();
protected:
void EraseCharacters(int pos, int count);
void InsertCharacter(int pos, QChar c);
void SetCharacter(int pos, QChar c);
void InsertString(int pos, QString s);
void NewLine();
void ResetLineBuffer();
StringVector enteredLines;
bool enteredLinesEmpty;
// the size (in text coords) of the window
int nline;
int ncolumn;
// the text
StringVector history;
// The new line buffer
QString lineData;
// The maximum allowed line length
int linelen;
// The cut buffer
QString cutbuf;
// number of characters in line
int ntotal;
// Current position in the buffer
int buff_curpos;
// Current position on the terminal
int term_curpos;
// Number of characters used to display the current input line
int term_len;
// Marker location in the buffer
int buff_mark;
// Cursor position at start of insert
int insert_curpos;
int keyseq_count;
int last_search;
QString prefix;
int prefix_len;
// True in insert mode
bool insert;
int startsearch;
// The prompt
QString prompt;
// length of the prompt string
int prompt_len;
// Are we waiting for input?
int loopactive;
// Are we waiting for a key press
bool keypresswait;
signals:
void CWDChanged();
void UpdateCWD(QString);
void updateDirView(QVariant);
void updateVarView(QVariant);
void updateStackView(QStringList);
void MoveDown();
void MoveUp();
void MoveRight();
void MoveLeft();
void ClearEOL();
void ClearEOD();
void MoveBOL();
void ClearDisplay();
void OutputRawString(QString txt);
void SendCommand(QString);
void Interrupt();
void UpdateInfoViews();
void ExecuteLine(QString txt);
void PopCompletions(QStringList txt);
public slots:
void Ready();
void ClearHistory();
void WriteHistory();
void OnChar( int c );
void SetTermWidth(int w);
void QueueString(QString);
void QueueMultiString(QString);
void QueueCommand(QString);
void QueueSilent(QString);
void ContinueAction();
void StopAction();
void DbStepAction();
void DbTraceAction();
void SetPrompt(QString);
void ClearDisplayCommand();
void ChangeDir(const QString& dir);
void PlaceCursorDXDY(int dx, int dy);
void updateStackDepth(int);
signals:
void UpdateTermWidth(int);
void RegisterInterrupt();
};
#endif
|