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
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "terminal_global.h"
#include "celliterator.h"
#include <QKeyEvent>
#include <QSize>
#include <QTextCharFormat>
#include <memory>
namespace TerminalSolution {
class Scrollback;
class SurfaceIntegration;
struct TerminalSurfacePrivate;
enum ColorIndex { Foreground = 16, Background = 17 };
struct TerminalCell
{
int width;
QString text;
bool bold{false};
bool italic{false};
std::variant<int, QColor> foregroundColor;
std::variant<int, QColor> backgroundColor;
QTextCharFormat::UnderlineStyle underlineStyle{QTextCharFormat::NoUnderline};
bool strikeOut{false};
};
struct Cursor
{
enum class Shape {
Block = 1,
Underline,
LeftBar,
};
QPoint position;
bool visible;
Shape shape;
bool blink{false};
};
class TERMINAL_EXPORT TerminalSurface : public QObject
{
Q_OBJECT;
public:
TerminalSurface(QSize initialGridSize);
~TerminalSurface();
public:
CellIterator begin() const;
CellIterator end() const;
std::reverse_iterator<CellIterator> rbegin() const;
std::reverse_iterator<CellIterator> rend() const;
CellIterator iteratorAt(QPoint pos) const;
CellIterator iteratorAt(int pos) const;
std::reverse_iterator<CellIterator> rIteratorAt(QPoint pos) const;
std::reverse_iterator<CellIterator> rIteratorAt(int pos) const;
public:
void clearAll();
void resize(QSize newSize);
TerminalCell fetchCell(int x, int y) const;
std::u32string::value_type fetchCharAt(int x, int y) const;
int cellWidthAt(int x, int y) const;
QSize liveSize() const;
QSize fullSize() const;
QPoint posToGrid(int pos) const;
int gridToPos(QPoint gridPos) const;
void dataFromPty(const QByteArray &data);
void flush();
void pasteFromClipboard(const QString &text);
void sendKey(Qt::Key key);
void sendKey(QKeyEvent *event);
void sendKey(const QString &text);
int invertedScrollOffset() const;
Cursor cursor() const;
SurfaceIntegration *surfaceIntegration() const;
void setSurfaceIntegration(SurfaceIntegration *surfaceIntegration);
using WriteToPty = std::function<qint64(const QByteArray &)>;
void setWriteToPty(WriteToPty writeToPty);
void mouseMove(QPoint pos, Qt::KeyboardModifiers modifiers);
void mouseButton(Qt::MouseButton button, bool pressed, Qt::KeyboardModifiers modifiers);
void sendFocus(bool hasFocus);
bool isInAltScreen();
void enableLiveReflow(bool enable);
signals:
void invalidated(QRect grid);
void fullSizeChanged(QSize newSize);
void cursorChanged(Cursor oldCursor, Cursor newCursor);
void altscreenChanged(bool altScreen);
void unscroll();
void cleared();
private:
std::unique_ptr<TerminalSurfacePrivate> d;
};
} // namespace TerminalSolution
|