forked from qt-creator/qt-creator
Terminal: Allow the underlying application to set title
Change-Id: I3530d645f16047df2546902d900e5e2fee8d071c Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
1bd2e84f9a
commit
9a7f45cc46
@@ -219,23 +219,15 @@ void TerminalPane::setupTerminalWidget(TerminalWidget *terminal)
|
|||||||
if (!terminal)
|
if (!terminal)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto setTabText = [this, terminal]() {
|
const auto setTabText = [this, terminal] {
|
||||||
const int index = m_tabWidget.indexOf(terminal);
|
const int index = m_tabWidget.indexOf(terminal);
|
||||||
const FilePath cwd = terminal->cwd();
|
m_tabWidget.setTabText(index, terminal->title());
|
||||||
|
|
||||||
const QString exe = terminal->currentCommand().isEmpty()
|
|
||||||
? terminal->shellName()
|
|
||||||
: terminal->currentCommand().executable().fileName();
|
|
||||||
|
|
||||||
if (cwd.isEmpty())
|
|
||||||
m_tabWidget.setTabText(index, exe);
|
|
||||||
else
|
|
||||||
m_tabWidget.setTabText(index, exe + " - " + cwd.fileName());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(terminal, &TerminalWidget::started, this, setTabText);
|
connect(terminal, &TerminalWidget::started, this, setTabText);
|
||||||
connect(terminal, &TerminalWidget::cwdChanged, this, setTabText);
|
connect(terminal, &TerminalWidget::cwdChanged, this, setTabText);
|
||||||
connect(terminal, &TerminalWidget::commandChanged, this, setTabText);
|
connect(terminal, &TerminalWidget::commandChanged, this, setTabText);
|
||||||
|
connect(terminal, &TerminalWidget::titleChanged, this, setTabText);
|
||||||
|
|
||||||
if (!terminal->shellName().isEmpty())
|
if (!terminal->shellName().isEmpty())
|
||||||
setTabText();
|
setTabText();
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ struct TerminalSurfacePrivate
|
|||||||
case VTERM_PROP_ICONNAME:
|
case VTERM_PROP_ICONNAME:
|
||||||
break;
|
break;
|
||||||
case VTERM_PROP_TITLE:
|
case VTERM_PROP_TITLE:
|
||||||
|
emit q->titleChanged(QString::fromUtf8(val->string.str, val->string.len));
|
||||||
break;
|
break;
|
||||||
case VTERM_PROP_ALTSCREEN:
|
case VTERM_PROP_ALTSCREEN:
|
||||||
m_altscreen = val->boolean;
|
m_altscreen = val->boolean;
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ signals:
|
|||||||
void altscreenChanged(bool altScreen);
|
void altscreenChanged(bool altScreen);
|
||||||
void unscroll();
|
void unscroll();
|
||||||
void bell();
|
void bell();
|
||||||
|
void titleChanged(const QString &title);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<TerminalSurfacePrivate> d;
|
std::unique_ptr<TerminalSurfacePrivate> d;
|
||||||
|
|||||||
@@ -399,6 +399,18 @@ void TerminalWidget::setupSurface()
|
|||||||
if (TerminalSettings::instance().audibleBell.value())
|
if (TerminalSettings::instance().audibleBell.value())
|
||||||
QApplication::beep();
|
QApplication::beep();
|
||||||
});
|
});
|
||||||
|
connect(m_surface.get(),
|
||||||
|
&Internal::TerminalSurface::titleChanged,
|
||||||
|
this,
|
||||||
|
[this](const QString &title) {
|
||||||
|
const FilePath titleFile = FilePath::fromUserInput(title);
|
||||||
|
if (!m_title.isEmpty()
|
||||||
|
|| m_openParameters.shellCommand.value_or(CommandLine{}).executable()
|
||||||
|
!= titleFile) {
|
||||||
|
m_title = titleFile.isFile() ? titleFile.baseName() : title;
|
||||||
|
}
|
||||||
|
emit titleChanged();
|
||||||
|
});
|
||||||
|
|
||||||
if (m_shellIntegration) {
|
if (m_shellIntegration) {
|
||||||
connect(m_shellIntegration.get(),
|
connect(m_shellIntegration.get(),
|
||||||
@@ -442,6 +454,17 @@ QColor TerminalWidget::toQColor(std::variant<int, QColor> color) const
|
|||||||
return std::get<QColor>(color);
|
return std::get<QColor>(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TerminalWidget::title() const
|
||||||
|
{
|
||||||
|
const FilePath dir = cwd();
|
||||||
|
QString title = m_title;
|
||||||
|
if (title.isEmpty())
|
||||||
|
title = currentCommand().isEmpty() ? shellName() : currentCommand().executable().fileName();
|
||||||
|
if (dir.isEmpty())
|
||||||
|
return title;
|
||||||
|
return title + " - " + dir.fileName();
|
||||||
|
}
|
||||||
|
|
||||||
void TerminalWidget::updateCopyState()
|
void TerminalWidget::updateCopyState()
|
||||||
{
|
{
|
||||||
if (!hasFocus())
|
if (!hasFocus())
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ public:
|
|||||||
|
|
||||||
void setShellName(const QString &shellName);
|
void setShellName(const QString &shellName);
|
||||||
QString shellName() const;
|
QString shellName() const;
|
||||||
|
QString title() const;
|
||||||
|
|
||||||
Utils::FilePath cwd() const;
|
Utils::FilePath cwd() const;
|
||||||
Utils::CommandLine currentCommand() const;
|
Utils::CommandLine currentCommand() const;
|
||||||
@@ -98,6 +99,7 @@ signals:
|
|||||||
void started(qint64 pid);
|
void started(qint64 pid);
|
||||||
void cwdChanged(const Utils::FilePath &cwd);
|
void cwdChanged(const Utils::FilePath &cwd);
|
||||||
void commandChanged(const Utils::CommandLine &cmd);
|
void commandChanged(const Utils::CommandLine &cmd);
|
||||||
|
void titleChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
@@ -207,6 +209,7 @@ private:
|
|||||||
bool m_ignoreScroll{false};
|
bool m_ignoreScroll{false};
|
||||||
|
|
||||||
QString m_preEditString;
|
QString m_preEditString;
|
||||||
|
QString m_title;
|
||||||
|
|
||||||
std::optional<Selection> m_selection;
|
std::optional<Selection> m_selection;
|
||||||
std::optional<LinkSelection> m_linkSelection;
|
std::optional<LinkSelection> m_linkSelection;
|
||||||
|
|||||||
4
src/plugins/terminal/tests/title
Executable file
4
src/plugins/terminal/tests/title
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo -e "\033[1m ⎆ The terminal title should have changed to 'Test Title'\033[0m"
|
||||||
|
echo -e "\033]0;Test Title\007"
|
||||||
Reference in New Issue
Block a user