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

A way to fix flickering #1497

Closed
cAttte opened this issue Aug 3, 2024 · 2 comments · Fixed by #1498
Closed

A way to fix flickering #1497

cAttte opened this issue Aug 3, 2024 · 2 comments · Fixed by #1498

Comments

@cAttte
Copy link

cAttte commented Aug 3, 2024

hey! i've been getting an annoying flicker on every screen update (am i the only one?) and i remembered how i fixed it back when i implemented CLI screen updates myself some time ago. basically, write the clear character along with the output rather than in separate writes. this seems to solve the flickering:

before.mp4
after.mp4

don't really have time for a proper PR + it's a little ugly (was just a quick patch-package) + there may be edge cases? but if you want i can open a PR. here's a diff:

--- a/node_modules/@inquirer/core/dist/esm/lib/screen-manager.mjs
+++ b/node_modules/@inquirer/core/dist/esm/lib/screen-manager.mjs
@@ -52,14 +52,14 @@ export default class ScreenManager {
             output += ansiEscapes.cursorUp(bottomContentHeight);
         // Return cursor to the initial left offset.
         output += ansiEscapes.cursorTo(this.cursorPos.cols);
-        this.clean();
         this.rl.output.unmute();
         /**
          * Set up state for next re-rendering
          */
+        const clean = this.getClean();
         this.extraLinesUnderPrompt = bottomContentHeight;
         this.height = height(output);
-        this.rl.output.write(output);
+        this.rl.output.write(clean + output);
         this.rl.output.mute();
     }
     checkCursorPos() {
@@ -71,14 +71,17 @@ export default class ScreenManager {
             this.cursorPos = cursorPos;
         }
     }
-    clean() {
-        this.rl.output.unmute();
-        this.rl.output.write([
+    getClean() {
+        return [
             this.extraLinesUnderPrompt > 0
                 ? ansiEscapes.cursorDown(this.extraLinesUnderPrompt)
                 : '',
             ansiEscapes.eraseLines(this.height),
-        ].join(''));
+        ].join('');
+    }
+    clean() {
+        this.rl.output.unmute();
+        this.rl.output.write(this.getClean());
         this.extraLinesUnderPrompt = 0;
         this.rl.output.mute();
     }
@SBoudrias
Copy link
Owner

Thanks for the deep-dive @cAttte! I went ahead and roughly implemented that change (with a bit more cleanup of the previous code.)

I'm kind of confuse because I was sure we had made a similar fix 😂... But now I wonder if that was maybe on inquirer and we never ported if to @inquirer/core - anyhow, thanks that was the nudge required to get this fixed!

@cAttte
Copy link
Author

cAttte commented Aug 4, 2024

great, thank you for implementing it! (and for all your work)

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 a pull request may close this issue.

2 participants