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<TAB>"

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.

路路路

--
Posted via http://www.ruby-forum.com/.

Use regexp or string.sub to do this

Joe

路路路

Sent from my iPad

On Oct 4, 2011, at 9:07 AM, Marc Heiler <shevegen@linuxmail.org> wrote:

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<TAB>"

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.

--
Posted via http://www.ruby-forum.com/\.

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 - GitHub - ConnorAtherton/rb-readline: Pure-Ruby Readline Implementation

路路路

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

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<TAB>"

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.