MauiKit Terminal

Pty.h
1/*
2 SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com>
3 SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#ifndef PTY_H
9#define PTY_H
10
11// Qt
12#include <QSize>
13
14// KDE
15#include <KPtyProcess>
16
17namespace Konsole
18{
19/**
20 * The Pty class is used to start the terminal process,
21 * send data to it, receive data from it and manipulate
22 * various properties of the pseudo-teletype interface
23 * used to communicate with the process.
24 *
25 * To use this class, construct an instance and connect
26 * to the sendData slot and receivedData signal to
27 * send data to or receive data from the process.
28 *
29 * To start the terminal process, call the start() method
30 * with the program name and appropriate arguments.
31 */
32class Pty : public KPtyProcess
33{
35
36public:
37 /**
38 * Constructs a new Pty.
39 *
40 * Connect to the sendData() slot and receivedData() signal to prepare
41 * for sending and receiving data from the terminal process.
42 *
43 * To start the terminal process, call the run() method with the
44 * name of the program to start and appropriate arguments.
45 */
46 explicit Pty(QObject *parent = nullptr);
47
48 /**
49 * Construct a process using an open pty master.
50 * See KPtyProcess::KPtyProcess()
51 */
52 explicit Pty(int ptyMasterFd, QObject *parent = nullptr);
53
54 ~Pty() override;
55
56 /**
57 * Starts the terminal process.
58 *
59 * Returns 0 if the process was started successfully or non-zero
60 * otherwise.
61 *
62 * @param program Path to the program to start
63 * @param arguments Arguments to pass to the program being started
64 * @param environment A list of key=value pairs which will be added
65 * to the environment for the new process. At the very least this
66 * should include an assignment for the TERM environment variable.
67 */
69
70 /** Control whether the pty device is writeable by group members. */
71 void setWriteable(bool writeable);
72
73 /**
74 * Enables or disables Xon/Xoff flow control. The flow control setting
75 * may be changed later by a terminal application, so flowControlEnabled()
76 * may not equal the value of @p on in the previous call to setFlowControlEnabled()
77 */
78 void setFlowControlEnabled(bool on);
79
80 /** Queries the terminal state and returns true if Xon/Xoff flow control is enabled. */
81 bool flowControlEnabled() const;
82
83 /**
84 * Sets the size of the window (in columns and lines of characters,
85 * and width and height in pixels) used by this teletype.
86 */
87 void setWindowSize(int columns, int lines, int width, int height);
88
89 /** Returns the size of the window used by this teletype in characters. See setWindowSize() */
90 QSize windowSize() const;
91
92 /** Returns the size of the window used by this teletype in pixels. See setWindowSize() */
93 QSize pixelSize() const;
94
95 /**
96 * Sets the special character for erasing previous not-yet-erased character.
97 * See termios(3) for detailed description.
98 */
99 void setEraseChar(char eraseChar);
100
101 /** */
102 char eraseChar() const;
103
104 /**
105 * Sets the initial working directory.
106 */
107 void setInitialWorkingDirectory(const QString &dir);
108
109 /**
110 * Returns the process id of the teletype's current foreground
111 * process. This is the process which is currently reading
112 * input sent to the terminal via. sendData()
113 *
114 * If there is a problem reading the foreground process group,
115 * 0 will be returned.
116 */
117 int foregroundProcessGroup() const;
118
119 /**
120 * Close the underlying pty master/slave pair.
121 */
122 void closePty();
123
124public Q_SLOTS:
125 /**
126 * Put the pty into UTF-8 mode on systems which support it.
127 */
128 void setUtf8Mode(bool on);
129
130 /**
131 * Sends data to the process currently controlling the
132 * teletype ( whose id is returned by foregroundProcessGroup() )
133 *
134 * @param data the data to send.
135 */
136 void sendData(const QByteArray &data);
137
139 /**
140 * Emitted when a new block of data is received from
141 * the teletype.
142 *
143 * @param buffer Pointer to the data received.
144 * @param length Length of @p buffer
145 */
146 void receivedData(const char *buffer, int length);
147
148protected:
149 // TODO: remove this; the method is removed from QProcess in Qt6
150 // instead use setChildProcessModifier() in the constructor
151#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
152 void setupChildProcess() override;
153#endif
154
155private Q_SLOTS:
156 // called when data is received from the terminal process
157 void dataReceived();
158
159private:
160 void init();
161
162 // takes a list of key=value pairs and adds them
163 // to the environment for the process
164 void addEnvironmentVariables(const QStringList &environment);
165
166 int _windowColumns;
167 int _windowLines;
168 int _windowWidth;
169 int _windowHeight;
170 char _eraseChar;
171 bool _xonXoff;
172 bool _utf8;
173};
174}
175
176#endif // PTY_H
void start()
QStringList program() const
The Pty class is used to start the terminal process, send data to it, receive data from it and manipu...
Definition Pty.h:33
QSize windowSize() const
Returns the size of the window used by this teletype in characters.
Definition Pty.cpp:121
bool flowControlEnabled() const
Queries the terminal state and returns true if Xon/Xoff flow control is enabled.
Definition Pty.cpp:150
void receivedData(const char *buffer, int length)
Emitted when a new block of data is received from the teletype.
void setInitialWorkingDirectory(const QString &dir)
Sets the initial working directory.
Definition Pty.cpp:212
void setEraseChar(char eraseChar)
Sets the special character for erasing previous not-yet-erased character.
Definition Pty.cpp:185
void closePty()
Close the underlying pty master/slave pair.
Definition Pty.cpp:304
QSize pixelSize() const
Returns the size of the window used by this teletype in pixels.
Definition Pty.cpp:126
Pty(QObject *parent=nullptr)
Constructs a new Pty.
Definition Pty.cpp:26
void setWriteable(bool writeable)
Control whether the pty device is writeable by group members.
Definition Pty.cpp:286
void setFlowControlEnabled(bool on)
Enables or disables Xon/Xoff flow control.
Definition Pty.cpp:131
void setWindowSize(int columns, int lines, int width, int height)
Sets the size of the window (in columns and lines of characters, and width and height in pixels) used...
Definition Pty.cpp:100
void sendData(const QByteArray &data)
Sends data to the process currently controlling the teletype ( whose id is returned by foregroundProc...
Definition Pty.cpp:78
int foregroundProcessGroup() const
Returns the process id of the teletype's current foreground process.
Definition Pty.cpp:309
void setUtf8Mode(bool on)
Put the pty into UTF-8 mode on systems which support it.
Definition Pty.cpp:162
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
QStringList environment() const const
QStringList arguments() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:57:30 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.