Ruby Readline - how to capture the full line?

Hi guys.

Consider this code:

require ‘pp’
require ‘readline’

Readline.completion_proc = proc { |input|
case input
else
pp input
end
}
Readline.completion_case_fold = true # ignore case
_ = Readline.readline(’ > ',true)

Now run this, and type:

“abc def”
then hit the TAB key.

The output should be:

“def”

Now my question - is there a way in ruby to capture the FULL line,
with readline? Including “abc”?

I need to react on whatever the user used here, and give him
different completion like abilities, just as you can do in
bash shell, with different commands.

Now run this

1.rb:6: syntax error, unexpected keyword_else, expecting keyword_when
1.rb:8: syntax error, unexpected keyword_end, expecting ‘}’

Now my question - is there a way in ruby to capture the FULL line,
with readline? Including “abc”?

Readline.completer_word_break_characters = “\n”

See the following link for a good tutorial:

http://bogojoker.com/readline/

Oops you are right, I forgot a when condition in the case menu.

My bad, sorry. Here the version that works:

require ‘pp’
require ‘readline’

Readline.completion_proc = proc { |input|
case input
when ‘foo’
else
pp input
end
}

Readline.completion_case_fold = true
Readline.completer_word_break_characters = “\n”
_ = Readline.readline(’ > ',true)

Thanks for the link 7stud, it now works perfect!
I can capture the full line, that solves it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs