diff --git a/tools/console.js b/tools/console.js index c6ad9007b3..9fa07e8a4c 100644 --- a/tools/console.js +++ b/tools/console.js @@ -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(); }, diff --git a/tools/main.js b/tools/main.js index a7f0a09874..cd851d7f55 100644 --- a/tools/main.js +++ b/tools/main.js @@ -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!