28#include <QtCore5Compat/QTextCodec>
34#include "KeyboardTranslator.h"
35#include "HistorySearch.h"
39 ,m_session(createSession(
QString()))
46 qDebug() << m_session->iconText() << m_session->iconName() << m_session->isMonitorSilence() << m_session->program() << state;
48 Q_EMIT hasActiveProcessChanged();
50 if(m_processName != m_session->foregroundProcessName())
52 m_processName = m_session->foregroundProcessName();
53 Q_EMIT foregroundProcessNameChanged();
58 m_session->setMonitorSilenceSeconds(30);
62 Q_EMIT bellRequest(message);
67 qDebug() <<
"changeTabTextColorRequest" << state;
72 qDebug() <<
"changeTabTextColorRequest" << state;
77 qDebug() <<
"changeBackgroundColorRequest" << state;
82 qDebug() <<
"openUrlRequest" << state;
85 connect(m_session.get(), &Konsole::Session::activity, [
this]()
87 qDebug() <<
"activity";
88 Q_EMIT processHasSilent(false);
91 connect(m_session.get(), &Konsole::Session::silence, [
this]()
93 qDebug() <<
"silence";
94 Q_EMIT processHasSilent(true);
103 m_session->disconnect();
109 if(m_session->isMonitorSilence() == value)
112 m_session->setMonitorSilence(value);
118 return m_session->isMonitorSilence();
123 m_session->setTitle(Session::NameRole, name);
126std::unique_ptr<Session> KSession::createSession(
QString name)
128 auto session = std::make_unique<Session>();
130 session->setTitle(Session::NameRole, name);
142 QString envshell = getenv(
"SHELL");
143 QString shellProg = !envshell.
isNull() ? envshell : QStringLiteral(
"/bin/bash");
144 session->setProgram(shellProg);
146 setenv(
"TERM",
"xterm-256color", 1);
151 session->setArguments(
args);
152 session->setAutoClose(
true);
154 session->setCodec(QTextCodec::codecForName(
"UTF-8"));
156 session->setFlowControlEnabled(
true);
157 session->setHistoryType(HistoryTypeBuffer(1000));
159 session->setDarkBackground(
true);
161 session->setKeyBindings(
QString());
170int KSession::getRandomSeed()
172 return m_session->sessionId() * 31;
177 m_session->setView(display);
182 m_session->removeView(display);
185void KSession::sessionFinished()
190void KSession::selectionChanged(
bool textSelected)
192 Q_UNUSED(textSelected)
197 if (m_session->isRunning())
207 if (!m_session->isRunning())
212 return m_session->sendSignal(signal);
217 return m_session->processId();
232 strCmd.
append(u
" | tail -1 | awk '{ print $5 }' | grep -q \\+");
240 sendText(QStringLiteral(
"\x05\x15"));
249 m_session->setEnvironment(environment);
254 if(m_session->program() == progname)
257 m_session->setProgram(progname);
263 return m_session->program();
268 if(_initialWorkingDirectory != dir)
270 _initialWorkingDirectory = dir;
271 m_session->setInitialWorkingDirectory(dir);
277QString KSession::getInitialWorkingDirectory()
279 return _initialWorkingDirectory;
284 if(m_session->arguments() ==
args)
287 m_session->setArguments(
args);
293 m_session->setCodec(codec);
301 m_session->setHistoryType(HistoryTypeFile());
303 m_session->setHistoryType(HistoryTypeBuffer(lines));
311 if(m_session->historyType().isUnlimited())
315 return m_session->historyType().maximumLineCount();
319QString KSession::getHistory()
const
325 historyDecoder.
begin(&historyStream);
326 m_session->emulation()->writeToStream(&historyDecoder);
327 historyDecoder.
end();
334 m_session->sendText(text);
356 m_session->emulation()->clearEntireScreen();
361 HistorySearch *
history =
new HistorySearch(
QPointer<Emulation>(m_session->emulation()), QRegExp(regexp), forwards, startColumn, startLine,
this);
369 m_session->setFlowControlEnabled(enabled);
374 return m_session->flowControlEnabled();
379 m_session->setKeyBindings(kb);
383QString KSession::getKeyBindings()
385 return m_session->keyBindings();
395 return m_session->keyBindings();
409 return m_session->userTitle();
414 return m_session->processId() != m_session->foregroundProcessId();
419 return m_session->foregroundProcessName();
424 return m_session->currentDir();
429 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)