28#include <QtCore5Compat/QTextCodec>
35#include "KeyboardTranslator.h"
36#include "HistorySearch.h"
40 ,m_session(createSession(
QString()))
47 qDebug() << m_session->iconText() << m_session->iconName() << m_session->isMonitorSilence() << m_session->program() << state;
49 Q_EMIT hasActiveProcessChanged();
51 if(m_processName != m_session->foregroundProcessName())
53 m_processName = m_session->foregroundProcessName();
54 Q_EMIT foregroundProcessNameChanged();
59 m_session->setMonitorSilenceSeconds(30);
63 Q_EMIT bellRequest(message);
68 qDebug() <<
"changeTabTextColorRequest" << state;
73 qDebug() <<
"changeTabTextColorRequest" << state;
78 qDebug() <<
"changeBackgroundColorRequest" << state;
83 qDebug() <<
"openUrlRequest" << state;
86 connect(m_session.get(), &Konsole::Session::activity, [
this]()
88 qDebug() <<
"activity";
89 Q_EMIT processHasSilent(false);
92 connect(m_session.get(), &Konsole::Session::silence, [
this]()
94 qDebug() <<
"silence";
95 Q_EMIT processHasSilent(true);
104 m_session->disconnect();
110 if(m_session->isMonitorSilence() == value)
113 m_session->setMonitorSilence(value);
119 return m_session->isMonitorSilence();
124 m_session->setTitle(Session::NameRole, name);
127std::unique_ptr<Session> KSession::createSession(
QString name)
129 auto session = std::make_unique<Session>();
131 session->setTitle(Session::NameRole, name);
143 QString envshell = getenv(
"SHELL");
144 QString shellProg = !envshell.
isNull() ? envshell : QStringLiteral(
"/bin/bash");
145 session->setProgram(shellProg);
147 setenv(
"TERM",
"xterm-256color", 1);
152 session->setArguments(
args);
153 session->setAutoClose(
true);
155 session->setCodec(QTextCodec::codecForName(
"UTF-8"));
157 session->setFlowControlEnabled(
true);
158 session->setHistoryType(HistoryTypeBuffer(1000));
160 session->setDarkBackground(
true);
162 session->setKeyBindings(
QString());
171int KSession::getRandomSeed()
173 return m_session->sessionId() * 31;
178 m_session->setView(display);
183 m_session->removeView(display);
186void KSession::sessionFinished()
191void KSession::selectionChanged(
bool textSelected)
193 Q_UNUSED(textSelected)
196bool KSession::isLocalUrl(
const QString &url)
199 return file.exists();
204 if (m_session->isRunning())
214 if (!m_session->isRunning())
219 return m_session->sendSignal(signal);
224 return m_session->processId();
239 strCmd.
append(u
" | tail -1 | awk '{ print $5 }' | grep -q \\+");
247 sendText(QStringLiteral(
"\x05\x15"));
256 m_session->setEnvironment(environment);
261 if(m_session->program() == progname)
264 m_session->setProgram(progname);
270 return m_session->program();
275 if(_initialWorkingDirectory != dir)
277 _initialWorkingDirectory = dir;
278 m_session->setInitialWorkingDirectory(dir);
284QString KSession::getInitialWorkingDirectory()
286 return _initialWorkingDirectory;
291 if(m_session->arguments() ==
args)
294 m_session->setArguments(
args);
300 m_session->setCodec(codec);
308 m_session->setHistoryType(HistoryTypeFile());
310 m_session->setHistoryType(HistoryTypeBuffer(lines));
318 if(m_session->historyType().isUnlimited())
322 return m_session->historyType().maximumLineCount();
326QString KSession::getHistory()
const
332 historyDecoder.
begin(&historyStream);
333 m_session->emulation()->writeToStream(&historyDecoder);
334 historyDecoder.
end();
341 m_session->sendText(text);
363 m_session->emulation()->clearEntireScreen();
368 HistorySearch *
history =
new HistorySearch(
QPointer<Emulation>(m_session->emulation()), QRegExp(regexp), forwards, startColumn, startLine,
this);
376 m_session->setFlowControlEnabled(enabled);
381 return m_session->flowControlEnabled();
386 m_session->setKeyBindings(kb);
390QString KSession::getKeyBindings()
392 return m_session->keyBindings();
402 return m_session->keyBindings();
416 return m_session->userTitle();
421 return m_session->processId() != m_session->foregroundProcessId();
426 return m_session->foregroundProcessName();
431 return m_session->currentDir();
436 return m_session->arguments();
QString history
The commands history.
void clearScreen()
clearScreen
void titleChanged()
titleChanged
void removeView(TerminalDisplay *display)
removeView
void startShellProgram()
startShellProgram
void addView(TerminalDisplay *display)
addView
void search(const QString ®exp, int startLine=0, int startColumn=0, bool forwards=true)
Search history.
bool sendSignal(int signal)
sendSignal
void noMatchFound()
noMatchFound
void initialWorkingDirectoryChanged()
initialWorkingDirectoryChanged
QString keyBindings()
Return current key bindings.
QString currentDir
The current directory of the session.
void setTitle(QString name)
setTitle
void changedKeyBindings(QString kb)
changedKeyBindings
QString foregroundProcessName
The name of the current process running.
void setInitialWorkingDirectory(const QString &dir)
Initial working directory.
void changeDir(const QString &dir)
changeDir
void setArgs(const QStringList &args)
Shell program args, default is none.
void setShellProgram(const QString &progname)
Shell program, default is /bin/bash
void monitorSilenceChanged()
monitorSilenceChanged
void sendKey(int rep, int key, int mod) const
Emulate a key press.
bool hasActiveProcess
Whether the session has an active process running.
int historySize
Allows to set the amount of lines to store in the history.
void setEnvironment(const QStringList &environment)
Set the custom enviroment variables.
void matchFound(int startColumn, int startLine, int endColumn, int endLine)
matchFound
void shellProgramChanged()
shellProgramChanged
void setKeyBindings(const QString &kb)
Set named key binding for the session.
QStringList args() const
args
int getShellPID()
getShellPID
void currentDirChanged()
currentDirChanged
void setHistorySize(int lines)
History size for scrolling.
void setMonitorSilence(bool value)
setMonitorSilence
void setFlowControlEnabled(bool enabled)
Sets whether flow control is enabled.
bool flowControlEnabled(void)
Returns whether flow control is enabled.
static QStringList availableKeyBindings()
Sets whether the flow control warning box should be shown when the flow control stop key (Ctrl+S) is ...
void argsChanged()
argsChanged
void setTextCodec(QTextCodec *codec)
Text codec, default is UTF-8.
void historySizeChanged()
historySizeChanged
void sendText(QString text)
Send some text to terminal.
QString shellProgram
Allows to change the default shell program, by default bash is used.
bool monitorSilence
Whether to monitor when the session has gone silent.
QList< QString > allTranslators()
Returns a list of the names of available keyboard translators.
static KeyboardTranslatorManager * instance()
Returns the global KeyboardTranslatorManager instance.
A terminal character decoder which produces plain text, ignoring colours and other appearance-related...
void end() override
End decoding.
void begin(QTextStream *output) override
Begin decoding characters.
void started()
Emitted when the terminal process starts.
void finished()
Emitted when the terminal process exits.
void titleChanged()
Emitted when the session's title has changed.
void openUrlRequest(const QString &url)
TODO: Document me.
void changeTabTextColorRequest(int)
Requests that the color the text for any tabs associated with this session should be changed;.
void stateChanged(int state)
Emitted when the activity state of this session changes.
void changeBackgroundColorRequest(const QColor &)
Requests that the background color of views on this session should be changed.
void bellRequest(const QString &message)
Emitted when a bell event occurs in the session.
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
KCOREADDONS_EXPORT QString quoteArg(const QString &arg)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString & append(QChar ch)
bool isNull() const const
QString & prepend(QChar ch)
QString & setNum(double n, char format, int precision)
std::string toStdString() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)