@forge/cli-shared

9.4.0-next.4-experimental-c5755749.4.0-next.6
out/ui/command-line-ui.js
~out/ui/command-line-ui.jsModified
+62−1
Index: package/out/ui/command-line-ui.js
===================================================================
--- package/out/ui/command-line-ui.js
+++ package/out/ui/command-line-ui.js
@@ -14,8 +14,9 @@
 const text_1 = require("./text");
 const multiple_table_prompt_1 = require("./multiple-table-prompt");
 const single_table_prompt_1 = require("./single-table-prompt");
 const shared_1 = require("../shared");
+const hint_rotation_1 = require("./hint-rotation");
 var ProgressLogType;
 (function (ProgressLogType) {
     ProgressLogType[ProgressLogType["startText"] = 0] = "startText";
     ProgressLogType[ProgressLogType["successText"] = 1] = "successText";
@@ -32,8 +33,12 @@
     promptInternal;
     insideProgress = false;
     statsigService;
     cachedSpinnerConfig = 'dots';
+    static HINT_ROTATION_INTERVAL_MS = 7000;
+    hintLine;
+    hintTimer;
+    hintGeneration = 0;
     addedProgressPadding = false;
     static ANSI_MOVE_CURSOR_UP_ONE = '\x1B[1A';
     static ANSI_CLEAR_CURSOR_LINE = '\x1B[2K';
     static NON_TTY_ENV_DEFAULT_COLUMNS = 100;
@@ -88,17 +93,20 @@
     }
     get debugEnabled() {
         return this.verbose();
     }
-    async displayProgress(progress, startText, successText) {
+    async displayProgress(progress, startText, successText, hintCategory) {
         try {
             this.insideProgress = true;
             this.addedProgressPadding = false;
             if (!this.debugEnabled) {
                 this.spinner.spinner = this.getSpinner();
                 this.spinner.start();
             }
             this.log(startText, ProgressLogType.startText);
+            if (hintCategory) {
+                this.startHintRotation(hintCategory);
+            }
             const result = await progress();
             const progressResult = typeof successText === 'function' ? successText(result) : successText;
             const isSuccessful = typeof progressResult === 'string' || progressResult.successful;
             if (isSuccessful) {
@@ -117,8 +125,56 @@
         finally {
             this.insideProgress = false;
         }
     }
+    startHintRotation(category) {
+        if (!this.spinner.isSpinning) {
+            return;
+        }
+        const generation = ++this.hintGeneration;
+        this.statsigService
+            ?.getHints()
+            .then((hints) => this.rotateHints(hints ?? [], generation, category))
+            .catch(() => this.debug(text_1.Text.hints.loadError));
+    }
+    rotateHints(hints, generation, category) {
+        if (generation !== this.hintGeneration) {
+            return;
+        }
+        const nextHint = (0, hint_rotation_1.createHintRotation)((0, hint_rotation_1.selectHintsForCategory)(hints, category));
+        let renderedHint = false;
+        const showNextHint = () => {
+            const text = nextHint();
+            if (text === undefined) {
+                this.clearHintTimer();
+                return;
+            }
+            this.stripHintLine();
+            this.hintLine = '\n  ' + chalk_1.default.dim('💡 ' + text);
+            this.spinner.text += this.hintLine;
+            renderedHint = true;
+        };
+        showNextHint();
+        if (renderedHint) {
+            this.clearHintTimer();
+            this.hintTimer = setInterval(showNextHint, CommandLineUI.HINT_ROTATION_INTERVAL_MS);
+        }
+    }
+    stripHintLine() {
+        if (this.hintLine && this.spinner.text.endsWith(this.hintLine)) {
+            this.spinner.text = this.spinner.text.slice(0, -this.hintLine.length);
+        }
+    }
+    clearHintTimer() {
+        clearInterval(this.hintTimer);
+        this.hintTimer = undefined;
+    }
+    stopHintRotation() {
+        this.hintGeneration++;
+        this.clearHintTimer();
+        this.stripHintLine();
+        this.hintLine = undefined;
+    }
     async displayTemporaryMessage(progress, waitText) {
         try {
             this.insideProgress = true;
             this.addedProgressPadding = false;
@@ -384,9 +440,13 @@
                 this.addedProgressPadding = true;
             }
         }
         if (this.spinner.isSpinning) {
+            this.stripHintLine();
             this.spinner.text += msg + '\n';
+            if (this.hintLine) {
+                this.spinner.text += this.hintLine;
+            }
         }
         else {
             this.logger.log(msg);
         }
@@ -407,8 +467,9 @@
             this.log(log_symbols_1.default.error + ' ' + errorText, ProgressLogType.other);
         }
     }
     stopProgressSpinner(success) {
+        this.stopHintRotation();
         if (!this.spinner.isSpinning) {
             return;
         }
         if (this.spinner.text.endsWith('\n')) {