GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
|
Base class for terminal emulation back-ends. More...
#include "Emulation.h"
Public Slots | |
void | receiveData (const char *buffer, int len) |
Processes an incoming stream of characters. | |
virtual void | sendKeyEvent (QKeyEvent *) |
Interprets a key press event and emits the sendData() signal with the resulting character stream. | |
virtual void | sendMouseEvent (int buttons, int column, int line, int eventType) |
Converts information about a mouse event into an xterm-compatible escape sequence and emits the character sequence via sendData() | |
virtual void | sendString (const char *string, int length=-1)=0 |
Sends a string of characters to the foreground terminal process. | |
virtual void | sendText (const QString &text)=0 |
Interprets a sequence of characters and sends the result to the terminal. | |
virtual void | setImageSize (int lines, int columns) |
Change the size of the emulation's image. |
Signals | |
void | changeTabTextColorRequest (int color) |
Requests that the color of the text used to represent the tabs associated with this emulation be changed. | |
void | imageSizeChanged (int lineCount, int columnCount) |
Emitted when the program running in the terminal changes the screen size. | |
void | lockPtyRequest (bool suspend) |
Requests that sending of input to the emulation from the terminal process be suspended or resumed. | |
void | outputChanged () |
Emitted when the contents of the screen image change. | |
void | profileChangeCommandReceived (const QString &text) |
Emitted when the terminal program requests to change various properties of the terminal display. | |
void | programUsesMouseChanged (bool usesMouse) |
This is emitted when the program running in the shell indicates whether or not it is interested in mouse events. | |
void | sendData (const char *data, int len) |
Emitted when a buffer of data is ready to send to the standard input of the terminal. | |
void | stateSet (int state) |
Emitted when the activity state of the emulation is set. | |
void | titleChanged (int title, const QString &newTitle) |
Emitted when the program running in the terminal wishes to update the session's title. | |
void | useUtf8Request (bool) |
Requests that the pty used by the terminal process be set to UTF 8 mode. |
Public Member Functions | |
Emulation () | |
Constructs a new terminal emulation. | |
~Emulation () | |
virtual void | clearEntireScreen ()=0 |
Copies the current image into the history and clears the screen. | |
void | clearHistory () |
Clears the history scroll. | |
const QTextCodec * | codec () |
Returns the codec used to decode incoming characters. | |
ScreenWindow * | createWindow () |
Creates a new window onto the output from this emulation. | |
virtual char | getErase () const |
TODO Document me. | |
const HistoryType & | history () |
Returns the history store used by this emulation. | |
QSize | imageSize () |
Returns the size of the screen image which the emulation produces. | |
QString | keyBindings () |
Returns the name of the emulation's current key bindings. | |
int | lineCount () |
Returns the total number of lines, including those stored in the history. | |
bool | programUsesMouse () const |
Returns true if the active terminal program wants mouse input events. | |
virtual void | reset ()=0 |
Resets the state of the terminal. | |
void | setCodec (const QTextCodec *) |
Sets the codec used to decode incoming characters. | |
void | setHistory (const HistoryType &) |
Sets the history store used by this emulation. | |
void | setKeyBindings (const QString &name) |
Sets the key bindings used to key events ( received through sendKeyEvent() ) into character streams to send to the terminal. | |
bool | utf8 () |
Convenience method. | |
virtual void | writeToStream (TerminalCharacterDecoder *decoder, int startLine, int endLine) |
Copies the output history from startLine to endLine into stream , using decoder to convert the terminal characters into text. |
Protected Types | |
enum | EmulationCodec { LocaleCodec = 0, Utf8Codec = 1 } |
Protected Slots | |
void | bufferedUpdate () |
Schedules an update of attached views. |
Protected Member Functions | |
virtual void | receiveChar (int ch) |
Processes an incoming character. | |
virtual void | resetMode (int mode)=0 |
void | setCodec (EmulationCodec codec) |
virtual void | setMode (int mode)=0 |
void | setScreen (int index) |
Sets the active screen. |
Protected Attributes | |
const QTextCodec * | _codec |
Screen * | _currentScreen |
QTextDecoder * | _decoder |
const KeyboardTranslator * | _keyTranslator |
Screen * | _screen [2] |
QList< ScreenWindow * > | _windows |
Private Slots | |
void | showBulk () |
void | usesMouseChanged (bool usesMouse) |
Private Attributes | |
QTimer | _bulkTimer1 |
QTimer | _bulkTimer2 |
bool | _usesMouse |
Base class for terminal emulation back-ends.
The back-end is responsible for decoding an incoming character stream and producing an output image of characters.
When input from the terminal is received, the receiveData() slot should be called with the data which has arrived. The emulation will process the data and update the screen image accordingly. The codec used to decode the incoming character stream into the unicode characters used internally can be specified using setCodec()
The size of the screen image can be specified by calling setImageSize() with the desired number of lines and columns. When new lines are added, old content is moved into a history store, which can be set by calling setHistory().
The screen image can be accessed by creating a ScreenWindow onto this emulation by calling createWindow(). Screen windows provide access to a section of the output. Each screen window covers the same number of lines and columns as the image size returned by imageSize(). The screen window can be moved up and down and provides transparent access to both the current on-screen image and the previous output. The screen windows emit an outputChanged signal when the section of the image they are looking at changes. Graphical views can then render the contents of a screen window, listening for notifications of output changes from the screen window which they are associated with and updating accordingly.
The emulation also is also responsible for converting input from the connected views such as keypresses and mouse activity into a character string which can be sent to the terminal program. Key presses can be processed by calling the sendKeyEvent() slot, while mouse events can be processed using the sendMouseEvent() slot. When the character stream has been produced, the emulation will emit a sendData() signal with a pointer to the character buffer. This data should be fed to the standard input of the terminal process. The translation of key presses into an output character stream is performed using a lookup in a set of key bindings which map key sequences to output character sequences. The name of the key bindings set used can be specified using setKeyBindings()
The emulation maintains certain state information which changes depending on the input received. The emulation can be reset back to its starting state by calling reset().
The emulation also maintains an activity state, which specifies whether terminal is currently active ( when data is received ), normal ( when the terminal is idle or receiving user input ) or trying to alert the user ( also known as a "Bell" event ). The stateSet() signal is emitted whenever the activity state is set. This can be used to determine how long the emulation has been active/idle for and also respond to a 'bell' event in different ways.
Definition at line 118 of file Emulation.h.
|
protected |
Definition at line 406 of file Emulation.h.
Emulation::Emulation | ( | ) |
Constructs a new terminal emulation.
Definition at line 52 of file Emulation.cpp.
References _bulkTimer1, _bulkTimer2, _currentScreen, _screen, programUsesMouseChanged(), showBulk(), and usesMouseChanged().
Emulation::~Emulation | ( | ) |
Definition at line 100 of file Emulation.cpp.
|
protectedslot |
Schedules an update of attached views.
Repeated calls to bufferedUpdate() in close succession will result in only a single update, much like the Qt buffered update of widgets.
Definition at line 297 of file Emulation.cpp.
References _bulkTimer1, _bulkTimer2, BULK_TIMEOUT1, and BULK_TIMEOUT2.
Referenced by Vt102Emulation::clearEntireScreen(), createWindow(), receiveData(), Vt102Emulation::reset(), and setImageSize().
Requests that the color of the text used to represent the tabs associated with this emulation be changed.
This is a Konsole-specific extension from pre-KDE 4 times.
TODO: Document how the parameter works.
Referenced by Vt102Emulation::tau().
|
pure virtual |
Copies the current image into the history and clears the screen.
Implemented in Vt102Emulation.
void Emulation::clearHistory | ( | ) |
Clears the history scroll.
Definition at line 134 of file Emulation.cpp.
References _screen, and Screen::setScroll().
Referenced by TerminalModel::clearHistory().
|
inline |
Returns the codec used to decode incoming characters.
See setCodec()
Definition at line 172 of file Emulation.h.
References _codec.
ScreenWindow * Emulation::createWindow | ( | ) |
Creates a new window onto the output from this emulation.
The contents of the window are then rendered by views which are set to use this window using the TerminalDisplay::setScreenWindow() method.
Definition at line 83 of file Emulation.cpp.
References _currentScreen, _windows, bufferedUpdate(), outputChanged(), and ScreenWindow::setScreen().
Referenced by TerminalModel::addView().
|
virtual |
const HistoryType & Emulation::history | ( | ) |
Returns the history store used by this emulation.
See setHistory()
Definition at line 145 of file Emulation.cpp.
References _screen, and Screen::getScroll().
Referenced by TerminalModel::historyType().
QSize Emulation::imageSize | ( | ) |
Returns the size of the screen image which the emulation produces.
Definition at line 327 of file Emulation.cpp.
References _currentScreen, Screen::getColumns(), and Screen::getLines().
Emitted when the program running in the terminal changes the screen size.
Referenced by setImageSize().
QString Emulation::keyBindings | ( | ) |
Returns the name of the emulation's current key bindings.
See setKeyBindings()
Definition at line 174 of file Emulation.cpp.
References _keyTranslator, and KeyboardTranslator::name().
int Emulation::lineCount | ( | ) |
Returns the total number of lines, including those stored in the history.
Definition at line 273 of file Emulation.cpp.
References _currentScreen, Screen::getHistLines(), and Screen::getLines().
Requests that sending of input to the emulation from the terminal process be suspended or resumed.
suspend | If true, requests that sending of input from the terminal process' stdout be suspended. Otherwise requests that sending of input be resumed. |
|
signal |
Emitted when the contents of the screen image change.
The emulation buffers the updates from successive image changes, and only emits outputChanged() at sensible intervals when there is a lot of terminal activity.
Normally there is no need for objects other than the screen windows created with createWindow() to listen for this signal.
ScreenWindow objects created using createWindow() will emit their own outputChanged() signal in response to this signal.
Referenced by createWindow(), and showBulk().
|
signal |
Emitted when the terminal program requests to change various properties of the terminal display.
A profile change command occurs when a special escape sequence, followed by a string containing a series of name and value pairs is received. This string can be parsed using a ProfileCommandParser instance.
text | A string expected to contain a series of key and value pairs in the form: name=value;name2=value2 ... |
bool Emulation::programUsesMouse | ( | ) | const |
Returns true if the active terminal program wants mouse input events.
The programUsesMouseChanged() signal is emitted when this changes.
Definition at line 73 of file Emulation.cpp.
References _usesMouse.
Referenced by TerminalModel::addView().
This is emitted when the program running in the shell indicates whether or not it is interested in mouse events.
usesMouse | This will be true if the program wants to be informed about mouse events or false otherwise. |
Referenced by Emulation(), Vt102Emulation::resetMode(), and Vt102Emulation::setMode().
Processes an incoming character.
See receiveData() ch
A unicode character code.
Reimplemented in Vt102Emulation.
Definition at line 192 of file Emulation.cpp.
References _currentScreen, Screen::BackSpace(), Screen::NewLine(), NOTIFYBELL, Screen::Return(), Screen::ShowCharacter(), stateSet(), and Screen::Tabulate().
Referenced by receiveData().
Processes an incoming stream of characters.
receiveData() decodes the incoming character buffer using the current codec(), and then calls receiveChar() for each unicode character in the resulting buffer.
receiveData() also starts a timer which causes the outputChanged() signal to be emitted when it expires. The timer allows multiple updates in quick succession to be buffered into a single outputChanged() signal emission.
buffer | A string of characters received from the terminal program. |
len | The length of buffer |
Definition at line 249 of file Emulation.cpp.
References _decoder, bufferedUpdate(), NOTIFYACTIVITY, receiveChar(), and stateSet().
Referenced by TerminalModel::onReceiveBlock(), and Vt102Emulation::sendKeyEvent().
|
pure virtual |
Resets the state of the terminal.
Implemented in Vt102Emulation.
Implemented in Vt102Emulation.
Emitted when a buffer of data is ready to send to the standard input of the terminal.
data | The buffer of data ready to be sent len The length of data in bytes |
Referenced by Vt102Emulation::sendKeyEvent(), sendKeyEvent(), and Vt102Emulation::sendString().
|
virtualslot |
Interprets a key press event and emits the sendData() signal with the resulting character stream.
Definition at line 218 of file Emulation.cpp.
References NOTIFYNORMAL, sendData(), and stateSet().
Converts information about a mouse event into an xterm-compatible escape sequence and emits the character sequence via sendData()
Definition at line 237 of file Emulation.cpp.
Sends a string of characters to the foreground terminal process.
string | The characters to send. |
length | Length of string or if set to a negative value, string will be treated as a null-terminated string and its length will be determined automatically. |
Definition at line 232 of file Emulation.cpp.
|
pure virtualslot |
Interprets a sequence of characters and sends the result to the terminal.
This is equivalent to calling sendKeyEvent() for each character in text
in succession.
Referenced by TerminalModel::sendText().
void Emulation::setCodec | ( | const QTextCodec * | qtc | ) |
Sets the codec used to decode incoming characters.
Definition at line 150 of file Emulation.cpp.
References _codec, _decoder, useUtf8Request(), and utf8().
Referenced by Vt102Emulation::reset(), TerminalModel::setCodec(), setCodec(), and Vt102Emulation::tau().
|
protected |
Definition at line 161 of file Emulation.cpp.
References LocaleCodec, setCodec(), and Utf8Codec.
void Emulation::setHistory | ( | const HistoryType & | t | ) |
Sets the history store used by this emulation.
When new lines are added to the output, older lines at the top of the screen are transferred to a history store.
The number of lines which are kept and the storage location depend on the type of store.
Definition at line 138 of file Emulation.cpp.
References _screen, Screen::setScroll(), and showBulk().
Referenced by TerminalModel::setHistoryType().
Change the size of the emulation's image.
Definition at line 313 of file Emulation.cpp.
References _screen, bufferedUpdate(), imageSizeChanged(), and Screen::resizeImage().
Referenced by Vt102Emulation::clearScreenAndSetColumns(), Vt102Emulation::tau(), and TerminalModel::updateTerminalSize().
void Emulation::setKeyBindings | ( | const QString & | name | ) |
Sets the key bindings used to key events ( received through sendKeyEvent() ) into character streams to send to the terminal.
Definition at line 169 of file Emulation.cpp.
References _keyTranslator, KeyboardTranslatorManager::findTranslator(), and KeyboardTranslatorManager::instance().
Referenced by TerminalModel::setKeyBindings().
Implemented in Vt102Emulation.
Sets the active screen.
The terminal has two screens, primary and alternate. The primary screen is used by default. When certain interactive programs such as Vim are run, they trigger a switch to the alternate screen.
index | 0 to switch to the primary screen, or 1 to switch to the alternate screen |
change between primary and alternate _screen
Definition at line 117 of file Emulation.cpp.
References _currentScreen, _screen, _windows, and Screen::setBusySelecting().
Referenced by Vt102Emulation::resetMode(), and Vt102Emulation::setMode().
|
privateslot |
Definition at line 286 of file Emulation.cpp.
References _bulkTimer1, _bulkTimer2, _currentScreen, outputChanged(), Screen::resetDroppedLines(), and Screen::resetScrolledLines().
Referenced by Emulation(), and setHistory().
Emitted when the activity state of the emulation is set.
state | The new activity state, one of NOTIFYNORMAL, NOTIFYACTIVITY or NOTIFYBELL |
Referenced by receiveChar(), receiveData(), sendKeyEvent(), and Vt102Emulation::tau().
Emitted when the program running in the terminal wishes to update the session's title.
This also allows terminal programs to customize other aspects of the terminal emulation display.
This signal is emitted when the escape sequence "\033]ARG;VALUE\007" is received in the input string, where ARG is a number specifying what should change and VALUE is a string specifying the new value.
TODO: The name of this method is not very accurate since this method is used to perform a whole range of tasks besides just setting the user-title of the session.
title | Specifies what to change.
|
newTitle | Specifies the new title |
Referenced by Vt102Emulation::updateTitle().
Requests that the pty used by the terminal process be set to UTF 8 mode.
TODO: More documentation
Referenced by setCodec().
|
inline |
Convenience method.
Returns true if the current codec used to decode incoming characters is UTF-8
Definition at line 181 of file Emulation.h.
References _codec.
Referenced by setCodec().
|
virtual |
Copies the output history from startLine
to endLine
into stream
, using decoder
to convert the terminal characters into text.
decoder | A decoder which converts lines of terminal characters with appearance attributes into output text. PlainTextDecoder is the most commonly used decoder. |
startLine | The first |
Definition at line 266 of file Emulation.cpp.
References _currentScreen, and Screen::writeToStream().
|
private |
Definition at line 451 of file Emulation.h.
Referenced by bufferedUpdate(), Emulation(), and showBulk().
|
private |
Definition at line 452 of file Emulation.h.
Referenced by bufferedUpdate(), Emulation(), and showBulk().
|
protected |
Definition at line 427 of file Emulation.h.
Referenced by codec(), Vt102Emulation::sendKeyEvent(), setCodec(), and utf8().
|
protected |
Definition at line 416 of file Emulation.h.
Referenced by Vt102Emulation::clearEntireScreen(), Vt102Emulation::clearScreenAndSetColumns(), createWindow(), Emulation(), imageSize(), lineCount(), receiveChar(), Vt102Emulation::reportCursorPosition(), Vt102Emulation::restoreCursor(), Vt102Emulation::saveCursor(), setScreen(), showBulk(), Vt102Emulation::tau(), and writeToStream().
|
protected |
Definition at line 428 of file Emulation.h.
Referenced by receiveData(), setCodec(), and ~Emulation().
|
protected |
Definition at line 430 of file Emulation.h.
Referenced by Vt102Emulation::getErase(), keyBindings(), Vt102Emulation::sendKeyEvent(), and setKeyBindings().
|
protected |
Definition at line 419 of file Emulation.h.
Referenced by clearHistory(), Emulation(), history(), Vt102Emulation::reset(), Vt102Emulation::resetMode(), Vt102Emulation::setDefaultMargins(), setHistory(), setImageSize(), Vt102Emulation::setMargins(), Vt102Emulation::setMode(), setScreen(), Vt102Emulation::tau(), and ~Emulation().
|
private |
Definition at line 450 of file Emulation.h.
Referenced by programUsesMouse(), and usesMouseChanged().
|
protected |
Definition at line 414 of file Emulation.h.
Referenced by createWindow(), setScreen(), and ~Emulation().