28#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
31#include <QtCore5Compat/QTextCodec>
38#include "KeyboardTranslator.h"
39#include "HistorySearch.h"
43 ,m_session(createSession(
QString()))
50 qDebug() << m_session->iconText() << m_session->iconName() << m_session->isMonitorSilence() << m_session->program() << state;
52 Q_EMIT hasActiveProcessChanged();
54 if(m_processName != m_session->foregroundProcessName())
56 m_processName = m_session->foregroundProcessName();
57 Q_EMIT foregroundProcessNameChanged();
62 m_session->setMonitorSilenceSeconds(30);
66 Q_EMIT bellRequest(message);
71 qDebug() <<
"changeTabTextColorRequest" << state;
76 qDebug() <<
"changeTabTextColorRequest" << state;
81 qDebug() <<
"changeBackgroundColorRequest" << state;
86 qDebug() <<
"openUrlRequest" << state;
89 connect(m_session.get(), &Konsole::Session::activity, [
this]()
91 qDebug() <<
"activity";
92 Q_EMIT processHasSilent(false);
95 connect(m_session.get(), &Konsole::Session::silence, [
this]()
97 qDebug() <<
"silence";
98 Q_EMIT processHasSilent(true);
107 m_session->disconnect();
113 if(m_session->isMonitorSilence() == value)
116 m_session->setMonitorSilence(value);
122 return m_session->isMonitorSilence();
127 m_session->setTitle(Session::NameRole, name);
130std::unique_ptr<Session> KSession::createSession(
QString name)
132 auto session = std::make_unique<Session>();
134 session->setTitle(Session::NameRole, name);
146 QString envshell = getenv(
"SHELL");
147 QString shellProg = !envshell.
isNull() ? envshell : QStringLiteral(
"/bin/bash");
148 session->setProgram(shellProg);
150 setenv(
"TERM",
"xterm-256color", 1);
155 session->setArguments(
args);
156 session->setAutoClose(
true);
158 session->setCodec(QTextCodec::codecForName(
"UTF-8"));
160 session->setFlowControlEnabled(
true);
161 session->setHistoryType(HistoryTypeBuffer(1000));
163 session->setDarkBackground(
true);
165 session->setKeyBindings(
QString());
174int KSession::getRandomSeed()
176 return m_session->sessionId() * 31;
181 m_session->setView(display);
186 m_session->removeView(display);
189void KSession::sessionFinished()
194void KSession::selectionChanged(
bool textSelected)
196 Q_UNUSED(textSelected)
201 if (m_session->isRunning())
211 if (!m_session->isRunning())
216 return m_session->sendSignal(signal);
221 return m_session->processId();
234 strCmd.
append(u
" | tail -1 | awk '{ print $5 }' | grep -q \\+");
242 sendText(QStringLiteral(
"\x05\x15"));
251 m_session->setEnvironment(environment);
256 if(m_session->program() == progname)
259 m_session->setProgram(progname);
265 return m_session->program();
270 if(_initialWorkingDirectory != dir)
272 _initialWorkingDirectory = dir;
273 m_session->setInitialWorkingDirectory(dir);
279QString KSession::getInitialWorkingDirectory()
281 return _initialWorkingDirectory;
286 if(m_session->arguments() ==
args)
289 m_session->setArguments(
args);
295 m_session->setCodec(codec);
303 m_session->setHistoryType(HistoryTypeFile());
305 m_session->setHistoryType(HistoryTypeBuffer(lines));
313 if(m_session->historyType().isUnlimited())
317 return m_session->historyType().maximumLineCount();
321QString KSession::getHistory()
const
327 historyDecoder.
begin(&historyStream);
328 m_session->emulation()->writeToStream(&historyDecoder);
329 historyDecoder.
end();
336 m_session->sendText(text);
358 m_session->emulation()->clearEntireScreen();
363 HistorySearch *
history =
new HistorySearch(
QPointer<Emulation>(m_session->emulation()), QRegExp(regexp), forwards, startColumn, startLine,
this);
371 m_session->setFlowControlEnabled(enabled);
376 return m_session->flowControlEnabled();
381 m_session->setKeyBindings(kb);
385QString KSession::getKeyBindings()
387 return m_session->keyBindings();
397 return m_session->keyBindings();
411 return m_session->userTitle();
416 return m_session->processId() != m_session->foregroundProcessId();
421 return m_session->foregroundProcessName();
426 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.
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)