diff --git a/src/widgets/ConsoleWidget.cpp b/src/widgets/ConsoleWidget.cpp index c4713c0f..6c74a708 100644 --- a/src/widgets/ConsoleWidget.cpp +++ b/src/widgets/ConsoleWidget.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "Cutter.h" #include "ConsoleWidget.h" #include "ui_ConsoleWidget.h" @@ -167,19 +168,40 @@ void ConsoleWidget::focusInputLineEdit() ui->inputLineEdit->setFocus(); } +void ConsoleWidget::removeLastLine() +{ + ui->outputTextEdit->setFocus(); + QTextCursor cur = ui->outputTextEdit->textCursor(); + ui->outputTextEdit->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); + ui->outputTextEdit->moveCursor(QTextCursor::StartOfLine, QTextCursor::MoveAnchor); + ui->outputTextEdit->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor); + ui->outputTextEdit->textCursor().removeSelectedText(); + ui->outputTextEdit->textCursor().deletePreviousChar(); + ui->outputTextEdit->setTextCursor(cur); +} + void ConsoleWidget::executeCommand(const QString &command) { if (!commandTask.isNull()) { return; } - ui->inputLineEdit->setEnabled(false); - QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + command + "\n"; + const int originalLines = ui->outputTextEdit->blockCount(); + QTimer *timer = new QTimer(this); + timer->setInterval(500); + timer->setSingleShot(true); + connect(timer, &QTimer::timeout, [this]() { + ui->outputTextEdit->appendPlainText("Executing the command..."); + }); + QString cmd_line = "[" + RAddressString(Core()->getOffset()) + "]> " + command + "\n"; commandTask = QSharedPointer(new CommandTask(command)); connect(commandTask.data(), &CommandTask::finished, this, [this, cmd_line, - command] (const QString & result) { + command, originalLines] (const QString & result) { + if (originalLines < ui->outputTextEdit->blockCount()) { + removeLastLine(); + } ui->outputTextEdit->appendPlainText(cmd_line + result); scrollOutputToEnd(); historyAdd(command); @@ -187,6 +209,9 @@ void ConsoleWidget::executeCommand(const QString &command) ui->inputLineEdit->setEnabled(true); ui->inputLineEdit->setFocus(); }); + connect(commandTask.data(), &CommandTask::finished, timer, &QTimer::stop); + + timer->start(); Core()->getAsyncTaskManager()->start(commandTask); } diff --git a/src/widgets/ConsoleWidget.h b/src/widgets/ConsoleWidget.h index 30668523..3b32630d 100644 --- a/src/widgets/ConsoleWidget.h +++ b/src/widgets/ConsoleWidget.h @@ -54,6 +54,7 @@ private: void scrollOutputToEnd(); void historyAdd(const QString &input); void invalidateHistoryPosition(); + void removeLastLine(); void executeCommand(const QString &command); QSharedPointer commandTask;