GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
TerminalModel Class Reference

Represents a terminal session consisting of a pseudo-teletype and a terminal emulation. More...

#include "TerminalModel.h"

Inheritance diagram for TerminalModel:
Collaboration diagram for TerminalModel:

Public Slots

void close ()
 Closes the terminal session. More...
 
void run ()
 Starts the terminal session. More...
 

Signals

void bellRequest (const QString &message)
 Emitted when a bell event occurs in the session. More...
 
void changeBackgroundColorRequest (const QColor &)
 Requests that the background color of views on this session should be changed. More...
 
void changeTabTextColorRequest (int)
 Requests that the color the text for any tabs associated with this session should be changed;. More...
 
void finished ()
 Emitted when the terminal process exits. More...
 
void openUrlRequest (const QString &url)
 TODO: Document me. More...
 
void profileChangeCommandReceived (const QString &text)
 Emitted when a profile change command is received from the terminal. More...
 
void profileChanged (const QString &profile)
 Emitted when the session's profile has changed. More...
 
void receivedData (const QString &text)
 Emitted when output is received from the terminal process. More...
 
void resizeRequest (const QSize &size)
 Emitted when the terminal process requests a change in the size of the terminal window. More...
 
void started ()
 Emitted when the terminal process starts. More...
 
void stateChanged (int state)
 Emitted when the activity state of this session changes. More...
 
void titleChanged ()
 Emitted when the session's title has changed. More...
 

Public Member Functions

 TerminalModel (KPty *kpty)
 Constructs a new session. More...
 
 ~TerminalModel ()
 
void addView (TerminalView *widget)
 Adds a new view for this session. More...
 
void clearHistory ()
 Clears the history store used by this session. More...
 
Emulationemulation () const
 Returns the terminal emulation instance being used to encode / decode characters to / from the process. More...
 
bool hasDarkBackground () const
 Returns true if the session has a dark background. More...
 
const HistoryTypehistoryType () const
 Returns the type of history store used by this session. More...
 
bool isMonitorActivity () const
 Returns true if monitoring for activity is enabled. More...
 
bool isMonitorSilence () const
 Returns true if monitoring for inactivity (silence) in the session is enabled. More...
 
QString keyBindings () const
 Returns the name of the key bindings used by this session. More...
 
QString profileKey () const
 Returns the profile key associated with this session. More...
 
void refresh ()
 Attempts to get the shell program to redraw the current display area. More...
 
void removeView (TerminalView *widget)
 Removes a view from this session. More...
 
void sendText (const QString &text) const
 Sends text to the current foreground terminal program. More...
 
void setAddToUtmp (bool)
 Specifies whether a utmp entry should be created for the pty used by this session. More...
 
void setAutoClose (bool b)
 Specifies whether to close the session automatically when the terminal process terminates. More...
 
void setCodec (QTextCodec *codec)
 Sets the text codec used by this session's terminal emulation. More...
 
void setDarkBackground (bool darkBackground)
 Sets whether the session has a dark background or not. More...
 
void setHistoryType (const HistoryType &type)
 Sets the type of history store used by this session. More...
 
void setKeyBindings (const QString &id)
 Sets the key bindings used by this session. More...
 
void setMonitorActivity (bool)
 Enables monitoring for activity in the session. More...
 
void setMonitorSilence (bool)
 Enables monitoring for silence in the session. More...
 
void setMonitorSilenceSeconds (int seconds)
 See setMonitorSilence() More...
 
void setProfileKey (const QString &profileKey)
 Sets the profile associated with this session. More...
 
void setSize (const QSize &size)
 Emits a request to resize the session to accommodate the specified window size. More...
 
QSize size ()
 Returns the terminal session's window size in lines and columns. More...
 
QList< TerminalView * > views () const
 Returns the views connected to this session. More...
 

Properties

QString keyBindings
 
QSize size
 

Private Slots

void activityStateSet (int)
 
void done (int)
 
void monitorTimerDone ()
 
void onEmulationSizeChange (int lines, int columns)
 
void onReceiveBlock (const char *buffer, int len)
 
void onViewSizeChange (int height, int width)
 
void sendData (const char *buf, int len)
 
void viewDestroyed (QObject *view)
 

Private Member Functions

void updateTerminalSize ()
 
WId windowId () const
 

Private Attributes

bool _addToUtmp
 
bool _autoClose
 
Emulation_emulation
 
bool _fullScripting
 
bool _hasDarkBackground
 
KPty_kpty
 
int _masterFd
 
bool _masterMode
 
QColor _modifiedBackground
 
bool _monitorActivity
 
bool _monitorSilence
 
QTimer * _monitorTimer
 
bool _notifiedActivity
 
QString _profileKey
 
SelfListener_selfListener
 
PseudoTerminal * _shellProcess
 
int _silenceSeconds
 
int _slaveFd
 
int _uniqueIdentifier
 
QList< TerminalView * > _views
 
bool _wantedClose
 

Detailed Description

Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.

The pseudo-teletype (or PTY) handles I/O between the terminal process and Konsole. The terminal emulation ( Emulation and subclasses ) processes the output stream from the PTY and produces a character image which is then shown on views connected to the session.

Each Session can be connected to one or more views by using the addView() method. The attached views can then display output from the program running in the terminal or send input to the program in the terminal in the form of keypresses and mouse activity.

Definition at line 57 of file TerminalModel.h.

Constructor & Destructor Documentation

◆ TerminalModel()

TerminalModel::TerminalModel ( KPty kpty)

Constructs a new session.

To start the terminal process, call the run() method, after specifying the program and arguments using setProgram() and setArguments()

If no program or arguments are specified explicitly, the Session falls back to using the program specified in the SHELL environment variable.

Definition at line 45 of file TerminalModel.cpp.

References _emulation, _kpty, _monitorTimer, _selfListener, activityStateSet(), changeTabTextColorRequest(), KPty::masterFd(), monitorTimerDone(), onReceiveBlock(), profileChangeCommandReceived(), and sendData().

◆ ~TerminalModel()

TerminalModel::~TerminalModel ( )

Definition at line 313 of file TerminalModel.cpp.

References _emulation.

Member Function Documentation

◆ activityStateSet

void TerminalModel::activityStateSet ( int  state)
privateslot

◆ addView()

void TerminalModel::addView ( TerminalView widget)

Adds a new view for this session.

The viewing widget will display the output from the terminal and input from the viewing widget (key presses, mouse activity etc.) will be sent to the terminal.

Views can be removed using removeView(). The session is automatically closed when the last view is removed.

Definition at line 111 of file TerminalModel.cpp.

References _emulation, _views, Emulation::createWindow(), onViewSizeChange(), Emulation::programBracketedPasteMode(), Emulation::programUsesMouse(), TerminalView::setBracketedPasteMode(), TerminalView::setScreenWindow(), TerminalView::setUsesMouse(), and viewDestroyed().

Referenced by QUnixTerminalImpl::initialize().

◆ bellRequest

void TerminalModel::bellRequest ( const QString &  message)
signal

Emitted when a bell event occurs in the session.

Referenced by activityStateSet().

◆ changeBackgroundColorRequest

void TerminalModel::changeBackgroundColorRequest ( const QColor &  )
signal

Requests that the background color of views on this session should be changed.

◆ changeTabTextColorRequest

void TerminalModel::changeTabTextColorRequest ( int  )
signal

Requests that the color the text for any tabs associated with this session should be changed;.

TODO: Document what the parameter does

Referenced by TerminalModel().

◆ clearHistory()

void TerminalModel::clearHistory ( )

Clears the history store used by this session.

Definition at line 355 of file TerminalModel.cpp.

References _emulation, and Emulation::clearHistory().

Referenced by QUnixTerminalImpl::setScrollBufferSize().

◆ close

void TerminalModel::close ( void  )
slot

Closes the terminal session.

This sends a hangup signal (SIGHUP) to the terminal process and causes the done(Session*) signal to be emitted.

Definition at line 302 of file TerminalModel.cpp.

References _autoClose, and _wantedClose.

Referenced by removeView().

◆ done

void TerminalModel::done ( int  )
privateslot

Definition at line 325 of file TerminalModel.cpp.

References finished().

◆ emulation()

Emulation * TerminalModel::emulation ( ) const

Returns the terminal emulation instance being used to encode / decode characters to / from the process.

Definition at line 330 of file TerminalModel.cpp.

References _emulation.

Referenced by setCodec().

◆ finished

void TerminalModel::finished ( )
signal

Emitted when the terminal process exits.

Referenced by done().

◆ hasDarkBackground()

bool TerminalModel::hasDarkBackground ( ) const

Returns true if the session has a dark background.

See setDarkBackground()

Definition at line 96 of file TerminalModel.cpp.

References _hasDarkBackground.

◆ historyType()

const HistoryType & TerminalModel::historyType ( ) const

Returns the type of history store used by this session.

Definition at line 350 of file TerminalModel.cpp.

References _emulation, and Emulation::history().

◆ isMonitorActivity()

bool TerminalModel::isMonitorActivity ( ) const

Returns true if monitoring for activity is enabled.

Definition at line 361 of file TerminalModel.cpp.

References _monitorActivity.

◆ isMonitorSilence()

bool TerminalModel::isMonitorSilence ( ) const

Returns true if monitoring for inactivity (silence) in the session is enabled.

Definition at line 363 of file TerminalModel.cpp.

References _monitorSilence.

◆ keyBindings()

QString TerminalModel::keyBindings ( ) const

Returns the name of the key bindings used by this session.

Definition at line 335 of file TerminalModel.cpp.

References _emulation, and Emulation::keyBindings().

◆ monitorTimerDone

void TerminalModel::monitorTimerDone ( )
privateslot

Definition at line 199 of file TerminalModel.cpp.

References _monitorSilence, _notifiedActivity, NOTIFYNORMAL, NOTIFYSILENCE, and stateChanged().

Referenced by TerminalModel().

◆ onEmulationSizeChange

void TerminalModel::onEmulationSizeChange ( int  lines,
int  columns 
)
privateslot

Definition at line 258 of file TerminalModel.cpp.

References setSize().

◆ onReceiveBlock

void TerminalModel::onReceiveBlock ( const char *  buffer,
int  len 
)
privateslot

Definition at line 402 of file TerminalModel.cpp.

References _emulation, len, Emulation::receiveData(), and receivedData().

Referenced by TerminalModel().

◆ onViewSizeChange

void TerminalModel::onViewSizeChange ( int  height,
int  width 
)
privateslot

Definition at line 254 of file TerminalModel.cpp.

References updateTerminalSize().

Referenced by addView().

◆ openUrlRequest

void TerminalModel::openUrlRequest ( const QString &  url)
signal

TODO: Document me.

◆ profileChangeCommandReceived

void TerminalModel::profileChangeCommandReceived ( const QString &  text)
signal

Emitted when a profile change command is received from the terminal.

Parameters
textThe text of the command. This is a string of the form "PropertyName=Value;PropertyName=Value ..."

Referenced by TerminalModel().

◆ profileChanged

void TerminalModel::profileChanged ( const QString &  profile)
signal

Emitted when the session's profile has changed.

Referenced by setProfileKey().

◆ profileKey()

QString TerminalModel::profileKey ( ) const

Returns the profile key associated with this session.

This can be passed to the SessionManager to obtain the current profile settings.

Definition at line 323 of file TerminalModel.cpp.

References _profileKey.

◆ receivedData

void TerminalModel::receivedData ( const QString &  text)
signal

Emitted when output is received from the terminal process.

Referenced by onReceiveBlock().

◆ refresh()

void TerminalModel::refresh ( )

Attempts to get the shell program to redraw the current display area.

This can be used after clearing the screen, for example, to get the shell to redraw the prompt line.

Definition at line 298 of file TerminalModel.cpp.

◆ removeView()

void TerminalModel::removeView ( TerminalView widget)

Removes a view from this session.

When the last view is removed, the session will be closed automatically.

widget will no longer display output from or send input to the terminal

Definition at line 167 of file TerminalModel.cpp.

References _emulation, _views, and close().

Referenced by viewDestroyed().

◆ resizeRequest

void TerminalModel::resizeRequest ( const QSize &  size)
signal

Emitted when the terminal process requests a change in the size of the terminal window.

Parameters
sizeThe requested window size in terms of lines and columns.

Referenced by setSize().

◆ run

void TerminalModel::run ( void  )
slot

Starts the terminal session.

This creates the terminal process and connects the teletype to it.

Definition at line 194 of file TerminalModel.cpp.

References started().

Referenced by QUnixTerminalImpl::initialize().

◆ sendData

void TerminalModel::sendData ( const char *  buf,
int  len 
)
privateslot

Definition at line 161 of file TerminalModel.cpp.

References _kpty, len, and KPty::masterFd().

Referenced by TerminalModel().

◆ sendText()

void TerminalModel::sendText ( const QString &  text) const

Sends text to the current foreground terminal program.

Definition at line 308 of file TerminalModel.cpp.

References _emulation, and Emulation::sendText().

Referenced by QUnixTerminalImpl::sendText().

◆ setAddToUtmp()

void TerminalModel::setAddToUtmp ( bool  set)

Specifies whether a utmp entry should be created for the pty used by this session.

Definition at line 397 of file TerminalModel.cpp.

References _addToUtmp.

◆ setAutoClose()

void TerminalModel::setAutoClose ( bool  b)
inline

Specifies whether to close the session automatically when the terminal process terminates.

Definition at line 191 of file TerminalModel.h.

References _autoClose.

Referenced by QUnixTerminalImpl::initialize().

◆ setCodec()

void TerminalModel::setCodec ( QTextCodec *  codec)

Sets the text codec used by this session's terminal emulation.

Definition at line 101 of file TerminalModel.cpp.

References emulation(), and Emulation::setCodec().

Referenced by QUnixTerminalImpl::initialize().

◆ setDarkBackground()

void TerminalModel::setDarkBackground ( bool  darkBackground)

Sets whether the session has a dark background or not.

The session uses this information to set the COLORFGBG variable in the process's environment, which allows the programs running in the terminal to determine whether the background is light or dark and use appropriate colors by default.

This has no effect once the session is running.

Definition at line 92 of file TerminalModel.cpp.

References _hasDarkBackground.

Referenced by QUnixTerminalImpl::initialize().

◆ setHistoryType()

void TerminalModel::setHistoryType ( const HistoryType type)

Sets the type of history store used by this session.

Lines of output produced by the terminal are added to the history store. The type of history store used affects the number of lines which can be remembered before they are lost and the storage (in memory, on-disk etc.) used.

Definition at line 345 of file TerminalModel.cpp.

References _emulation, and Emulation::setHistory().

Referenced by QUnixTerminalImpl::initialize(), and QUnixTerminalImpl::setScrollBufferSize().

◆ setKeyBindings()

void TerminalModel::setKeyBindings ( const QString &  id)

Sets the key bindings used by this session.

The bindings specify how input key sequences are translated into the character stream which is sent to the terminal.

Parameters
idThe name of the key bindings to use. The names of available key bindings can be determined using the KeyboardTranslatorManager class.

Definition at line 340 of file TerminalModel.cpp.

References _emulation, and Emulation::setKeyBindings().

Referenced by QUnixTerminalImpl::initialize().

◆ setMonitorActivity()

void TerminalModel::setMonitorActivity ( bool  _monitor)

Enables monitoring for activity in the session.

This will cause notifySessionState() to be emitted with the NOTIFYACTIVITY state flag when output is received from the terminal.

Definition at line 365 of file TerminalModel.cpp.

References _monitorActivity, _notifiedActivity, activityStateSet(), and NOTIFYNORMAL.

◆ setMonitorSilence()

void TerminalModel::setMonitorSilence ( bool  _monitor)

Enables monitoring for silence in the session.

This will cause notifySessionState() to be emitted with the NOTIFYSILENCE state flag when output is not received from the terminal for a certain period of time, specified with setMonitorSilenceSeconds()

Definition at line 373 of file TerminalModel.cpp.

References _monitorSilence, _monitorTimer, _silenceSeconds, activityStateSet(), and NOTIFYNORMAL.

◆ setMonitorSilenceSeconds()

void TerminalModel::setMonitorSilenceSeconds ( int  seconds)

See setMonitorSilence()

Definition at line 389 of file TerminalModel.cpp.

References _monitorSilence, _monitorTimer, and _silenceSeconds.

◆ setProfileKey()

void TerminalModel::setProfileKey ( const QString &  profileKey)

Sets the profile associated with this session.

Parameters
profileKeyA key which can be used to obtain the current profile settings from the SessionManager

Definition at line 318 of file TerminalModel.cpp.

References _profileKey, and profileChanged().

◆ setSize()

void TerminalModel::setSize ( const QSize &  size)

Emits a request to resize the session to accommodate the specified window size.

Parameters
sizeThe size in lines and columns to request.

Definition at line 413 of file TerminalModel.cpp.

References resizeRequest(), and size.

Referenced by onEmulationSizeChange().

◆ size()

QSize TerminalModel::size ( )

Returns the terminal session's window size in lines and columns.

◆ started

void TerminalModel::started ( )
signal

Emitted when the terminal process starts.

Referenced by run().

◆ stateChanged

void TerminalModel::stateChanged ( int  state)
signal

Emitted when the activity state of this session changes.

Parameters
stateThe new state of the session. This may be one of NOTIFYNORMAL, NOTIFYSILENCE or NOTIFYACTIVITY

Referenced by activityStateSet(), and monitorTimerDone().

◆ titleChanged

void TerminalModel::titleChanged ( )
signal

Emitted when the session's title has changed.

◆ updateTerminalSize()

void TerminalModel::updateTerminalSize ( )
private

◆ viewDestroyed

void TerminalModel::viewDestroyed ( QObject view)
privateslot

Definition at line 152 of file TerminalModel.cpp.

References _views, and removeView().

Referenced by addView().

◆ views()

QList< TerminalView * > TerminalModel::views ( ) const

Returns the views connected to this session.

Definition at line 106 of file TerminalModel.cpp.

References _views.

◆ windowId()

WId TerminalModel::windowId ( ) const
private

Member Data Documentation

◆ _addToUtmp

bool TerminalModel::_addToUtmp
private

Definition at line 353 of file TerminalModel.h.

Referenced by setAddToUtmp().

◆ _autoClose

bool TerminalModel::_autoClose
private

Definition at line 347 of file TerminalModel.h.

Referenced by close(), and setAutoClose().

◆ _emulation

◆ _fullScripting

bool TerminalModel::_fullScripting
private

Definition at line 354 of file TerminalModel.h.

◆ _hasDarkBackground

bool TerminalModel::_hasDarkBackground
private

Definition at line 367 of file TerminalModel.h.

Referenced by hasDarkBackground(), and setDarkBackground().

◆ _kpty

KPty* TerminalModel::_kpty
private

Definition at line 360 of file TerminalModel.h.

Referenced by TerminalModel(), sendData(), and updateTerminalSize().

◆ _masterFd

int TerminalModel::_masterFd
private

Definition at line 356 of file TerminalModel.h.

◆ _masterMode

bool TerminalModel::_masterMode
private

Definition at line 346 of file TerminalModel.h.

◆ _modifiedBackground

QColor TerminalModel::_modifiedBackground
private

Definition at line 363 of file TerminalModel.h.

◆ _monitorActivity

bool TerminalModel::_monitorActivity
private

Definition at line 343 of file TerminalModel.h.

Referenced by activityStateSet(), isMonitorActivity(), and setMonitorActivity().

◆ _monitorSilence

bool TerminalModel::_monitorSilence
private

◆ _monitorTimer

QTimer* TerminalModel::_monitorTimer
private

◆ _notifiedActivity

bool TerminalModel::_notifiedActivity
private

Definition at line 345 of file TerminalModel.h.

Referenced by activityStateSet(), monitorTimerDone(), and setMonitorActivity().

◆ _profileKey

QString TerminalModel::_profileKey
private

Definition at line 365 of file TerminalModel.h.

Referenced by profileKey(), and setProfileKey().

◆ _selfListener

SelfListener* TerminalModel::_selfListener
private

Definition at line 359 of file TerminalModel.h.

Referenced by TerminalModel().

◆ _shellProcess

PseudoTerminal* TerminalModel::_shellProcess
private

Definition at line 338 of file TerminalModel.h.

◆ _silenceSeconds

int TerminalModel::_silenceSeconds
private

Definition at line 351 of file TerminalModel.h.

Referenced by activityStateSet(), setMonitorSilence(), and setMonitorSilenceSeconds().

◆ _slaveFd

int TerminalModel::_slaveFd
private

Definition at line 357 of file TerminalModel.h.

◆ _uniqueIdentifier

int TerminalModel::_uniqueIdentifier
private

Definition at line 336 of file TerminalModel.h.

◆ _views

QList<TerminalView*> TerminalModel::_views
private

Definition at line 341 of file TerminalModel.h.

Referenced by addView(), removeView(), updateTerminalSize(), viewDestroyed(), and views().

◆ _wantedClose

bool TerminalModel::_wantedClose
private

Definition at line 348 of file TerminalModel.h.

Referenced by close().

Property Documentation

◆ keyBindings

QString TerminalModel::keyBindings
readwrite

Definition at line 1 of file TerminalModel.h.

◆ size

QSize TerminalModel::size
readwrite

Definition at line 1 of file TerminalModel.h.

Referenced by setSize().


The documentation for this class was generated from the following files: