28#include <QtCore5Compat/QTextCodec>
34#include "KeyboardTranslator.h"
35#include "HistorySearch.h"
39 ,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();
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)
198 if (m_session->isRunning())
208 if (!m_session->isRunning())
213 return m_session->sendSignal(signal);
218 return m_session->processId();
233 strCmd.
append(u
" | tail -1 | awk '{ print $5 }' | grep -q \\+");
241 sendText(QStringLiteral(
"\x05\x15"));
250 m_session->setEnvironment(environment);
255 if(m_session->program() == progname)
258 m_session->setProgram(progname);
264 return m_session->program();
269 if(_initialWorkingDirectory != dir)
271 _initialWorkingDirectory = dir;
272 m_session->setInitialWorkingDirectory(dir);
278QString KSession::getInitialWorkingDirectory()
280 return _initialWorkingDirectory;
285 if(m_session->arguments() ==
args)
288 m_session->setArguments(
args);
294 m_session->setCodec(codec);
302 m_session->setHistoryType(HistoryTypeFile());
304 m_session->setHistoryType(HistoryTypeBuffer(lines));
312 if(m_session->historyType().isUnlimited())
316 return m_session->historyType().maximumLineCount();
320QString KSession::getHistory()
const
323 QTextStream historyStream(&
history);
324 PlainTextDecoder historyDecoder;
326 historyDecoder.
begin(&historyStream);
327 m_session->emulation()->writeToStream(&historyDecoder);
328 historyDecoder.
end();
335 m_session->sendText(text);
357 m_session->emulation()->clearEntireScreen();
362 HistorySearch *
history =
new HistorySearch(
QPointer<Emulation>(m_session->emulation()), QRegExp(regexp), forwards, startColumn, startLine,
this);
370 m_session->setFlowControlEnabled(enabled);
375 return m_session->flowControlEnabled();
380 m_session->setKeyBindings(kb);
384QString KSession::getKeyBindings()
386 return m_session->keyBindings();
396 return m_session->keyBindings();
410 return m_session->userTitle();
415 return m_session->processId() != m_session->foregroundProcessId();
420 return m_session->foregroundProcessName();
425 return m_session->currentDir();
430 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.
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.
@ NameRole
The name of the session.
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)