From a8f5167e86938c57134ade37c4f558c61a8cc088 Mon Sep 17 00:00:00 2001 From: "Yurii.Huang" Date: Fri, 13 Sep 2024 18:16:48 +0800 Subject: [PATCH 1/2] refactor: add scheme style with terminal 1.default use system deepin-terminal scheme 2.not found deepin-terminal scheme, use qrc-file scheme file --- .../console/color-schemes/Dark.colorscheme | 104 ++++++++++++++++++ .../console/color-schemes/Light.colorscheme | 104 ++++++++++++++++++ src/plugins/console/console.qrc | 8 ++ src/plugins/console/consolewidget.cpp | 25 ++++- 4 files changed, 236 insertions(+), 5 deletions(-) create mode 100644 src/plugins/console/color-schemes/Dark.colorscheme create mode 100644 src/plugins/console/color-schemes/Light.colorscheme create mode 100644 src/plugins/console/console.qrc diff --git a/src/plugins/console/color-schemes/Dark.colorscheme b/src/plugins/console/color-schemes/Dark.colorscheme new file mode 100644 index 000000000..80c844106 --- /dev/null +++ b/src/plugins/console/color-schemes/Dark.colorscheme @@ -0,0 +1,104 @@ + +[Background] +Bold=true +Color=37,37,37 +Transparency=false + +[BackgroundIntense] +Bold=true +Color=0,0,0 +Transparency=false + +[Color0] +Bold=true +Color=0,0,0 +Transparency=false + +[Color0Intense] +Bold=true +Color=104,104,104 +Transparency=false + +[Color1] +Bold=true +Color=178,24,24 +Transparency=false + +[Color1Intense] +Bold=true +Color=255,84,84 +Transparency=false + +[Color2] +Bold=true +Color=24,178,24 +Transparency=false + +[Color2Intense] +Bold=true +Color=133,153,0 +Transparency=false + +[Color3] +Bold=true +Color=178,104,24 +Transparency=false + +[Color3Intense] +Bold=true +Color=255,255,84 +Transparency=false + +[Color4] +Bold=true +Color=52,101,164 +Transparency=false + +[Color4Intense] +Bold=true +Color=52,101,164 +Transparency=false + +[Color5] +Bold=true +Color=225,30,225 +Transparency=false + +[Color5Intense] +Bold=true +Color=30,144,255 +Transparency=false + +[Color6] +Bold=true +Color=24,178,178 +Transparency=false + +[Color6Intense] +Bold=true +Color=253,246,227 +Transparency=false + +[Color7] +Bold=true +Color=238,232,213 +Transparency=false + +[Color7Intense] +Bold=true +Color=255,255,255 +Transparency=false + +[Foreground] +Bold=true +Color=0,205,0 +Transparency=false + +[ForegroundIntense] +Bold=true +Color=0,205,0 +Transparency=false + +[General] +Description=Green on Black +Opacity=1 diff --git a/src/plugins/console/color-schemes/Light.colorscheme b/src/plugins/console/color-schemes/Light.colorscheme new file mode 100644 index 000000000..fec4d9db2 --- /dev/null +++ b/src/plugins/console/color-schemes/Light.colorscheme @@ -0,0 +1,104 @@ + +[Background] +Bold=true +Color=248,248,248 +Transparency=false + +[BackgroundIntense] +Bold=true +Color=255,255,255 +Transparency=false + +[Color0] +Bold=true +Color=0,0,0 +Transparency=false + +[Color0Intense] +Bold=true +Color=104,104,104 +Transparency=false + +[Color1] +Bold=true +Color=178,24,24 +Transparency=false + +[Color1Intense] +Bold=true +Color=255,84,84 +Transparency=false + +[Color2] +Bold=true +Color=24,178,24 +Transparency=false + +[Color2Intense] +Bold=true +Color=133,153,0 +Transparency=false + +[Color3] +Bold=true +Color=178,104,24 +Transparency=false + +[Color3Intense] +Bold=true +Color=233,233,79 +Transparency=false + +[Color4] +Bold=true +Color=24,24,178 +Transparency=false + +[Color4Intense] +Bold=true +Color=52,101,164 +Transparency=false + +[Color5] +Bold=true +Color=225,30,225 +Transparency=false + +[Color5Intense] +Bold=true +Color=30,144,255 +Transparency=false + +[Color6] +Bold=true +Color=24,178,178 +Transparency=false + +[Color6Intense] +Bold=true +Color=24,178,178 +Transparency=false + +[Color7] +Bold=true +Color=238,232,213 +Transparency=false + +[Color7Intense] +Bold=true +Color=238,232,213 +Transparency=false + +[Foreground] +Bold=true +Color=0,0,0 +Transparency=false + +[ForegroundIntense] +Bold=true +Color=0,0,0 +Transparency=false + +[General] +Description=Green on Black +Opacity=1 diff --git a/src/plugins/console/console.qrc b/src/plugins/console/console.qrc new file mode 100644 index 000000000..63ac1e355 --- /dev/null +++ b/src/plugins/console/console.qrc @@ -0,0 +1,8 @@ + + + + + color-schemes/Dark.colorscheme + color-schemes/Light.colorscheme + + diff --git a/src/plugins/console/consolewidget.cpp b/src/plugins/console/consolewidget.cpp index c5839c199..86c4b1f09 100644 --- a/src/plugins/console/consolewidget.cpp +++ b/src/plugins/console/consolewidget.cpp @@ -7,6 +7,7 @@ #include +#include #include DWIDGET_USE_NAMESPACE @@ -32,6 +33,12 @@ ConsoleWidget::ConsoleWidget(QWidget *parent, bool startNow) setAutoFillBackground(true); setTerminalOpacity(1); + // using default deepin-terminal style schemes + // U can see schemes path with deepin-os + QString sys_schemes_path = "/usr/share/terminalwidget5/color-schemes"; + if (QDir(sys_schemes_path).exists()) + addCustomColorSchemeDir(sys_schemes_path); + auto theme = DGuiApplicationHelper::instance()->themeType(); updateColorScheme(theme); if (availableKeyBindings().contains("linux")) @@ -85,11 +92,19 @@ void ConsoleWidget::contextMenuEvent(QContextMenuEvent *event) void ConsoleWidget::updateColorScheme(DGuiApplicationHelper::ColorType themetype) { - if (themetype == DGuiApplicationHelper::DarkType - && availableColorSchemes().contains("Linux")) - this->setColorScheme("Linux"); - else if (availableColorSchemes().contains("BlackOnWhite")) - this->setColorScheme("BlackOnWhite"); + if (DGuiApplicationHelper::DarkType == themetype) { + // need add member option setting check logic + if (availableColorSchemes().contains("Dark")) + this->setColorScheme("Dark"); + else + this->setColorScheme(":/color-schemes/Dark.colorscheme"); + } else if (DGuiApplicationHelper::LightType == themetype) { + // need add member option setting check logic + if (availableColorSchemes().contains("Light")) + this->setColorScheme("Light"); + else + this->setColorScheme(":/color-schemes/Light.colorscheme"); + } } void ConsoleWidget::enterCurrentProjectPath() From 7bbf5a9128ea110b8c2453d814403752ae7bcbf1 Mon Sep 17 00:00:00 2001 From: "Yurii.Huang" Date: Wed, 18 Sep 2024 19:54:21 +0800 Subject: [PATCH 2/2] refactor: new/select/run2 console support 1. add new/select/run2 console service interface 2. add logic for console plugin --- src/plugins/console/console.cpp | 3 ++ src/plugins/console/consolemanager.cpp | 45 +++++++++++++++++++++++-- src/plugins/console/consolemanager.h | 6 +++- src/services/terminal/terminalservice.h | 3 ++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/plugins/console/console.cpp b/src/plugins/console/console.cpp index 298e02108..0bdde53d6 100644 --- a/src/plugins/console/console.cpp +++ b/src/plugins/console/console.cpp @@ -43,6 +43,9 @@ bool Console::start() using namespace std::placeholders; terminalService->sendCommand = std::bind(&ConsoleManager::sendCommand, consoleManager, _1); terminalService->executeCommand = std::bind(&ConsoleManager::executeCommand, consoleManager, _1, _2, _3, _4, _5); + terminalService->createConsole = std::bind(&ConsoleManager::newConsole, consoleManager, _1, _2); + terminalService->selectConsole = std::bind(&ConsoleManager::selectConsole, consoleManager, _1); + terminalService->run2Console = std::bind(&ConsoleManager::run2Console, consoleManager, _1, _2); } return true; } diff --git a/src/plugins/console/consolemanager.cpp b/src/plugins/console/consolemanager.cpp index 9cbb00f3f..c8e4dac19 100644 --- a/src/plugins/console/consolemanager.cpp +++ b/src/plugins/console/consolemanager.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,7 @@ class ConsoleManagerPrivate : public QObject void appendConsole(); void removeConsole(); void switchConsole(const QModelIndex &index, const QModelIndex &previous); + void switchConsole(const QUuid &uuid); void updateButtonState(); public: @@ -99,7 +101,8 @@ void ConsoleManagerPrivate::initUI() void ConsoleManagerPrivate::initConnection() { - connect(consoleListView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ConsoleManagerPrivate::switchConsole); + connect(consoleListView->selectionModel(), &QItemSelectionModel::currentChanged, + this, QOverload::of(&ConsoleManagerPrivate::switchConsole)); connect(addConsoleBtn, &DToolButton::clicked, this, &ConsoleManagerPrivate::appendConsole); connect(removeConsoleBtn, &DToolButton::clicked, this, &ConsoleManagerPrivate::removeConsole); connect(model, &QStandardItemModel::rowsRemoved, this, &ConsoleManagerPrivate::updateButtonState); @@ -141,6 +144,13 @@ void ConsoleManagerPrivate::switchConsole(const QModelIndex &index, const QModel } } +void ConsoleManagerPrivate::switchConsole(const QUuid &uuid) { + if (auto console = q->findConsole(uuid.toString())) { + console->setFocus(); + consoleStackedWidget->setCurrentWidget(console); + } +} + void ConsoleManagerPrivate::updateButtonState() { removeConsoleBtn->setEnabled(model->rowCount() > 1); @@ -175,7 +185,7 @@ QTermWidget *ConsoleManager::findConsole(const QString &id) return d->consoleMap.value(id, nullptr); } -QTermWidget *ConsoleManager::createConsole(const QString &name, bool startNow) +QTermWidget *ConsoleManager::createConsole(const QString &name, bool startNow, bool rename) { auto id = QUuid::createUuid().toString(); ConsoleWidget *console = new ConsoleWidget(this, startNow); @@ -184,6 +194,7 @@ QTermWidget *ConsoleManager::createConsole(const QString &name, bool startNow) QStandardItem *item = new QStandardItem(name); item->setData(id, IdRole); + item->setData(rename, Qt::EditRole); d->model->appendRow(item); d->consoleListView->setCurrentIndex(d->model->index(d->model->rowCount() - 1, 0)); @@ -218,6 +229,36 @@ void ConsoleManager::executeCommand(const QString &name, const QString &program, console->sendText(cmd); } +QUuid ConsoleManager::newConsole(const QString &name, bool rename) +{ + auto ptr_term = dynamic_cast(this->createConsole(name, true, rename)); + return QUuid::fromString(d->consoleMap.key(ptr_term, "")); +} + +void ConsoleManager::selectConsole(const QUuid &uuid) +{ + d->switchConsole(uuid); +} + +void ConsoleManager::run2Console(const QUuid &uuid, const QProcess &process) +{ + auto ptr_term = findConsole(uuid.toString()); + if (!ptr_term) + return; + + if (!process.workingDirectory().isEmpty()) + ptr_term->changeDir(process.workingDirectory()); + if (!process.environment().isEmpty()) + ptr_term->setEnvironment(process.environment()); + if (!process.program().isEmpty()) { + QString cmd = process.program(); + if (!process.arguments().isEmpty()) + cmd += ' ' + process.arguments().join(' '); + cmd += '\n'; + ptr_term->sendText(cmd); + } +} + void ConsoleManager::showEvent(QShowEvent *event) { Q_UNUSED(event); diff --git a/src/plugins/console/consolemanager.h b/src/plugins/console/consolemanager.h index d649f6396..008e031c6 100644 --- a/src/plugins/console/consolemanager.h +++ b/src/plugins/console/consolemanager.h @@ -7,6 +7,7 @@ #include "consolewidget.h" +class QProcess; class ConsoleManagerPrivate; class ConsoleManager : public QWidget { @@ -17,9 +18,12 @@ class ConsoleManager : public QWidget QTermWidget *currentConsole(); QTermWidget *findConsole(const QString &id); - QTermWidget *createConsole(const QString &name, bool startNow = true); + QTermWidget *createConsole(const QString &name, bool startNow = true, bool rename = true); void sendCommand(const QString &text); void executeCommand(const QString &name, const QString &program, const QStringList &args, const QString &workingDir, const QStringList &env); + QUuid newConsole(const QString &name, bool rename = true); + void selectConsole(const QUuid &uuid); + void run2Console(const QUuid &uuid, const QProcess &process); private: void showEvent(QShowEvent *event) override; diff --git a/src/services/terminal/terminalservice.h b/src/services/terminal/terminalservice.h index a5110ef22..6cf055a80 100644 --- a/src/services/terminal/terminalservice.h +++ b/src/services/terminal/terminalservice.h @@ -32,6 +32,9 @@ class SERVICE_EXPORT TerminalService final : public dpf::PluginService, dpf::Aut */ DPF_INTERFACE(void, sendCommand, const QString &command); DPF_INTERFACE(void, executeCommand, const QString &name, const QString &program, const QStringList &args, const QString &workingDir, const QStringList &env); + DPF_INTERFACE(QUuid, createConsole, const QString &name, bool rename); + DPF_INTERFACE(void, selectConsole, const QUuid &id); + DPF_INTERFACE(void, run2Console, const QUuid &id, const QProcess& process); }; } // namespace dpfservice