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

Using select with message longer than terminal width duplicates the message. #153

Closed
eahefnawy opened this issue Apr 8, 2019 · 4 comments · Fixed by #168
Closed

Using select with message longer than terminal width duplicates the message. #153

eahefnawy opened this issue Apr 8, 2019 · 4 comments · Fixed by #168
Labels
bug Something isn't working

Comments

@eahefnawy
Copy link

eahefnawy commented Apr 8, 2019

Describe the bug

Using select with message longer than terminal width duplicates the message and breaks the UI.

prompts-bug

To Reproduce

Just run this script in a relatively narrow terminal window:

const prompts = require('prompts')

const runPrompt = async () => {
  const selected = await prompts(
    {
      type: 'select',
      name: 'template',
      message: 'What would you like to create in this directory?',
      choices: [
        { title: 'My Own Component', value: 'component' },
        { title: 'Function', value: 'function' },
        { title: 'API', value: 'api' },
        { title: 'Website', value: 'website' },
        { title: 'Realtime Application', value: 'realtime-app' },
        { title: 'Chat Application', value: 'chat-app' },
        { title: 'Websocket Backend', value: 'websocket-backend' }
      ],
      initial: 0
    },
    {
      onCancel: () => process.exit(0)
    }
  )
  console.log(selected)
}

runPrompt()

Expected behavior

It should detect terminal width and adjust cursor automatically. It shouldn't duplicate the message.

System

  • OS: macOS 10.14.2
  • Terminal: iTerm
  • Node version: v11.12.0

Additional context

Might be related to #89

@lumio lumio added the bug Something isn't working label Apr 13, 2019
@daKmoR
Copy link

daKmoR commented Apr 14, 2019

I can verify this - but it doesn't even need to be a small screen - as soon as the message is multi-line the bug appears 😭

const questions = [{
  type: 'select',
  name: 'rootType',
  message: 'What would you like to do today?\n  More info on the full flow can be found at\n  https://open-wc.org/create/',
  choices: [
    { title: 'Scaffold a new project', value: 'scaffold' },
    { title: 'Upgrade an existing project', value: 'upgrade' },
    { title: 'Nah, I am fine thanks! => exit', value: 'exit' },
  ],
  initial: 1,
}];

@terkelg
Copy link
Owner

terkelg commented May 6, 2019

Thank you for reporting this bug

@dangercard
Copy link

I've been reading my code for hours thinking I had made a mistake. Good thing I checked here. Thanks for the report!

@dsosborn
Copy link

dsosborn commented Jun 4, 2019

The list of options also duplicates if the list is taller than the window.

terkelg pushed a commit that referenced this issue Jul 5, 2019
* fix(select): duplicate when text > 1 line

* fix(confirm): duplicate when text > 1 line

* fix(date): duplicate when text > 1 line + simplified TextPrompt.render()

* fix(toggle): duplicate when text > 1 line

* fix(number): duplicate when text > 1 line

* fix(autocomplete): duplicate when text > 1 line

* fix(number): cursor pos when error is shown

* fix(prompt): Use existing clear function + export lines function

* fix(date): Formatting

* fix(prompt): formatting

* Updated sisteransi + removed util/ansi.js

* fix(dependency): anticipate next version of sisteransi (1.0.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants