Skip to content

Latest commit

 

History

History
164 lines (126 loc) · 4.3 KB

terminal.h

File metadata and controls

164 lines (126 loc) · 4.3 KB
 
Feb 20, 2013
Feb 20, 2013
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
/*
Copyright 2011-2012 Heikki Holstila <heikki.holstila@gmail.com>
This file is part of FingerTerm.
FingerTerm 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.
FingerTerm 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 FingerTerm. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TERMINAL_H
#define TERMINAL_H
#include <QtCore>
class PtyIFace;
class Util;
Jul 22, 2013
Jul 22, 2013
27
class QQuickView;
Feb 20, 2013
Feb 20, 2013
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
struct TermChar {
QChar c;
int fgColor;
int bgColor;
int attrib;
};
const int attribNone = 0;
const int attribBold = 1;
const int attribUnderline = 2;
const int attribNegative = 4;
const QByteArray multiCharEscapes("().*+-/%#");
struct TermAttribs {
QPoint cursorPos;
bool wrapAroundMode;
bool originMode;
int currentFgColor;
int currentBgColor;
int currentAttrib;
};
class Terminal : public QObject
{
Q_OBJECT
public:
static const int defaultFgColor = 7;
static const int defaultBgColor = 0;
explicit Terminal(QObject *parent = 0);
virtual ~Terminal() {}
Jun 8, 2016
Jun 8, 2016
62
Feb 20, 2013
Feb 20, 2013
63
void setPtyIFace(PtyIFace* pty);
Jul 22, 2013
Jul 22, 2013
64
void setWindow(QQuickView* win) { iWindow=win; }
Feb 20, 2013
Feb 20, 2013
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
void setUtil(Util* util) { iUtil = util; }
void insertInBuffer(const QString& chars);
QPoint cursorPos();
void setCursorPos(QPoint pos);
bool showCursor();
Q_INVOKABLE QSize termSize() { return iTermSize; }
void setTermSize(QSize size);
QList<QList<TermChar> >& buffer();
QList<QList<TermChar> >& backBuffer() { return iBackBuffer; }
QList<TermChar>& currentLine();
Oct 14, 2015
Oct 14, 2015
81
Q_INVOKABLE void keyPress(int key, int modifiers, const QString& text="");
Feb 20, 2013
Feb 20, 2013
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Q_INVOKABLE const QStringList printableLinesFromCursor(int lines);
Q_INVOKABLE void putString(QString str, bool unEscape=false);
Q_INVOKABLE void pasteFromClipboard();
Q_INVOKABLE void copySelectionToClipboard();
Q_INVOKABLE const QStringList grabURLsFromBuffer();
Q_INVOKABLE QString getUserMenuXml();
void scrollBackBufferFwd(int lines);
void scrollBackBufferBack(int lines);
int backBufferScrollPos() { return iBackBufferScrollPos; }
void resetBackBufferScrollPos();
Jun 8, 2016
Jun 8, 2016
96
void setSelection(QPoint start, QPoint end, bool selectionOngoing);
Feb 20, 2013
Feb 20, 2013
97
98
99
100
101
102
103
104
105
106
QRect selection();
Q_INVOKABLE void clearSelection();
bool hasSelection();
TermChar zeroChar;
signals:
void cursorPosChanged(QPoint newPos);
void termSizeChanged(QSize newSize);
void displayBufferChanged();
Jun 8, 2016
Jun 8, 2016
107
108
void selectionChanged();
void scrollBackBufferAdjusted(bool reset);
Jun 8, 2016
Jun 8, 2016
109
void selectionFinished();
Feb 20, 2013
Feb 20, 2013
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
private:
Q_DISABLE_COPY(Terminal)
static const char ch_ESC = 0x1B; //escape
static const int maxScrollBackLines = 300;
void insertAtCursor(QChar c, bool overwriteMode=true, bool advanceCursor=true);
void deleteAt(QPoint pos);
void clearAt(QPoint pos);
void eraseLineAtCursor(int from=-1, int to=-1);
void clearAll(bool wholeBuffer=false);
void ansiSequence(const QString& seq);
void oscSequence(const QString& seq);
void escControlChar(const QString& seq);
void trimBackBuffer();
void scrollBack(int lines, int insertAt=-1);
void scrollFwd(int lines, int removeAt=-1);
void resetTerminal();
void resetTabs();
void adjustSelectionPosition(int lines);
PtyIFace* iPtyIFace;
Jul 22, 2013
Jul 22, 2013
132
QQuickView* iWindow;
Feb 20, 2013
Feb 20, 2013
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
Util* iUtil;
QList<QList<TermChar> > iBuffer;
QList<QList<TermChar> > iAltBuffer;
QList<QList<TermChar> > iBackBuffer;
QList<QList<int> > iTabStops;
QSize iTermSize;
bool iEmitCursorChangeSignal;
bool iShowCursor;
bool iUseAltScreenBuffer;
bool iAppCursorKeys;
bool iReplaceMode;
bool iNewLineMode;
int iMarginTop;
int iMarginBottom;
int iBackBufferScrollPos;
TermAttribs iTermAttribs;
TermAttribs iTermAttribs_saved;
TermAttribs iTermAttribs_saved_alt;
QString escSeq;
QString oscSeq;
int escape;
QRect iSelection;
};
#endif // TERMINAL_H