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:
@@ -0,0 +1,91 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
# include "widgets/BaseWindow.hpp"
|
||||
|
||||
# include <boost/signals2/connection.hpp>
|
||||
# include <QString>
|
||||
# include <QTextBlockFormat>
|
||||
# include <QTextCharFormat>
|
||||
# include <sol/forward.hpp>
|
||||
|
||||
class QTextEdit;
|
||||
class QTextCharFormat;
|
||||
class QTextBlockFormat;
|
||||
|
||||
namespace chatterino::lua::api {
|
||||
enum class LogLevel;
|
||||
} // namespace chatterino::lua::api
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Plugin;
|
||||
class SvgButton;
|
||||
class PixmapButton;
|
||||
|
||||
class PluginRepl : public BaseWindow
|
||||
{
|
||||
public:
|
||||
PluginRepl(QString id, QWidget *parent = nullptr);
|
||||
|
||||
static QFont currentFont();
|
||||
|
||||
protected:
|
||||
void themeChangedEvent() override;
|
||||
|
||||
private:
|
||||
struct LogOptions {
|
||||
/// Maximum number of items to show in tables.
|
||||
size_t maxItems = 10;
|
||||
};
|
||||
|
||||
void tryRun(QString code);
|
||||
void logResult(const sol::protected_function_result &res,
|
||||
const LogOptions &opts);
|
||||
|
||||
void log(std::optional<lua::api::LogLevel> level, const QString &text);
|
||||
|
||||
void tryUpdate();
|
||||
void setPlugin(Plugin *plugin);
|
||||
|
||||
void updateFont();
|
||||
void updatePinned();
|
||||
|
||||
QString id;
|
||||
Plugin *plugin = nullptr;
|
||||
|
||||
boost::signals2::scoped_connection pluginDestroyConn;
|
||||
boost::signals2::scoped_connection pluginLogConn;
|
||||
boost::signals2::scoped_connection pluginLoadedConn;
|
||||
|
||||
bool isPinned = false;
|
||||
|
||||
struct {
|
||||
QTextEdit *input = nullptr;
|
||||
QTextEdit *output = nullptr;
|
||||
SvgButton *clear = nullptr;
|
||||
SvgButton *reload = nullptr;
|
||||
PixmapButton *pin = nullptr;
|
||||
} ui;
|
||||
|
||||
struct {
|
||||
QTextCharFormat self;
|
||||
QTextCharFormat debug;
|
||||
QTextCharFormat info;
|
||||
QTextCharFormat warning;
|
||||
QTextCharFormat error;
|
||||
} charFormats;
|
||||
struct {
|
||||
QTextBlockFormat self;
|
||||
QTextBlockFormat debug;
|
||||
QTextBlockFormat info;
|
||||
QTextBlockFormat warning;
|
||||
QTextBlockFormat error;
|
||||
} blockFormats;
|
||||
|
||||
QFont font;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user