GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
QUnixTerminalImpl.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 e_k (e_k@users.sourceforge.net)
2  Copyright (C) 2012-2018 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(p),
29  _parent (p)
30 {
31  setMinimumSize(300, 200);
32  initialize();
33 }
34 
36 {
37  m_terminalView = new TerminalView(this);
42  m_terminalView->setContextMenuPolicy(Qt::CustomContextMenu);
45  m_terminalView->setSize(80, 40);
47 
48  UrlFilter *url_filter = new UrlFilter();
49  m_terminalView->filterChain ()->addFilter (url_filter);
50 
51  UrlFilter *file_filter = new UrlFilter (Filter::Type::ErrorLink);
52  m_terminalView->filterChain ()->addFilter (file_filter);
53 
54  connect (file_filter, SIGNAL (request_edit_mfile_signal (const QString&, int)),
55  _parent, SLOT (edit_mfile (const QString&, int)));
56  connect (file_filter, SIGNAL (request_open_file_signal (const QString&, int)),
57  _parent, SLOT (open_file (const QString&, int)));
58 
59  connect(m_terminalView, SIGNAL(customContextMenuRequested(QPoint)),
60  this, SLOT(handleCustomContextMenuRequested(QPoint)));
61 
62  connect (m_terminalView, SIGNAL (interrupt_signal (void)),
63  this, SLOT (terminal_interrupt ()));
64 
65 #ifdef Q_OS_MAC
66  QFont font = QFont("Monaco");
67  font.setStyleHint(QFont::TypeWriter);
68  font.setPointSize(11);
69 #else
70  QFont font = QFont("Monospace");
71  font.setStyleHint(QFont::TypeWriter);
72  font.setPointSize(10);
73 #endif
74  setTerminalFont(font);
75  setFocusPolicy (Qt::StrongFocus);
76  setFocusProxy(m_terminalView);
77  setFocus(Qt::OtherFocusReason);
78 
79  m_kpty = new KPty();
80  m_kpty->open();
81 
84  m_terminalModel->setCodec(QTextCodec::codecForName("UTF-8"));
90  connectToPty();
91 }
93 {
94  if (value > 0)
95  {
98  }
99  else
101 }
102 
105 {
106  return m_terminalView->filterActions (at);
107 }
108 
110 {
111  // Store the file descriptor associated with the STDERR stream onto
112  // another temporary file descriptor for reconnect in the destructor.
113  fdstderr = dup (STDERR_FILENO);
114 
115  int fds = m_kpty->slaveFd();
116 
117  dup2 (fds, STDIN_FILENO);
118  dup2 (fds, STDOUT_FILENO);
119  dup2 (fds, STDERR_FILENO);
120 
121  if(!isatty(STDIN_FILENO)) {
122  qDebug("Error: stdin is not a tty.");
123  }
124 
125  if(!isatty(STDOUT_FILENO)) {
126  qDebug("Error: stdout is not a tty.");
127  }
128 
129  if(!isatty(STDERR_FILENO)) {
130  qDebug("Error: stderr is not a tty.");
131  }
132 }
133 
135 {
136  delete m_terminalModel;
137  delete m_kpty;
138  delete m_terminalView;
139 
140  // Restore stderr so that any errors at exit might appear somewhere.
141  dup2 (fdstderr, STDERR_FILENO);
142 
143  emit destroyed();
144 }
145 
146 void QUnixTerminalImpl::setTerminalFont(const QFont &font)
147 {
148  if(!m_terminalView)
149  return;
150  m_terminalView->setVTFont(font);
151 }
152 
154 {
155  if(!m_terminalView)
156  return;
157  m_terminalView->setSize(h, v);
158 }
159 
160 void QUnixTerminalImpl::sendText(const QString& text)
161 {
163 }
164 
166 {
167  switch(type) {
171  }
173 }
174 
175 // FIXME -- not sure how to make these work properly given the way the
176 // Unix terminal handles colors.
177 void QUnixTerminalImpl::setBackgroundColor (const QColor& color)
178  {
179  ColorEntry cols[TABLE_COLORS];
180 
181  const ColorEntry * curr_cols = m_terminalView->colorTable();
182  for(int i=0;i<TABLE_COLORS;i++)
183  {
184  cols[i] = curr_cols[i];
185  }
186 
187  cols[DEFAULT_BACK_COLOR].color = color;
188 
190 
191  }
192 void QUnixTerminalImpl::setForegroundColor (const QColor& color)
193 {
194  ColorEntry cols[TABLE_COLORS];
195 
196  const ColorEntry * curr_cols = m_terminalView->colorTable();
197  for(int i=0;i<TABLE_COLORS;i++)
198  {
199  cols[i] = curr_cols[i];
200  }
201 
202  cols[DEFAULT_FORE_COLOR].color = color;
203 
205 
206 
207 }
208 void QUnixTerminalImpl::setSelectionColor (const QColor& color) { }
209 
210 void QUnixTerminalImpl::setCursorColor (bool useForegroundColor,
211  const QColor& color)
212 {
213  m_terminalView->setKeyboardCursorColor (useForegroundColor, color);
214 }
215 
217 {
219  m_terminalView->repaint();
220  m_terminalView->update();
221 }
222 
224 {
225  m_terminalView->resize(this->size());
227  m_terminalView->repaint();
228  m_terminalView->update();
229 }
230 
232 {
234 }
235 
237 {
239 }
240 
242 {
244 }
245 
246 
248 {
249  return m_terminalView->selectedText ();
250 }
251 
252 void
254 {
255  _extra_interrupt = extra;
256 }
257 
258 void
260 {
262 };
An entry in a terminal display&#39;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:363
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:350
QList< QAction * > get_hotspot_actions(const QPoint &at)
void setKeyboardCursorShape(KeyboardCursorShape shape)
Sets the shape of the keyboard cursor.
void run()
Starts the terminal session.
void clearHistory()
Clears the history store used by this session.
virtual void handle_visibility_changed(bool visible)
#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)
void addFilter(Filter *filter)
Adds a new filter to the chain.
Definition: Filter.cpp:54
void visibility_changed(bool visible)
Is called, when the terminal&#39;s visibility has changed in order to stop orstart timers etc...
A filter which matches URLs in blocks of text.
Definition: Filter.h:265
void setKeyBindings(const QString &id)
Sets the key bindings used by this session.
Select the whole line underneath the cursor.
Definition: TerminalView.h:149
void terminal_interrupt(void)
Definition: QTerminal.h:116
FilterChain * filterChain() const
Returns the display&#39;s filter chain.
TerminalView * m_terminalView
#define STDIN_FILENO
Definition: sysdep.cc:88
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.
QList< QAction * > filterActions(const QPoint &position)
Returns a list of menu actions created by the filters for the content at the given position...
QString selectedText()
Show the scroll bar on the right side of the display.
Definition: TerminalView.h:98
An cursor shaped like the capital letter &#39;I&#39;, similar to the IBeam cursor used in Qt/KDE text editors...
Definition: TerminalView.h:180
A rectangular block which covers the entire area of the cursor character.
Definition: TerminalView.h:170
const ColorEntry * colorTable() const
Returns the terminal color palette used by the display.
double h
Definition: graphics.cc:11808
void selectAll()
selects all content
TerminalModel * m_terminalModel
int slaveFd() const
Definition: kpty.cpp:486
void has_extra_interrupt(bool extra_interrupt)
OCTAVE_EXPORT octave_value_list at
Definition: time.cc:115
idx type
Definition: ov.cc:3114
void setBellMode(int mode)
Sets the type of effect used to alert the user when a &#39;bell&#39; 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&#39;s terminal emulation.
void sendText(const QString &text)
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.
void setScrollBufferSize(int value)
p
Definition: lu.cc:138
void setBackgroundColor(const QColor &color)
KDE notification.
Definition: TerminalView.h:301
A single flat line which occupies the space at the bottom of the cursor character&#39;s area...
Definition: TerminalView.h:175
for i
Definition: data.cc:5264
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
Definition: TerminalView.h:63
Provides primitives for opening & closing a pseudo TTY pair, assigning the controlling TTY...
Definition: kpty.h:35
void sendText(const QString &text) const
Sends text to the current foreground terminal program.
nd group nd example For each display the value
Definition: sysdep.cc:866
QUnixTerminalImpl(QWidget *parent=nullptr)
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:154
#define DEFAULT_BACK_COLOR