Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

Input prompt flickers while waiting for validation function

Open anchenyi opened this issue 1 year ago • 2 comments

I use the input prompt from the @inquirer/prompts package to handle user input. However, I noticed that the built-in waiting spinner keeps flickering while the validation function is processing. How can I avoid this issue? Thanks.

Terminal: Windows Powershell @inquirer/prompts: 5.0.4 node: v16.20.2

Typescipt Codes to reproduce

import { input } from "@inquirer/prompts";
const validate = async (input: string) => {
    await new Promise(resolve => setTimeout(resolve, 5000));
    return true
};

(async () => {
    let message: string =  "select your message"
    let defaultValue = "1"

    const answer = await input({
        message,
        default: defaultValue,
        validate: validate,
        });
    console.log(`input value:${answer}`);
})();

https://github.com/SBoudrias/Inquirer.js/assets/162104711/bb6e98c5-07bd-4180-968d-d77051b24769

anchenyi avatar May 29 '24 05:05 anchenyi

For reference, here's another fix to a similar issue that was happening in other cases: https://github.com/SBoudrias/Inquirer.js/pull/1379

SBoudrias avatar May 31 '24 20:05 SBoudrias

Pushed a little perf improvement, I'd appreciate if you could test it out and let me know if it's any better for you. I personally don't encounter this flickering in any mac OS prompt - so I'm having a hard time diving deeper into the issue.

SBoudrias avatar Jun 19 '24 21:06 SBoudrias

hi @SBoudrias Thanks for the response. I checked the latest @inquirer/prompts v5.1.0, the flickers still exist.

anchenyi avatar Jul 01 '24 05:07 anchenyi

This flickering happens when registering the input of the prompts(without validation). I'm thinking to work on this.

saurabhje avatar Jul 06 '24 20:07 saurabhje

@saurabhje that'd be great. Let me know if you get blocked somewhere.

SBoudrias avatar Jul 06 '24 20:07 SBoudrias

We received a suggestion for a way to improve performance, it's merged and released. Would appreciate feedback form the folks here: does it fix/improve the situation for you?

SBoudrias avatar Aug 04 '24 22:08 SBoudrias

hi @SBoudrias, I tried @inquirer/prompts:5.3.8, and this issue is resolved on my side. Thank you!

anchenyi avatar Aug 07 '24 07:08 anchenyi

Amazing that's great to hear! Thanks for following up 😁

SBoudrias avatar Aug 07 '24 11:08 SBoudrias