From 9a5d33a316537c1c28cd184af83eae5e9e2c77ad Mon Sep 17 00:00:00 2001 From: Karliss Date: Sat, 11 Nov 2023 16:34:47 +0200 Subject: [PATCH] Temporary fix for command output to console widget. * partially revert #3193 - printing the terminal escape sequences directly to text widget causes more issues than the tab problem it tried to fix * move the conversation to html from command task to the console widget * add hack converting tab to multiple spaces --- src/common/CommandTask.cpp | 6 +----- src/common/CommandTask.h | 4 +--- src/core/Cutter.cpp | 6 ++++-- src/widgets/ConsoleWidget.cpp | 6 +++--- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/common/CommandTask.cpp b/src/common/CommandTask.cpp index c027cab132..0366aaf2b3 100644 --- a/src/common/CommandTask.cpp +++ b/src/common/CommandTask.cpp @@ -2,8 +2,7 @@ #include "CommandTask.h" #include "TempConfig.h" -CommandTask::CommandTask(const QString &cmd, ColorMode colorMode, bool outFormatHtml) - : cmd(cmd), colorMode(colorMode), outFormatHtml(outFormatHtml) +CommandTask::CommandTask(const QString &cmd, ColorMode colorMode) : cmd(cmd), colorMode(colorMode) { } @@ -12,8 +11,5 @@ void CommandTask::runTask() TempConfig tempConfig; tempConfig.set("scr.color", colorMode); auto res = Core()->cmdTask(cmd); - if (outFormatHtml) { - res = CutterCore::ansiEscapeToHtml(res); - } emit finished(res); } diff --git a/src/common/CommandTask.h b/src/common/CommandTask.h index 24a74a5ba1..15136699ea 100644 --- a/src/common/CommandTask.h +++ b/src/common/CommandTask.h @@ -17,8 +17,7 @@ class CUTTER_EXPORT CommandTask : public AsyncTask MODE_16M = COLOR_MODE_16M }; - CommandTask(const QString &cmd, ColorMode colorMode = ColorMode::DISABLED, - bool outFormatHtml = false); + CommandTask(const QString &cmd, ColorMode colorMode = ColorMode::DISABLED); QString getTitle() override { return tr("Running Command"); } @@ -31,7 +30,6 @@ class CUTTER_EXPORT CommandTask : public AsyncTask private: QString cmd; ColorMode colorMode; - bool outFormatHtml; }; #endif // COMMANDTASK_H diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index bd9983c332..f9f8570c8b 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -4451,11 +4451,13 @@ bool CutterCore::setColor(const QString &key, const QString &color) QString CutterCore::ansiEscapeToHtml(const QString &text) { int len; - char *html = rz_cons_html_filter(text.toUtf8().constData(), &len); + QString r = text; + r.replace("\t", " "); + char *html = rz_cons_html_filter(r.toUtf8().constData(), &len); if (!html) { return {}; } - QString r = QString::fromUtf8(html, len); + r = QString::fromUtf8(html, len); rz_mem_free(html); return r; } diff --git a/src/widgets/ConsoleWidget.cpp b/src/widgets/ConsoleWidget.cpp index 63f0ab650f..cf1b6aaabd 100644 --- a/src/widgets/ConsoleWidget.cpp +++ b/src/widgets/ConsoleWidget.cpp @@ -228,11 +228,11 @@ void ConsoleWidget::executeCommand(const QString &command) addOutput(cmd_line); RVA oldOffset = Core()->getOffset(); - commandTask = QSharedPointer( - new CommandTask(command, CommandTask::ColorMode::MODE_256, false)); + commandTask = + QSharedPointer(new CommandTask(command, CommandTask::ColorMode::MODE_16M)); connect(commandTask.data(), &CommandTask::finished, this, [this, cmd_line, command, oldOffset](const QString &result) { - ui->outputTextEdit->appendPlainText(result); + ui->outputTextEdit->appendHtml(CutterCore::ansiEscapeToHtml(result)); scrollOutputToEnd(); historyAdd(command); commandTask.clear();