Question: I want make interactive application where user launches it and can do various task by typing commands (some kind of shell)

example:  

```
./myapp.rb  
App says Hi  
Commands:   
  help - display help about command
  open - open task
  do - do action
Start>help open
  open <TaskName>
  opens specified task
Start>open Something  
Something>do SomeAction
  Success!
Something> (blinking cursor here)

```

I searched but couldn't find any ruby gems that I could use specially for console interaction, so I'm about to my make my own...

I looked at [Thor](https://www.ruby-toolbox.com/projects/thor), but that's not exactly as I want, maybe I could use it, but not sure...

it could look something like:

```
class Tasks
  attr_reader :opened_task

  desc "open <TaskName>", "opens specified task"
  def open(params)
  end

  desc "do <ActionName>", "do specified action"
  def do(params)
  end
end

tasks = Tasks.new
# theoretical Console class
console = Console.new
console.addCommand("open",tasks.method(:open),"open task")
console.addCommand("do",tasks.method(:do),"do action")
console.start("%s>",[*tasks.opened_task])

```

so my question is, what gems I could use to make such console class? maybe someone have already made something similar?
I plan using [HighLine](https://www.ruby-toolbox.com/gems/highline) for input/output, but any other suggestion what could I use?

Answer: 
What you want is a [REPL](http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) – `Read → Evaluate → Print Loop`.

IRB, for example, implements a REPL for the Ruby language.

Here's a very simple implementation of your application's REPL:

```
loop do
  Application::Console.prompt.display
  input = gets.chomp
  command, *params = input.split /\s/

  case command
  when /\Ahelp\z/i
    puts Application::Console.help_text
  when /\Aopen\z/i
    Application::Task.open params.first
  when /\Ado\z/i
    Application::Action.perform *params
  else puts 'Invalid command'
  end
end

```

`\A` and `\z` match the start of the string and the end of the string, respectively.
[TTY](http://piotrmurach.github.io/tty/) is a really good gem for easily doing this sort of things. You have plenty of tools which can work alone or with the full toolKit. You can use colors, prompts, execute shell natives, interact with the screen, print tables, progressbars and many other useful elements of command lines whith the easy of a goop api.

Particularly [tty-prompt](https://github.com/piotrmurach/tty-prompt) is really useful for asking for user input.

A brief example for the case you proposed:

```
require 'tty-prompt'
require 'pastel'

prompt = TTY::Prompt.new
loop do
  cmd, parms* = prompt.ask('user@machine$ ').split /\s/
  case cmd
    when "hola"
      puts "Hola amigo " parms
    when "exit"
      break if prompt.yes?('Do you really want to exit?')
  end
end

```