Skip to content

Commit

Permalink
Temporary fix for command output to console widget.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
karliss committed Nov 11, 2023
1 parent fe85af2 commit 9a5d33a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
6 changes: 1 addition & 5 deletions src/common/CommandTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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);
}
4 changes: 1 addition & 3 deletions src/common/CommandTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }

Expand All @@ -31,7 +30,6 @@ class CUTTER_EXPORT CommandTask : public AsyncTask
private:
QString cmd;
ColorMode colorMode;
bool outFormatHtml;
};

#endif // COMMANDTASK_H
6 changes: 4 additions & 2 deletions src/core/Cutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/ConsoleWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ void ConsoleWidget::executeCommand(const QString &command)
addOutput(cmd_line);

RVA oldOffset = Core()->getOffset();
commandTask = QSharedPointer<CommandTask>(
new CommandTask(command, CommandTask::ColorMode::MODE_256, false));
commandTask =
QSharedPointer<CommandTask>(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();
Expand Down

0 comments on commit 9a5d33a

Please sign in to comment.