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

Async suggest messing up/duplicating output #371

Open
Fusseldieb opened this issue Sep 19, 2022 · 2 comments
Open

Async suggest messing up/duplicating output #371

Fusseldieb opened this issue Sep 19, 2022 · 2 comments

Comments

@Fusseldieb
Copy link

Fusseldieb commented Sep 19, 2022

Hi!

First of all, this library is amazing, it can do a whole load of stuff!

However, today I discovered one of it's weaknesses...

When I try to get something from an API and return it via an async suggest, it duplicated the output with every keystroke. See below:

? Test »
? Test ... t
? Test » te
? Test ... tes
? Test » test
? Test » testi
? Test ... testin
? Test » testing
>   d
    e
    f

It doesn't even need to be an API... If suggest isn't immediate (be it a timeout, an API call, etc), it duplicates the output, even if I return the EXACT same array.
Happens on PowerShell and the newer Terminal.

OS: Win 11

@joeykilpatrick
Copy link
Contributor

Can you provide a minimal code sample that causes this behavior? I am trying to reproduce but am not able.

This seems to work as expected:

await prompts({
  type: 'autocomplete',
  name: 'value',
  message: 'Pick your favorite actor',
  choices: [
    { title: 'Cage' },
    { title: 'Clooney', value: 'silver-fox' },
    { title: 'Gyllenhaal' },
    { title: 'Gibson' },
    { title: 'Grant' }
  ],
  suggest: async (input, choices) => choices.filter(i => i.title.slice(0, input.length) === input)
})

@eddie-corrigall-ledn
Copy link

eddie-corrigall-ledn commented Jan 23, 2023

I had a similar problem when I chose style emoji, and used 2 separate await prompts(). The first and second prompts() used style: 'emoji' with type: "text". I saw many duplicate emojis appear until I removed the style` property.

OS: OSX
Terminal: iTerm
Version: 2.4.2

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

No branches or pull requests

3 participants