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

gather attribute does not work with menu #48

Open
smackesey opened this issue Oct 26, 2012 · 4 comments
Open

gather attribute does not work with menu #48

smackesey opened this issue Oct 26, 2012 · 4 comments

Comments

@smackesey
Copy link

The RDoc says to use the gather attribute of a Question to select multiple items. This works when using ask, but it fails when using choose. This seems odd since Menu (passed to the choose block) inherits from Question (passed to the ask block)

This code

#!/usr/bin/env ruby

require 'highline/import'
require 'rb-readline'

choices = %w[ rabbit caterpillar frog ]

x = choose do |menu|
  menu.prompt = "Animal?  "
  menu.choices(*choices)
  menu.gather = 3
end

generates, after entering three choices, this error:

/Users/seanmackesey/.rvm/gems/ruby-1.9.3-p194/gems/highline-1.6.15/lib/highline/menu.rb:303:in `[]': no implicit conversion from nil to integer (TypeError)

It seems like menu should work with gather. Is it not intended to? You also get an error if you set gather to a string/regexp.

@JEG2
Copy link
Owner

JEG2 commented Oct 29, 2012

I played around with this a little today and you're right that it doesn't work. It looks like HighLine's menu code doesn't support the Array of results. I guess this is a bug.

Still, it's not totally clear to me how this should work. For example, if code sets up blocks to be run for each item, should that happen as the individual item is picked or after all items have been picked?

It's hard for me to imagine how this combination of features would be used. Do you have a more realistic example that could shed more light on this?

@smackesey
Copy link
Author

It seems much more intuitive to me to run the block item by item.

As for a realistic example, I encountered this issue while trying to use the Highline menu system to filter an error log. I'm building a database from a bunch of CSV files and some of the data is rejected during the build process. This goes into a big JSON file where each entry includes, among other data, the name of the file that generated the error and the type of error. I need to provide subsets of these build errors on demand to coworkers, so I was trying to build a little command line utility that would let me select an arbitrary set of files followed by an arbitrary set of error types, and output the error log after being filtered by these selections. I was originally trying to use the string/regex form of gather to terminate the menu by entering a blank, after selecting all desired options. I can imagine many similar use cases, but perhaps there are better ways to approach such a problem?

@JEG2
Copy link
Owner

JEG2 commented Oct 29, 2012

It seems much more intuitive to me to run the block item by item.

If we're going that route, why not just wrap the choose() call in a simple loop? Then you could even change the list as the select items which seems to lead to a better UI.

@JEG2
Copy link
Owner

JEG2 commented Feb 5, 2015

We are currently planning the next major version of HighLine. We will include a discussion of this issue in the plans we make for that release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants