feat: add REPL for plugins (#6120)

This can be enabled by setting the `.plugins.repl.enabled` setting to true


Close Chatterino and make a backup of your settings.json before attempting any modifications.
```json5
{
  "plugins": {
    "repl": {
      "enabled": true,
    },
  },
}
```
This commit is contained in:
nerix
2025-06-28 16:04:08 +02:00
committed by GitHub
parent 9e59fb1a5f
commit b6623cff88
16 changed files with 1000 additions and 18 deletions
+24
View File
@@ -3,12 +3,15 @@
# include "Application.hpp"
# include "common/Args.hpp"
# include "controllers/accounts/AccountController.hpp"
# include "controllers/plugins/PluginController.hpp"
# include "singletons/Paths.hpp"
# include "singletons/Settings.hpp"
# include "util/Helpers.hpp"
# include "util/LayoutCreator.hpp"
# include "util/RemoveScrollAreaBackground.hpp"
# include "widgets/PluginRepl.hpp"
# include "widgets/settingspages/SettingWidget.hpp"
# include <QCheckBox>
# include <QFormLayout>
@@ -78,6 +81,17 @@ PluginsPage::PluginsPage()
"enable and disable them.");
groupLayout->addRow(disabledLabel);
}
if (getSettings()->pluginRepl.enabled)
{
groupLayout->addRow(SettingWidget::fontButton(
"REPL font", getSettings()->pluginRepl.fontFamily,
&PluginRepl::currentFont, [](const QFont &font) {
getSettings()->pluginRepl.fontFamily = font.family();
getSettings()->pluginRepl.fontSize = font.pointSize();
getSettings()->pluginRepl.fontStyle = font.styleName();
}));
}
}
this->rebuildContent();
@@ -231,6 +245,16 @@ void PluginsPage::rebuildContent()
{
reloadButton->setEnabled(false);
}
if (getSettings()->pluginRepl.enabled)
{
auto *replButton = new QPushButton("Open REPL", this->dataFrame_);
QObject::connect(replButton, &QPushButton::clicked, [id]() {
auto *repl = new PluginRepl(id);
repl->show();
});
pluginEntry->addRow(replButton);
}
}
}
@@ -10,6 +10,7 @@
#include <QBoxLayout>
#include <QCheckBox>
#include <QFontDialog>
#include <QFormLayout>
#include <QLabel>
#include <QLineEdit>
@@ -393,6 +394,45 @@ SettingWidget *SettingWidget::lineEdit(const QString &label,
return widget;
}
SettingWidget *SettingWidget::fontButton(const QString &label,
QStringSetting &familySetting,
std::function<QFont()> currentFont,
std::function<void(QFont)> onChange)
{
auto *widget = new SettingWidget(label);
auto *lbl = new QLabel(label + ":");
auto *button = new QPushButton(currentFont().family());
widget->hLayout->addWidget(lbl);
widget->hLayout->addStretch(1);
widget->hLayout->addWidget(button);
familySetting.connect(
[button, currentFont](const auto &) {
button->setText(currentFont().family());
},
widget->managedConnections);
QObject::connect(button, &QPushButton::clicked,
[widget, currentFont{std::move(currentFont)},
onChange{std::move(onChange)}]() {
bool ok = false;
auto font =
QFontDialog::getFont(&ok, currentFont(), widget);
if (ok)
{
onChange(font);
}
});
widget->actionWidget = button;
widget->label = lbl;
return widget;
}
SettingWidget *SettingWidget::setTooltip(QString tooltip)
{
assert(!tooltip.isEmpty());
+6 -1
View File
@@ -23,7 +23,7 @@ namespace chatterino {
class GeneralPageView;
class SettingWidget : QWidget
class SettingWidget : public QWidget
{
Q_OBJECT
@@ -66,6 +66,11 @@ public:
QStringSetting &setting,
const QString &placeholderText = {});
static SettingWidget *fontButton(const QString &label,
QStringSetting &familySetting,
std::function<QFont()> currentFont,
std::function<void(QFont)> onChange);
SettingWidget *setTooltip(QString tooltip);
SettingWidget *setDescription(const QString &text);