Enable colors for ConsoleWidget (#823)

This commit is contained in:
tushar khurana 2018-10-21 20:23:38 +05:30 committed by xarkes
parent e16cd22082
commit 3347104cf1
3 changed files with 17 additions and 8 deletions

View File

@ -1,13 +1,16 @@
#include "CommandTask.h" #include "CommandTask.h"
#include "TempConfig.h"
CommandTask::CommandTask(const QString &cmd) CommandTask::CommandTask(const QString &cmd, ColorMode colorMode, bool outFormatHtml)
: cmd(cmd) : cmd(cmd), colorMode(colorMode), outFormatHtml(outFormatHtml)
{ {
} }
void CommandTask::runTask() void CommandTask::runTask() {
{ TempConfig tempConfig;
tempConfig.set("scr.color", colorMode);
tempConfig.set("scr.html", outFormatHtml);
auto res = Core()->cmdTask(cmd); auto res = Core()->cmdTask(cmd);
emit finished(res); emit finished(res);
} }

View File

@ -10,7 +10,9 @@ class CommandTask : public AsyncTask
Q_OBJECT Q_OBJECT
public: public:
CommandTask(const QString &cmd); enum ColorMode {DISABLED=COLOR_MODE_DISABLED, MODE_16=COLOR_MODE_16, MODE_256=COLOR_MODE_256, MODE_16M=COLOR_MODE_16M};
CommandTask(const QString &cmd, ColorMode colorMode=ColorMode::DISABLED, bool outFormatHtml=false);
QString getTitle() override { return tr("Running Command"); } QString getTitle() override { return tr("Running Command"); }
@ -22,6 +24,8 @@ protected:
private: private:
QString cmd; QString cmd;
ColorMode colorMode;
bool outFormatHtml;
}; };
#endif //COMMANDTASK_H #endif //COMMANDTASK_H

View File

@ -5,6 +5,7 @@
#include <QShortcut> #include <QShortcut>
#include <QStringListModel> #include <QStringListModel>
#include <QTimer> #include <QTimer>
#include <iostream>
#include "Cutter.h" #include "Cutter.h"
#include "ConsoleWidget.h" #include "ConsoleWidget.h"
#include "ui_ConsoleWidget.h" #include "ui_ConsoleWidget.h"
@ -173,14 +174,15 @@ void ConsoleWidget::executeCommand(const QString &command)
ui->outputTextEdit->appendPlainText("Executing the command..."); ui->outputTextEdit->appendPlainText("Executing the command...");
}); });
QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + command + "\n"; QString cmd_line = "<br>[" + RAddressString(Core()->getOffset()) + "]> " + command + "<br>";
commandTask = QSharedPointer<CommandTask>(new CommandTask(command)); commandTask = QSharedPointer<CommandTask>(new CommandTask(command, CommandTask::ColorMode::MODE_256, true));
connect(commandTask.data(), &CommandTask::finished, this, [this, cmd_line, connect(commandTask.data(), &CommandTask::finished, this, [this, cmd_line,
command, originalLines] (const QString & result) { command, originalLines] (const QString & result) {
if (originalLines < ui->outputTextEdit->blockCount()) { if (originalLines < ui->outputTextEdit->blockCount()) {
removeLastLine(); removeLastLine();
} }
ui->outputTextEdit->appendPlainText(cmd_line + result); ui->outputTextEdit->appendHtml(cmd_line + result);
scrollOutputToEnd(); scrollOutputToEnd();
historyAdd(command); historyAdd(command);
commandTask = nullptr; commandTask = nullptr;