mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-22 12:56:11 +00:00
235761941f
* Added stdout/stderr redirection to the console
114 lines
2.3 KiB
C++
114 lines
2.3 KiB
C++
#ifndef CONSOLEWIDGET_H
|
|
#define CONSOLEWIDGET_H
|
|
|
|
#include "core/MainWindow.h"
|
|
#include "CutterDockWidget.h"
|
|
#include "common/CommandTask.h"
|
|
|
|
#include <QStringListModel>
|
|
#include <QSocketNotifier>
|
|
#include <QLocalSocket>
|
|
|
|
#include <memory>
|
|
|
|
class QCompleter;
|
|
class QShortcut;
|
|
|
|
namespace Ui {
|
|
class ConsoleWidget;
|
|
}
|
|
|
|
class ConsoleWidget : public CutterDockWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit ConsoleWidget(MainWindow *main, QAction *action = nullptr);
|
|
|
|
~ConsoleWidget();
|
|
|
|
void setDebugOutputEnabled(bool enabled)
|
|
{
|
|
debugOutputEnabled = enabled;
|
|
}
|
|
|
|
void setMaxHistoryEntries(int max)
|
|
{
|
|
maxHistoryEntries = max;
|
|
}
|
|
|
|
protected:
|
|
bool eventFilter(QObject *obj, QEvent *event);
|
|
|
|
public slots:
|
|
void focusInputLineEdit();
|
|
|
|
void addOutput(const QString &msg);
|
|
void addDebugOutput(const QString &msg);
|
|
|
|
private slots:
|
|
void setupFont();
|
|
|
|
void on_inputLineEdit_returnPressed();
|
|
|
|
void on_execButton_clicked();
|
|
|
|
void showCustomContextMenu(const QPoint &pt);
|
|
|
|
void historyNext();
|
|
void historyPrev();
|
|
|
|
void triggerCompletion();
|
|
void disableCompletion();
|
|
void updateCompletion();
|
|
|
|
void clear();
|
|
|
|
/**
|
|
* @brief Passes redirected output from the pipe to the terminal and console
|
|
*/
|
|
void processQueuedOutput();
|
|
|
|
private:
|
|
void scrollOutputToEnd();
|
|
void historyAdd(const QString &input);
|
|
void invalidateHistoryPosition();
|
|
void removeLastLine();
|
|
void executeCommand(const QString &command);
|
|
void setWrap(bool wrap);
|
|
|
|
/**
|
|
* @brief Redirects stderr and stdout to the output pipe which is handled by
|
|
* processQueuedOutput
|
|
*/
|
|
void redirectOutput();
|
|
|
|
QSharedPointer<CommandTask> commandTask;
|
|
|
|
std::unique_ptr<Ui::ConsoleWidget> ui;
|
|
QAction *actionWrapLines;
|
|
QList<QAction *> actions;
|
|
bool debugOutputEnabled;
|
|
int maxHistoryEntries;
|
|
int lastHistoryPosition;
|
|
QStringList history;
|
|
bool completionActive;
|
|
QStringListModel completionModel;
|
|
QCompleter *completer;
|
|
QShortcut *historyUpShortcut;
|
|
QShortcut *historyDownShortcut;
|
|
FILE *origStderr;
|
|
FILE *origStdout;
|
|
QLocalSocket *pipeSocket;
|
|
#ifdef Q_OS_WIN
|
|
HANDLE hRead;
|
|
HANDLE hWrite;
|
|
#else
|
|
int redirectPipeFds[2];
|
|
QVector<char> *redirectionBuffer;
|
|
QSocketNotifier *outputNotifier;
|
|
#endif
|
|
};
|
|
|
|
#endif // CONSOLEWIDGET_H
|