piotrmurach / tty-prompt

A beautiful and powerful interactive command line prompt
https://ttytoolkit.org
MIT License
1.47k stars 136 forks source link

Prompt select , per_page , hash issue #46

Closed Celedhrim closed 7 years ago

Celedhrim commented 7 years ago

hi

tty-prompt 0.11.0

choices = {'Scorpion' => 1, 'Kano' => 2, 'Jax' => 3}
prompt.select("Choose your letter?", choices)

produce this output:

Choose your letter? (Use arrow keys, press Enter to select)
‣ Scorpion
  Kano
  Jax

Now I set per_page

choices = {'Scorpion' => 1, 'Kano' => 2, 'Jax' => 3}
prompt.select("Choose your letter?", choices, per_page: 2)

the per_page can be 2 , 10 , 25 , always same result

Choose your letter? (Use arrow keys, press Enter to select)
‣ ["Scorpion", 1]

Only one entry is display and baddly

piotrmurach commented 7 years ago

Hi,

Thanks for using the library.

You have found a case where pagination doesn't work, which is when choices are provided as hash object rather than array. This is a bug, in the interim you could do the following:

prompt.select("Choose your letter?", per_page: 2) do |menu|
  menu.choice 'Scorpion', 1
  menu.choice 'Kano', 2
  menu.choice 'Jax', 3
end