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

Discussion on a better set of actions for user input #459

Open
ezekg opened this issue Dec 1, 2014 · 3 comments
Open

Discussion on a better set of actions for user input #459

ezekg opened this issue Dec 1, 2014 · 3 comments

Comments

@ezekg
Copy link

ezekg commented Dec 1, 2014

Similar to #457, I'd like to see some discussion on more ways to gather user input. Right now, if you want to do anything other than ask a simple question with ask, then you're either left to fend for yourself, or you have to use an option like :limited_to, which is not ideal (more on that particular issue is discussed in the link above). Below are some simple proposals to start the discussion.

Actions

Shell select menu:

Shell select menu with an up/down arrow selection.

? What would you like to do?
  Item 1
> Item 2
  Item 3

Shell radio menu:

Shell radio select menu. Use spacebar for selection like web forms?

? Select dependencies:
  ( ) Item 1
  (x) Item 2
> (x) Item 3

Indexed menu:

Standard select by index.

? Choose a framework:
  1. Item 1
  2. Item 2
  3. Item 3
  > 2

Standard menu:

Standard select by name.

? Which version would you like to use?
  Item 1
  Item 2
  Item 3
  > Ite

Prompt sets

Ability to create 'sets' of prompts/actions that can be rewound (back) and fast-forwarded (skip) similar to Interact with the left/right arrow keys. Nothing is worse than inputting a typo and having to ctr+c out of the script and restart.

options = prompts do |prompt|
  set, :something,
    prompt.ask "Ask something"
  set, :something_else,
    prompt.ask "Ask something else"
  set, :choice,
    prompt.select "Choose deps", ["Item 1", "item 2", "item 3"], :radio
end

puts options[:choice] #=> ["item 2"]

Styling

I'd like to see an option to style the select items differently from the actual method color. Maybe something like how HighLine does it:

choose do |menu|
  menu.prompt = set_color("Please choose your favorite programming language:", :blue)
  # Add single choice, and message if chosen
  menu.choice :ruby do
    set_color(say("Good choice!"), :green)
  end
  # Add array of choices and a message if either is chosen
  menu.choices(:python, :perl) do
    set_color(say("Not from around here, are you?"), :yellow)
  end
end

In addition to styling the new actions, I think that we should also be able to color the (:default) string (and possibly other options) differently from the rest of the text. For example:

ask "Site name:", :cyan,
  :default => "site"

Will output the entire string Site name: (site) as the same color. Being able to differentiate these two would produce a better overall user experience. I think the best example of great actions and user experience for user input is Yeoman.

Discussion

I wanted to get some discussion going before diving straight into something like this. Is this even something that would want to be implemented into Thor? My team has been using Thor for scaffolding / setup scripts, and the more complex our setups get, the more we wish that these features were available.

Thoughts? Additional ideas? Let's hear 'em.

@ezekg
Copy link
Author

ezekg commented Dec 6, 2014

Similar issue on HighLine.

@ezekg
Copy link
Author

ezekg commented Jun 21, 2015

I extended Thor a bit IO-wise for a recent project if anybody wants to check it out. It has shell select menus that can be navigated with the arrow keys, unicode icons, easier-to-use implementation of colors, indentation, more user-friendly questions, etc. It's compatible with MRI >= 1.9.3.

@piotrmurach
Copy link

@ezekg The menu functionality you have described is very important but I would also argue that thor is not necessarily the place to add it to. I think it would be good to keep thor focused and not to become a magnet for attracting anything connected with CLI app development. I see thor core functionality as object oriented command line options parser.

If you are still looking for something that handles your use cases you can try using tty-prompt that I've been working on recently. It's not complete by any means but it already sports quite few prompt helpers and should integrate with thor nicely.

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

2 participants