JEG2 / highline

A higher level command-line oriented interface.
Other
1.29k stars 137 forks source link

Menu prompt not reused after failed menu selection #180

Closed intentionaccident closed 8 years ago

intentionaccident commented 8 years ago
requre 'highline/import'
choose do | menu |
  menu.prompt = "> "
  menu.choice :exit, "Exit cube editor" do
    abort("Exiting")
  end
end

After a failed selection the promt defaults to '? ' I hope I'm not missing something in the API.

abinoam commented 8 years ago

I have confirmed the behavior in my setup. I'll be taking a look at it.

abinoam commented 8 years ago

Dear @strigonLeader,

I'm sorry but you're right, this particular need has no intuitive way of doing it.

Reviewing the code I could see that, when "reasking" the question in the face of an error HighLine doesn't show the prompt you set up. Instead, it shows the responses[:ask_on_error] string. And... for menus, there were no easy way to overwrite it. I have made a simple workaround in a PR that I'm pushing that allows it to be overwritten.

You should add the following line inside the configuration block.

menu.responses[:ask_on_error] = "> "

So your complete example would be:

require 'highline/import'

choose do |menu|
  menu.prompt = "> "
  menu.responses[:ask_on_error] = "> "
  menu.choice :exit, "Exit cube editor" do
    abort("Exiting")
  end
end

When I have more time I will rework this to something more straightforward.