Readline question - completely replace input?

Hi.

This is a strange question perhaps …

I use Readline.readline to fetch user input.

Now if the user types:

“abc”

And then presses tab, I want this to complete to:

“do_action foobar”

So, yes, the original input “abc” no longer has anything to do with the
end result. :slight_smile:

Is this possible? So far I am using Readline only to do something like:

“do”

expand into

"do_action "

But it would be kind of neat to both append something specifically after
TAB was pressed, and to also completely change the original input at the
same time.

Use regexp or string.sub to do this

Joe

Sent from my iPad

On Tue, Oct 04, 2011 at 10:07:52PM +0900, Marc H. wrote:

“do”

expand into

"do_action "

But it would be kind of neat to both append something specifically after
TAB was pressed, and to also completely change the original input at the
same time.

This is certainly possible using rb-readline[1] (pure Ruby port of GNU
Readline), but I doubt that the C binding to GNU Readline provides
enough hooks.

As a rough starting point, you could look at rl_bind_key() to redefine
the behaviour of \t. Some methods and variables to look at are:

rl_insert()
rl_redisplay()
@_rl_last_v_pos
@rl_point
@rl_done

1 - https://github.com/luislavena/rb-readline

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