blob: a6fc7425d486a2be3806a426d1802a02ceaae86d (
plain)
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
|
// 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 "celliterator.h"
#include "shellintegration.h"
#include <QKeyEvent>
#include <QSize>
#include <QTextCharFormat>
#include <memory>
namespace Terminal::Internal {
class Scrollback;
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 TerminalSurface : public QObject
{
Q_OBJECT;
public:
TerminalSurface(QSize initialGridSize, ShellIntegration *shellIntegration);
~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;
ShellIntegration *shellIntegration() const;
signals:
void writeToPty(const QByteArray &data);
void invalidated(QRect grid);
void fullSizeChanged(QSize newSize);
void cursorChanged(Cursor oldCursor, Cursor newCursor);
void altscreenChanged(bool altScreen);
void unscroll();
void bell();
private:
std::unique_ptr<TerminalSurfacePrivate> d;
};
} // namespace Terminal::Internal
|