-
Notifications
You must be signed in to change notification settings - Fork 4
/
ReplWidget.h
58 lines (45 loc) · 1.3 KB
/
ReplWidget.h
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
#ifndef TERMINALWIDGET_H
#define TERMINALWIDGET_H
#include <QtGui/QPlainTextEdit>
#include <QKeyEvent>
#include <QTextBlock>
#include <QTextCursor>
#include <QTextDocumentFragment>
#include <QStack>
class ReplWidget : public QPlainTextEdit
{
Q_OBJECT
public:
ReplWidget(QWidget *parent = 0);
QString prompt() const;
void setPrompt(const QString &prompt);
protected:
void keyPressEvent(QKeyEvent *e);
// Do not handle other events
void mousePressEvent(QMouseEvent *) { /* Ignore */ }
void mouseDoubleClickEvent(QMouseEvent *) { /* Ignore */ }
void mouseMoveEvent(QMouseEvent *) { /* Ignore */ }
void mouseReleaseEvent(QMouseEvent *) { /* Ignore */ }
private:
void handleLeft(QKeyEvent *event);
void handleEnter();
void handleHistoryUp();
void handleHistoryDown();
void handleHome();
void moveToEndOfLine();
void clearLine();
QString getCommand() const;
int getIndex (const QTextCursor &crQTextCursor );
QString userPrompt;
QStack<QString> historyUp;
QStack<QString> historyDown;
bool locked, historySkip;
// The command signal is fired when a user input is entered
signals:
void command(QString command);
// The result slot displays the result of a command in the terminal
public slots:
void result(QString result);
void append(QString text);
};
#endif