Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show output of commands in Debug Console #1593

Merged
merged 4 commits into from
Jun 5, 2017
Merged

Conversation

ketanhwr
Copy link
Contributor

@ketanhwr ketanhwr commented Jun 4, 2017

This closes #1552. I've attached a screenshot of the same.

outputconsole

Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking fine, apart from inline comments. :-)

Would it maybe be helpful to not only write the output of the command, but also a line with the final command being executed? That may help in finding issues with used variables, for example.

Executing: echo "Hello World"

: QProcess(DocumentManager::instance())
, mName(command.name)
, mFinalCommand(command.finalCommand())
, mFinalWorkingDirectory(command.finalWorkingDirectory())
, mLogger(CommandManager::instance()->logger())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the logger is available from the global CommandManager instance, I don't see a reason to also have it as member of CommandProcess.

@@ -209,12 +216,20 @@ CommandProcess::CommandProcess(const Command &command, bool inTerminal)

connect(this, SIGNAL(finished(int)), SLOT(deleteLater()));

if (showOutput)
connect(this, &QProcess::readyReadStandardOutput, this, &CommandProcess::consoleOutput);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll want to also connect to readyReadStandardError or use setProcessChannelMode to merge the standard error channel into the standard out channel.

Of course, it would be nice to report the error channel as appropriate to the LoggingInterface, so that the Debug Console will show errors in red.

if (!mFinalWorkingDirectory.trimmed().isEmpty())
setWorkingDirectory(mFinalWorkingDirectory);

start(mFinalCommand);
}

void CommandProcess::consoleOutput()
{
mLogger->log(LoggingInterface::INFO, QLatin1String(readAllStandardOutput()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't wrap the returned QByteArray with a QLatin1String, cause that will break whenever the encoding of the output is not actually latin1. Since we can't really know the output encoding, we should probably assume local encoding, which means using QString::fromLocal8Bit.

@@ -132,7 +143,7 @@ void CommandDialog::updateWidgets(const QModelIndex &current, const QModelIndex
mUi->exBrowseButton->setEnabled(enable);
mUi->keySequenceEdit->setEnabled(enable);
mUi->clearButton->setEnabled(enable);
mUi->saveBox->setEnabled(enable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line shouldn't be deleted, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I noticed that this line is already there in top 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I deleted this one.

<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="outputBox">
<property name="text">
<string>Show Output on Console</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use "Show output in Debug Console".

@@ -154,7 +154,7 @@
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="outputBox">
<property name="text">
<string>Show Output on Console</string>
<string>Show Output in Debug Console</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: please lowercase "output"

if (showOutput)
if (showOutput) {
CommandManager::instance()->logger()->log(LoggingInterface::INFO,
QString(QLatin1String("Executing: "))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be a translatable string, like tr("Executing: %1").arg(...)

@bjorn bjorn merged commit 74cede0 into mapeditor:master Jun 5, 2017
@bjorn
Copy link
Member

bjorn commented Jun 5, 2017

It's working well, nicely done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write output from custom commands to Debug Console window
2 participants