GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QUnixTerminalImpl.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 e_k (e_k@users.sourceforge.net)
2  Copyright (C) 2012-2016 Jacob Dawid <jacob.dawid@cybercatalyst.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <QDebug>
21 
22 #include "unix/QUnixTerminalImpl.h"
23 #include "unix/kpty.h"
24 
25 #include <termios.h>
26 
28  : QTerminal(parent) {
29  setMinimumSize(300, 200);
30  initialize();
31 }
32 
34 {
35  m_terminalView = new TerminalView(this);
40  m_terminalView->setContextMenuPolicy(Qt::CustomContextMenu);
43  m_terminalView->setSize(80, 40);
45 
46  connect(m_terminalView, SIGNAL(customContextMenuRequested(QPoint)),
47  this, SLOT(handleCustomContextMenuRequested(QPoint)));
48 
49  connect (m_terminalView, SIGNAL (interrupt_signal (void)),
50  this, SLOT (terminal_interrupt ()));
51 
52 #ifdef Q_OS_MAC
53  QFont font = QFont("Monaco");
54  font.setStyleHint(QFont::TypeWriter);
55  font.setPointSize(11);
56 #else
57  QFont font = QFont("Monospace");
58  font.setStyleHint(QFont::TypeWriter);
59  font.setPointSize(10);
60 #endif
61  setTerminalFont(font);
62  setFocusPolicy (Qt::StrongFocus);
63  setFocusProxy(m_terminalView);
64  setFocus(Qt::OtherFocusReason);
65 
66  m_kpty = new KPty();
67  m_kpty->open();
68 
71  m_terminalModel->setCodec(QTextCodec::codecForName("UTF-8"));
77  connectToPty();
78 }
80 {
81  if (value > 0)
82  {
85  }
86  else
88 }
89 
91 {
92  // Store the file descriptor associated with the STDERR stream onto
93  // another temporary file descriptor for reconnect in the destructor.
94  fdstderr = dup (STDERR_FILENO);
95 
96  int fds = m_kpty->slaveFd();
97 
98  dup2 (fds, STDIN_FILENO);
99  dup2 (fds, STDOUT_FILENO);
100  dup2 (fds, STDERR_FILENO);
101 
102  if(!isatty(STDIN_FILENO)) {
103  qDebug("Error: stdin is not a tty.");
104  }
105 
106  if(!isatty(STDOUT_FILENO)) {
107  qDebug("Error: stdout is not a tty.");
108  }
109 
110  if(!isatty(STDERR_FILENO)) {
111  qDebug("Error: stderr is not a tty.");
112  }
113 }
114 
116 {
117  delete m_terminalModel;
118  delete m_kpty;
119  delete m_terminalView;
120 
121  // Restore stderr so that any errors at exit might appear somewhere.
122  dup2 (fdstderr, STDERR_FILENO);
123 
124  emit destroyed();
125 }
126 
127 void QUnixTerminalImpl::setTerminalFont(const QFont &font)
128 {
129  if(!m_terminalView)
130  return;
131  m_terminalView->setVTFont(font);
132 }
133 
135 {
136  if(!m_terminalView)
137  return;
138  m_terminalView->setSize(h, v);
139 }
140 
141 void QUnixTerminalImpl::sendText(const QString& text)
142 {
143  m_terminalModel->sendText(text);
144 }
145 
147 {
148  switch(type) {
152  }
154 }
155 
156 // FIXME -- not sure how to make these work properly given the way the
157 // Unix terminal handles colors.
158 void QUnixTerminalImpl::setBackgroundColor (const QColor& color)
159  {
160  ColorEntry cols[TABLE_COLORS];
161 
162  const ColorEntry * curr_cols = m_terminalView->colorTable();
163  for(int i=0;i<TABLE_COLORS;i++)
164  {
165  cols[i] = curr_cols[i];
166  }
167 
168  cols[DEFAULT_BACK_COLOR].color = color;
169 
171 
172  }
173 void QUnixTerminalImpl::setForegroundColor (const QColor& color)
174 {
175  ColorEntry cols[TABLE_COLORS];
176 
177  const ColorEntry * curr_cols = m_terminalView->colorTable();
178  for(int i=0;i<TABLE_COLORS;i++)
179  {
180  cols[i] = curr_cols[i];
181  }
182 
183  cols[DEFAULT_FORE_COLOR].color = color;
184 
186 
187 
188 }
189 void QUnixTerminalImpl::setSelectionColor (const QColor& color) { }
190 
191 void QUnixTerminalImpl::setCursorColor (bool useForegroundColor,
192  const QColor& color)
193 {
194  m_terminalView->setKeyboardCursorColor (useForegroundColor, color);
195 }
196 
198 {
200  m_terminalView->repaint();
201  m_terminalView->update();
202 }
203 
205 {
206  m_terminalView->resize(this->size());
208  m_terminalView->repaint();
209  m_terminalView->update();
210 }
211 
213 {
215 }
216 
218 {
220 }
221 
223 {
225 }
226 
227 
229 {
230  return m_terminalView->selectedText ();
231 }
232 
233 void
235 {
236  _extra_interrupt = extra;
237 }
An entry in a terminal display's color palette.
void addView(TerminalView *widget)
Adds a new view for this session.
void setTerminalSizeStartup(bool on)
Sets whether the terminal size display is shown briefly after the widget is first shown...
Definition: TerminalView.h:379
int dup2(int old_fd, int new_fd)
Definition: oct-syscalls.cc:50
#define TABLE_COLORS
void setScrollBarPosition(ScrollBarPosition position)
Specifies whether the terminal display has a vertical scroll bar, and if so whether it is shown on th...
void setSize(int h, int v)
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition: TerminalModel.h:57
void setTerminalSizeHint(bool on)
Sets whether or not the current height and width of the terminal in lines and columns is displayed wh...
Definition: TerminalView.h:366
void setKeyboardCursorShape(KeyboardCursorShape shape)
Sets the shape of the keyboard cursor.
void sendText(const QString &text) const
Sends text to the current foreground terminal program.
void run()
Starts the terminal session.
void clearHistory()
Clears the history store used by this session.
#define DEFAULT_FORE_COLOR
void interrupt_signal(void)
void setColorTable(const ColorEntry table[])
Sets the terminal color palette used by the display.
void setCursorType(CursorType type, bool blinking)
#define isatty
void setKeyBindings(const QString &id)
Sets the key bindings used by this session.
Select the whole line underneath the cursor.
Definition: TerminalView.h:165
void terminal_interrupt(void)
Definition: QTerminal.h:113
TerminalView * m_terminalView
#define STDIN_FILENO
Definition: sysdep.cc:93
void setSize(int cols, int lins)
bool open()
Create a pty master/slave pair.
Definition: kpty.cpp:212
QColor color
The color value of this entry for display.
void setHistoryType(const HistoryType &type)
Sets the type of history store used by this session.
QString selectedText()
int slaveFd() const
Definition: kpty.cpp:486
Show the scroll bar on the right side of the display.
Definition: TerminalView.h:98
An cursor shaped like the capital letter 'I', similar to the IBeam cursor used in Qt/KDE text editors...
Definition: TerminalView.h:196
A rectangular block which covers the entire area of the cursor character.
Definition: TerminalView.h:186
double h
Definition: graphics.cc:11205
void selectAll()
selects all content
TerminalModel * m_terminalModel
void has_extra_interrupt(bool extra_interrupt)
idx type
Definition: ov.cc:3129
void setBellMode(int mode)
Sets the type of effect used to alert the user when a 'bell' occurs in the terminal session...
void setCursorColor(bool useForegroundColor, const QColor &color)
void pasteClipboard()
Pastes the content of the clipboard into the display.
void setDarkBackground(bool darkBackground)
Sets whether the session has a dark background or not.
void setBlinkingCursor(bool blink)
Specifies whether or not the cursor blinks.
void setForegroundColor(const QColor &color)
void setTerminalFont(const QFont &font)
virtual void resizeEvent(QResizeEvent *)
void setKeyboardCursorColor(bool useForegroundColor, const QColor &color)
Sets the color used to draw the keyboard cursor.
void showEvent(QShowEvent *)
void setCodec(QTextCodec *codec)
Sets the text codec used by this session's terminal emulation.
void sendText(const QString &text)
QUnixTerminalImpl(QWidget *parent=0)
void copyClipboard(bool extra_interrupt)
Copies the selected text to the clipboard.
void setAutoClose(bool b)
Specifies whether to close the session automatically when the terminal process terminates.
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
void setScrollBufferSize(int value)
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
void setBackgroundColor(const QColor &color)
KDE notification.
Definition: TerminalView.h:317
A single flat line which occupies the space at the bottom of the cursor character's area...
Definition: TerminalView.h:191
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
Definition: TerminalView.h:63
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable or any other valid Octave code The number of return their size
Definition: input.cc:871
Provides primitives for opening & closing a pseudo TTY pair, assigning the controlling TTY...
Definition: kpty.h:35
const ColorEntry * colorTable() const
Returns the terminal color palette used by the display.
void setVTFont(const QFont &font)
Sets the font used to draw the display.
void setSelectionColor(const QColor &color)
virtual void handleCustomContextMenuRequested(const QPoint &at)
Definition: QTerminal.cc:94
void updateImage()
Causes the terminal display to fetch the latest character image from the associated terminal screen (...
void setTripleClickMode(TripleClickMode mode)
Sets how the text is selected when the user triple clicks within the display.
Definition: TerminalView.h:170
#define DEFAULT_BACK_COLOR