New Console.withProgressDisplayVisible function

This replaces the pattern of turning two flags on and off by hand.

Also, avoid calling _updateProgressDisplay unless you're actually
changing values.
This commit is contained in:
David Glasser
2014-11-11 17:27:50 -08:00
parent 352af3b8e0
commit 4aa33782fa
2 changed files with 52 additions and 28 deletions

View File

@@ -516,12 +516,42 @@ _.extend(Console.prototype, {
setPretty: function (pretty) {
var self = this;
if (FORCE_PRETTY === undefined) {
self._pretty = pretty;
}
// If we're being forced, do nothing.
if (FORCE_PRETTY !== undefined)
return;
// If no change, do nothing.
if (self._pretty === pretty)
return;
self._pretty = pretty;
self._updateProgressDisplay();
},
// Runs f with the progress display visible (ie, with progress display enabled
// and pretty). Resets both flags to their original values after f runs.
withProgressDisplayVisible: function (f) {
var self = this;
var originalPretty = self._pretty;
var originalProgressDisplayEnabled = self._progressDisplayEnabled;
// Turn both flags on.
self._pretty = self._progressDisplayEnabled = true;
// Update the screen if anything changed.
if (!originalPretty || !originalProgressDisplayEnabled)
self._updateProgressDisplay();
try {
return f();
} finally {
// Reset the flags.
self._pretty = originalPretty;
self._progressDisplayEnabled = originalProgressDisplayEnabled;
// Update the screen if anything changed.
if (!originalPretty || !originalProgressDisplayEnabled)
self._updateProgressDisplay();
}
},
setVerbose: function (verbose) {
var self = this;
self.verbose = verbose;
@@ -745,6 +775,9 @@ _.extend(Console.prototype, {
enabled = true;
}
if (self._progressDisplayEnabled === enabled)
return;
self._progressDisplayEnabled = enabled;
self._updateProgressDisplay();
},

View File

@@ -371,22 +371,18 @@ var springboard = function (rel, options) {
// XXX split better
try {
Console.setPretty(true);
Console.enableProgressDisplay(true);
buildmessage.enterJob({
title: "Downloading tools package " + toolsPkg + "@" + toolsVersion
}, function () {
tropohouse.default.maybeDownloadPackageForArchitectures({
packageName: toolsPkg,
version: toolsVersion,
architectures: [archinfo.host()],
definitelyNotLocal: true
Console.withProgressDisplayVisible(function () {
buildmessage.enterJob({
title: "Downloading tools package " + toolsPkg + "@" + toolsVersion
}, function () {
tropohouse.default.maybeDownloadPackageForArchitectures({
packageName: toolsPkg,
version: toolsVersion,
architectures: [archinfo.host()],
definitelyNotLocal: true
});
});
});
Console.enableProgressDisplay(false);
Console.setPretty(false);
} catch (err) {
// We have failed to download the tool that we are supposed to springboard
// to! That's bad. Let's exit.
@@ -795,11 +791,9 @@ Fiber(function () {
// Somehow we have a catalog that doesn't have any releases on the
// default track. Try syncing, at least. (This is a pretty unlikely
// error case, since you should always start with a non-empty catalog.)
Console.setPretty(true);
Console.enableProgressDisplay(true);
alreadyRefreshed = catalog.refreshOrWarn();
Console.enableProgressDisplay(false);
Console.setPretty(false);
Console.withProgressDisplayVisible(function () {
alreadyRefreshed = catalog.refreshOrWarn();
});
releaseName = release.latestKnown();
}
if (!releaseName) {
@@ -855,11 +849,9 @@ Fiber(function () {
}
// ATTEMPT 3: modern release, troposphere sync needed.
Console.setPretty(true);
Console.enableProgressDisplay(true);
alreadyRefreshed = catalog.refreshOrWarn();
Console.enableProgressDisplay(false);
Console.setPretty(false);
Console.withProgressDisplayVisible(function () {
alreadyRefreshed = catalog.refreshOrWarn();
});
// Try to load the release even if the refresh failed, since it might
// have failed on a later page than the one we needed.
@@ -1296,7 +1288,6 @@ commandName + ": You're not in a Meteor project directory.\n" +
require('./profile-require.js').printReport();
Console.setPretty(command.pretty);
Console.enableProgressDisplay(true);
// Run the command!